我遇到的问题几乎和这家伙但该解决方案对我来说不起作用,我想是因为我正在索引的字符串在宏参数中。
来自另一个问题:
在索引上下文中,字符
!
、@
和需要进行转义。为了让 makeindex 理解您是要提及它们而不是使用它们,您必须用 '引用' 它们。以下应该可以解决问题:|
"
\index{"!} % or, in this case: \fun{"!}
将其应用到我的代码中我得到
\newcommand{\coper}[1]%
{%
\texttt{#1}%
\ifthenelse%
{\equal{#1}{!} \OR \equal{#1}{@}}%
{%
\index{"#1@\texttt{"#1} (C operator)}%
\index{operators!\texttt{"#1} (C)}%
}%
{%
\index{#1@\texttt{#1} (C operator)}%
\index{operators!\texttt{#1} (C)}%
}%
}
调用\coper{!}
会在索引中添加一个条目,但是感叹号不会出现在索引中(它只是空白,但周围的文本在那里)。
当通过宏参数给出索引时,如何将感叹号添加到索引中?
答案1
这与"
错误消息表明您有{
超过}
我假设
\index{"#1@\texttt{"#1} (C operator)%
旨在
\index{"#1@\texttt{"#1} (C operator)}%
和
\index{#1@\texttt{#1} (C operator)%
旨在
\index{#1@\texttt{#1} (C operator)}%
\documentclass{article}
\usepackage{makeidx,ifthen}
\makeindex
\begin{document}
\newcommand{\coper}[1]%
{%
\texttt{#1}%
\ifthenelse%
{\equal{#1}{!} \OR \equal{#1}{@}}%
{%
\index{"#1@\texttt{"#1} (C operator)}%
\index{operators!\texttt{"#1} (C)}%
}%
{%
\index{#1@\texttt{#1} (C operator)}%
\index{operators!\texttt{#1} (C)}%
}%
}
aaa\coper{!}
\printindex
\end{document}