4

Can someone help my why are the two warning messages different syntactically (when they seem to be generated the same way)?

\documentclass{article}

\usepackage{enumitem}
\usepackage{refcount}

\makeatletter
\newcommand\statuslabel[1]{%
    \def\nref{\getrefnumber{#1}}
    \@latex@warning{Not a number (\#3): \nref}
}
\makeatother

\makeatletter
\newcounter{enumerateof} % to create unique labels
\newenvironment{enumerateof}
  {\stepcounter{enumerateof}
   \begin{enumerate}[
     label=\protect\statuslabel{enof@\arabic{enumerateof}},
     ref=\arabic*]}
  {\label{enof@\arabic{enumerateof}}%
   \end{enumerate}}
\makeatother

\begin{document}

\begin{enumerateof}
    \item example
\end{enumerateof}

\begin{table}
    \caption{example}
    \label{tab@ex}
\end{table}

\protect\statuslabel{tab@ex}

\end{document}

Warning messages:

LaTeX Warning: Not a number (\#3): {1} on input line 27.
LaTeX Warning: Not a number (\#3): 1 on input line 35.

Where does those curly braces come from? How can I remove them (define something which is equal to the content of the braces}?

4

It seems that enumitem package adds them there. To remove them, you can (quite safely) do as here:

\documentclass{article}

\usepackage{enumitem}
\usepackage{refcount}

\makeatletter
\newcommand\statuslabel[1]{%
    \edef\nref{\getrefnumber{#1}}
    \edef\nref{\expandafter\@firstofone\nref}
    \@latex@warning{Not a number (\#3): \nref}
}
\makeatother

\makeatletter
\newcounter{enumerateof} % to create unique labels
\newenvironment{enumerateof}
  {\stepcounter{enumerateof}
   \begin{enumerate}[
     label=\protect\statuslabel{enof@\arabic{enumerateof}},
     ref=\arabic*]}
  {\label{enof@\arabic{enumerateof}}%
   \end{enumerate}}
\makeatother

\begin{document}

\begin{enumerateof}
    \item example
\end{enumerateof}

\begin{table}
    \caption{example}
    \label{tab@ex}
\end{table}

\protect\statuslabel{tab@ex}

\end{document}

The point is that if \nref expands to let's say 123 at the first step, then \@firstofone takes 1 as its argument and returns 1, leaving 23 in the stream. And if it's {123}, then \@firstofone takes it all and removes the braces.

| improve this answer | |
  • Do you think it is a bug in enumitem? – masu Oct 28 '13 at 17:10
  • I would not call this exactly a bug. It is a property of the package, probably given by the fact that the author didn't consider someone doing this. I'll contact the package author and ask him for his opinion, he might even answer here I think. – yo' Oct 28 '13 at 18:32
  • Thanks. I thought the same. Even I didn't consider someone doing this. :) – masu Oct 28 '13 at 18:34
  • For the big picture, my task wasn't exactly this. I used your solution as a part in my answer for a different topic. – masu Oct 28 '13 at 18:36
  • 2
    It's a feature, in fact -- ref is supposed to print a string (and also \arabic for that matter), which may include formating commands, and which should be local. (But I discovered sometimes there is an extra pair of redundant braces.) – Javier Bezos Nov 4 '13 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.