![添加一个词汇表条目,其名称是使用 \equal{} 的宏](https://linux22.com/image/381148/%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E8%AF%8D%E6%B1%87%E8%A1%A8%E6%9D%A1%E7%9B%AE%EF%BC%8C%E5%85%B6%E5%90%8D%E7%A7%B0%E6%98%AF%E4%BD%BF%E7%94%A8%20%5Cequal%7B%7D%20%E7%9A%84%E5%AE%8F.png)
我定义了一些用于\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}