I have a custom counter and output it with leading zeros. When I reference it, I get some real strange output, but the enumeration itself works.
Preamble:
\newcounter{reqcount}
\setcounter{reqcount}{3}
\newcommand{\threedigits}[1]{%
\ifnum #1<100 0\fi%
\ifnum #1<10 0\fi%
\number#1}
Document
\refstepcounter{reqcount}\label{req}
[DR-\threedigits{\arabic{reqcount}}] % Works, outputs [DR-001]
[DR-{\ref{req}}] % Outputs [DR-4<100 04<10 004]
Someone posted this answer but it was removed. I don't know why, but the code below works and the above does not.
\documentclass{article}
\newcounter{reqcount}
\setcounter{reqcount}{0}
\newcommand{\threedigits}[1]%
{%
\ifnum #1<10 00%
\else%
\ifnum #1<100 0%
\fi%
\fi%
\number#1%
}
\newcommand\DR[1]% macro to typeset a new DR item
{%
\refstepcounter{reqcount}\label{DR:#1}%
[DR-\threedigits{\value{reqcount}}]%
}
\makeatletter
\newcommand\refDR[1]% macro to cross-reference to a particular DR item
{%
[DR-\expandafter\threedigits\ref{DR:#1}]%
}
\makeatother
\begin{document}
%.... 88 DR items later
\setcounter{reqcount}{1}
\DR{foo} blah blah
As seen in~\refDR{foo}, blah blah blah
\end{document}
\documentclass{...}and ending with\end{document}. – egreg Jan 09 '14 at 11:01\thereqcount(which you obviously have: otherwise[DR-{\ref{req}}]should print something like »[DR-4]«) so this is not an MWE – cgnieder Jan 10 '14 at 10:10