1

EXAMPLE 1 below works fine but EXAMPLE 2 produces "undefined control sequence". The only difference is the \vlabel command within brackets in the \caption command. What is the problem?

EXAMPLE 1:

\documentclass{article}
\usepackage{pgffor}
\usepackage{ifthen}

\newcommand{\vlabel}[1]
{%
\ifthenelse{\equal{#1}{numbersa}}{Numbers A}{}%
}

\begin{document}

\listoftables

\begin{table}
\caption[Numbers A]{\vlabel{numbersa}}
\end{table}

\end{document}

EXAMPLE 2:

\documentclass{article}
\usepackage{pgffor}
\usepackage{ifthen}

\newcommand{\vlabel}[1]
{%
\ifthenelse{\equal{#1}{numbersa}}{Numbers A}{}%
}

\begin{document}

\listoftables

\begin{table}
\caption[\vlabel{numbersa}]{\vlabel{numbersa}}
\end{table}

\end{document}
  • Hi and welcome, Code highlighting and markup works just like over at TeXwelt.de. – Johannes_B Mar 30 '15 at 18:23
1

The expansion of ifthen macros causes problems in the auxiliary files. You either need to \protect them

...
\caption[\protect\vlabel{numbersa}]{\vlabel{numbersa}}
...

or use an alternative:

\documentclass{article}
\newcommand{\vlabel}[1]{%
  \ifnum\pdfstrcmp{#1}{numbersa}=0
    Numbers A%
  \fi
}

\begin{document}

\listoftables% LoF

\begin{table} \caption[Numbers A]{\vlabel{numbersa}} \end{table}

\begin{table} \caption[\vlabel{numbersa}]{\vlabel{numbersa}} \end{table}

\end{document}

\pdfstrcmp (requires e-TeX) is expandable, making sure that only Numbers A makes its way into the LoF.

  • Excellent, both solutions work perfectly, thank you very much! – Sarine Mar 30 '15 at 21:11

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.