# Using siunitx in captions?

I am using pdflatex(texlive 2011) to compile a document. Unfortunately it does not compile.

! Undefined control sequence.
\metre ->\ERROR

l.69 ...feld  \num{6}{\metre} mal \num{6}{\metre}}


siunitx works for units in normal text, but using it in captions fails. Is this a bug or misconfiguration. Under texlive 2009 it compiles flawlessly.

Here is my figure command

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{figure}
\caption{\num{6}{\metre}}
\end{figure}
\end{document}

-
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Benedikt Bauer Jan 17 '13 at 20:18
@elcojon: I've tided up the MWE so it is 'stand alone' and minimal. – Joseph Wright Jan 17 '13 at 20:26

Things will work correctly if you do not abuse \num :-)

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\listoffigures
\begin{figure}
Some filler
\caption{A caption \SI{6}{\metre}}
\end{figure}
\end{document}


Reason: the \num macro command takes one argument: a number. You therefore effectively have a free-standing unit after the \num, and these are not therefore correctly processed by siunitx.

To explain why this worked in TL2009, that had version 1 of siunitx. The older code created 'free-standing' units as standard, which was changed for version 2. 'Free-standing' units have various issues, including namespace issues: this change was quite deliberate. Of course, this means that something like

\documentclass{article}
\usepackage{siunitx}
\sisetup{free-standing-units}
\begin{document}
\begin{figure}
\caption{\num{6}{\metre}}
\end{figure}
\end{document}


will work, but as it's not the correct use of \num I really don't encourage it!

-
You are right. And I appreciate your help a lot. Yet, I do have another problem very related to this. I might open another question. – user24537 Jan 17 '13 at 20:26