如何不在 \index 中重复单词

如何不在 \index 中重复单词

为了制作索引,我必须写两次单词,

\documentclass[12pt,oneside]{book}
\usepackage{makeidx}
\makeindex
\begin{document}
This will not print \index{anything} !!! 
However it will make an entery in Index. 
To print the word in text and index you need to write word \index{word}.
\printindex
\end{document}

要为 建立索引,我们需要写入word \index{word}。我觉得这有些多余。

有没有什么方法(包或代码)可以只写\index{word}

答案1

您可以定义一个\iindex带有一个参数的新命令(例如),并使用该参数调用\index并将其打印在文本上。

\newcommand{\iindex}[1]{#1\index{#1}} 

然后你只需输入\iindex{word}

\documentclass[12pt,oneside]{book}
\usepackage{makeidx}
\makeindex
\newcommand{\iindex}[1]{#1\index{#1}} %%This is new command
 %%%and then you type \iindex{word}

\begin{document}
This will not print \index{anything} !!! 
However it will make an entry in Index. 
To print the word in text and index you need to write word \index{word}. 
Or \iindex{word} single.
\printindex
\end{document}

相关内容