# User defined command produces error in conflict with siunitx and TeXLive2011

I recently installed TeXLive 2011 on my MacBook (running MacOS X 10.6.8) and got the following problem:

Example:

\documentclass[11pt, a4paper]{scrbook}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[TS1, T1]{fontenc}
\usepackage{aecompl}
\usepackage{textcomp}
\usepackage[ngerman]{babel}
\usepackage{xspace}
\usepackage[tight]{units}
\usepackage{varwidth}
\usepackage{xcolor}
\usepackage{amsmath}

\usepackage{siunitx}
%\usepackage[round-mode=places, round-integer-to-decimal, round-precision=2,
%   table-format = 1.2,
%   table-number-alignment=center,
%   output-decimal-marker={,},
%   group-digits=false
%   ]{siunitx}

\newcommand{\FZ}[1]{\ensuremath{\textcolor{blue}{#1}}\xspace}
\newcommand{\ps}{\FZ{p_{\mathrm{s}}}}

\begin{document}
\listoffigures

\begin{figure}
\rule{5cm}{5cm}

\caption{effect of \ps on $p_{\mathrm{s}}$}
\end{figure}

\rule{1pt}{5cm}

effect of \ps on $p_{\mathrm{s}}$ -- here it works

\end{document}


With TeXLive 2010 it compiles without a problem.

With TeXLive 2011, I get the following error message after the second pdflatex run:

 (./FehlerTeX2011.lof ./FehlerTeX2011.lof:2: Undefined control
sequence. <argument> ... 0.1}{\ignorespaces effect of \pson
$p_{\mathrm {s}}$} l.2 ...aces effect of \pson $p_{\mathrm {s}}$}}{1}


There seems to be a problem with the custom command \ps, the siunitx package and the list of figures, as the error can be avoided

• by deactivating siunitx
• or by typesetting \ps*{}* in the caption with parenthesis
• or by removing the list of figures
• or by using TeXLive 2010 instead
(luckily in OS X there is a way to switch between different TeX installations easily)

Can anybody help and tell me what's going wrong?

here is the complete log file for used package versions:

    This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011)
