下面的 EXAMPLE 1 运行正常,但 EXAMPLE 2 产生“未定义的控制序列”。唯一的区别是命令\vlabel
中括号内的命令\caption
。问题是什么?
示例 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}
示例 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}
答案1
扩展ifthen
\protect
宏会导致辅助文件中出现问题。您需要
...
\caption[\protect\vlabel{numbersa}]{\vlabel{numbersa}}
...
或者使用替代方案:
\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
(需要 e-TeX)是可扩展的,确保只能Numbers A
进入 LoF。