我定义了一些用于\equal{}
测试参数是否为空的命令。我想将这些命令用作词汇表中的名称。但是,使用 进行编译时,以下最小示例不起作用latexmk
:
\documentclass{article}
\usepackage{glossaries}
\usepackage{ifthen}
\newcommand{\testWithEqual}[1]{\ifthenelse{\equal{#1}{}}{Nothing}{Something}}
\newcommand{\testWithOutEqual}[0]{Anything}
\makeglossaries
% This entry works:
\newglossaryentry{testWithOutEqual}{
name={\testWithOutEqual{}},
description={testWithOutEqual entry}
}
% This entry results in failure:
\newglossaryentry{testWithEqual}{
name={\testWithEqual{}},
description={testWithEqual entry}
}
\begin{document}
\glsaddall
\printglossary
\end{document}
具体来说,我认为日志中的相关信息是:
Undefined control sequence. <argument> \equal {}{}
有办法实现这个吗?
答案1
您可以定义自己的宏来测试空参数。以下代码可以做到这一点并且有效:
\documentclass{article}
\usepackage{glossaries}
\usepackage{ifthen}
\newcommand{\testWithEqual}[1]{\MyIfEmptyTF{#1}{Nothing}{Something}}
\makeatletter
\newcommand\MyIfEmptyTF[1]
{%
\if\relax\detokenize{#1}\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\makeatother
\newcommand{\testWithOutEqual}[0]{Anything}
\makeglossaries
% This entry works:
\newglossaryentry{testWithOutEqual}{
name={\testWithOutEqual{}},
description={testWithOutEqual entry}
}
% This entry results in failure:
\newglossaryentry{testWithEqual}{
name={\testWithEqual{}},
description={testWithEqual entry}
}
\begin{document}
\glsaddall
\printglossary
\end{document}