\write18 enabled.
entering extended mode
(./FehlerTeX2011.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2011-07-01, ngerman-x-2011-07-01, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
h, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnis
h, french, galician, german, ngerman, swissgerman, monogreek, greek, hungarian,
icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, marathi, or
iya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian, kurmanji,
lao, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk, pol
ish, portuguese, romanian, russian, sanskrit, serbian, serbianc, slovak, sloven
ian, spanish, swedish, turkish, turkmen, ukrainian, uppersorbian, welsh, loaded
.
(/usr/local/texlive/2011/texmf-dist/tex/latex/koma-script/scrbook.cls
Document Class: scrbook 2011/06/16 v3.09a KOMA-Script document class (book)
(/usr/local/texlive/2011/texmf-dist/tex/latex/koma-script/scrkbase.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/koma-script/scrbase.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/koma-script/scrlfile.sty

))) (/usr/local/texlive/2011/texmf-dist/tex/latex/koma-script/tocbasic.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/koma-script/scrsize11pt.clo)
(/usr/local/texlive/2011/texmf-dist/tex/latex/koma-script/typearea.sty
Package typearea, 2011/06/16 v3.09a KOMA-Script package (type area)

)) (/usr/local/texlive/2011/texmf-dist/tex/generic/babel/babel.sty
(/usr/local/texlive/2011/texmf-dist/tex/generic/babel/ngermanb.ldf
(/usr/local/texlive/2011/texmf-dist/tex/generic/babel/babel.def)))
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/inputenc.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/utf8.def
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/t1enc.dfu)
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/ot1enc.dfu)
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/omsenc.dfu)))
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/fontenc.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/ts1enc.def
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/ts1enc.dfu))
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/t1enc.def))
(/usr/local/texlive/2011/texmf-dist/tex/latex/ae/aecompl.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/textcomp.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/ts1enc.def))
(/usr/local/texlive/2011/texmf-dist/tex/latex/tools/xspace.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/units/units.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/units/nicefrac.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/varwidth/varwidth.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/latexconfig/color.cfg)
(/usr/local/texlive/2011/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)))
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the ?' option.
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/siunitx/siunitx.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3names.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3bootstrap.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/etex-pkg/etex.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/tools/calc.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/latexconfig/graphics.cfg))
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3basics.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3expan.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3tl.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3seq.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3int.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3quark.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3prg.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3clist.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3token.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3prop.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3msg.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3io.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3file.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3skip.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3keys.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3fp.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3box.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3coffins.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3color.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3kernel/l3luatex.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/tools/array.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/l3packages/xparse/xparse.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/beamer/translator/translator.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/beamer/translator/translator-lang
uage-mappings.tex))) (./FehlerTeX2011.aux)
(/usr/local/texlive/2011/texmf-dist/tex/latex/base/ts1cmr.fd)
(/usr/local/texlive/2011/texmf-dist/tex/context/base/supp-pdf.mkii
) (/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/ifpdf.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/oberdiek/grfext.sty
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/etexcmds.sty)))
(/usr/local/texlive/2011/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
(/usr/local/texlive/2011/texmf-dist/tex/latex/beamer/translator/dicts/translato
r-basic-dictionary/translator-basic-dictionary-English.dict)
(/usr/local/texlive/2011/texmf-dist/tex/latex/siunitx/config/siunitx-abbreviati
ons.cfg)
(/usr/local/texlive/2011/texmf-dist/tex/latex/siunitx/config/siunitx-binary.cfg
) (/usr/local/texlive/2011/texmf-dist/tex/latex/base/t1cmss.fd)
(./FehlerTeX2011.lof

-
Are you really sure about loading aecompl? The support for Type1 fonts in T1 encoding is full on MacTeX. – egreg Dec 9 '11 at 12:07
@egreg: thanks for your hint. I'm not sure about that - it might be a relict which has survived many years in my preamble. I'll see if I can remove it. :-) – MostlyHarmless Dec 9 '11 at 12:53

This happens because siunitx defines \ps as an abbreviation with the standard settings. Now, most of the time you won't see any effect, but what happens here is that there is some modification necessary for the procedure LaTeX uses to write the \caption information to the .lof file. What siunitx does is make \ps a protected command during that process, which again is almost always transparent. The problem arises specifically because you've decided to use it in a xspace-based way with no following argument.

The first solution is to include an argument after \ps:

\documentclass{article}
\usepackage{siunitx,xspace}

\newcommand{\ps}{\ensuremath{p_{\mathrm{s}}}\xspace}

\begin{document}
\listoffigures

\begin{figure}
\caption{effect of \ps{} on $p_{\mathrm{s}}$}
\end{figure}

\end{document}


The second is to tell siunitx not to define any abbreviated units:

\documentclass{article}
\usepackage{siunitx,xspace}
\sisetup{abbreviations = false}

\newcommand{\ps}{\ensuremath{p_{\mathrm{s}}}\xspace}

\begin{document}
\listoffigures

\begin{figure}
\caption{effect of \ps on $p_{\mathrm{s}}$}
\end{figure}

\end{document}


(I've cut down your example to a minimum in both cases.)

You've seen a change since the TeX Live 2010 version of siunitx as the default is now to define abbreviations: the older setting was to do this only if requested, but over all it made more sense for most people to have this setting 'on' to start with.

-
Why \newcommand{\ps}{...} doesn't trigger an error? – egreg Dec 9 '11 at 11:45
Interesting, that siunitx has effect on commands which are user defined. Instead of switching of all abbreviations, how about a feature to switch off just one, like \UnDeclareSIUnit{\ps} and further a warning, when a user defines such a macro? – Stefan Kottwitz Dec 9 '11 at 11:45
@egreg Unit macros are only defined within the scope of the \SI command and similar. The only issue is making sure that if someone puts a unit inside use of \addtocontents then it is written correctly to the output. The approach currently taken is to define the unit macros within that scope. What I can do is adjust the code so that this is only done if there is no other definition about. (With my LaTeX3 hat on, simply using an \unexpanded inside the write is attractive, but I'm not keen to do something quite that radical.) – Joseph Wright Dec 9 '11 at 11:51
@StefanKottwitz I used to have a selectable set of unit abbreviations, but for the complexity it adds the outcome is not worth it. If people need a selected set of abbreviations then usually they are best off doing the entire job themselves. – Joseph Wright Dec 9 '11 at 11:53
To elaborate a bit more on the need to do this, imagine that the caption contains something like \SI{10}{\ps}. If \ps gets expanded at all when written to the .lof file, then it will mess up the units. So the only safe thing to do is to make sure that all unit macros are protected during the writing process. – Joseph Wright Dec 9 '11 at 11:59

I can compile on TeX Live 2011 without problems.

It seems that a space is lost in the .lof file, as the compiler complains that \pson is unknown, while you wrote \ps on. So, you could use {} or \space after \ps, or even use \xspace directly in the definition of the command or try it without \xspace since \xspace isn't guaranteed to work well in all situations.

Further, as the problem seems to occur on your system with the list of figures, so with captions, you could

• protect the \ps macro:

\caption{effect of \protect\ps on $p_{\mathrm{s}}$}

• or declare it as robust command:

\DeclareRobustCommand{\ps}{\FZ{p_{\mathrm{s}}}}

-
Thanks, Stefan! \protect indeed helps. \DeclareRobustCommand` however does not change anything for me, I also get an error message then. – MostlyHarmless Dec 10 '11 at 23:19