当我使用 指示索引条目时,\index
我必须在上下文中并作为参数输入索引词的文本两次\index
:
This is an index: Hello! \index{Hello} And ....
当我决定更改索引词时,我必须对两个词进行更改。我怎样才能强制 TeX 输出 的参数\index
?(也许\index*
!)
答案1
这index
包提供了带星号的版本\index*
,它既排版了它的参数,又将它添加到索引中;还有hvindex
包及其\Index
命令。
\documentclass{article}
\usepackage{index}
\makeindex
\begin{document}
Some text about \index*{foo}.
\printindex
\end{document}
\documentclass{article}
\usepackage{makeidx}
\makeindex
\usepackage{hvindex}
\begin{document}
Some text about \Index{foo}.
\printindex
\end{document}
如果您不想使用其他软件包,您可以保存原始版本\index
并将其包含在重新定义中,以执行您想要的操作。(以下示例假设\index
没有具有可选参数。
\documentclass{article}
\usepackage{makeidx}
\makeindex
\let\oldindex\index
\renewcommand*{\index}[1]{#1\oldindex{#1}}
\begin{document}
Some text about \index{foo}.
\printindex
\end{document}
编辑:我似乎发现了一个错误hvindex
:在 & 后面添加了一个虚假空格\Index
,显然是因为源代码中各行末尾缺少注释符号。以下补丁可更正此行为:
\documentclass{article}
\usepackage{makeidx}
\makeindex
\usepackage{hvindex}
% The following must NOT be enclosed in `\makeatletter`/`\makeatother`
\def\IndexXXi#1@#2@#3\IndexNIL{%
\ifx\relax#2\relax % no @ in last arg
\def\hvTemp{#1}%
\ifx\hvTemp\hvEncap\index{{#1}}#1\else% {{...}} to get "| with hyperref
\ifx\hvIDXfont\hvIDXfontDefault\index{#1}#1% <-- THIS COMMENT SIGN WAS MISSING
\else\index{#1@\hvIDXfont{#1}}\hvIDXfont{#1}\fi\fi%#1
\else\index{#1@#2}#2\fi}% % #1@#2
%
\def\IndexXXii#1!#2@#3@#4\IndexNIL{%
\ifx\relax#3\relax % no @ in last arg
\def\hvTemp{#2}%
\ifx\hvTemp\hvEncap\index{#1!{#2}}#2\else
\ifx\hvIDXfont\hvIDXfontDefault\index{#2}#2% <-- THIS ONE, TOO
\else\index{#1!#2@\hvIDXfont{#2}}\hvIDXfont{#2}\fi\fi%
\else\index{#1!\protect#2@#3}#3\fi}
%
\def\IndexXXiii#1!#2!#3@#4@#5\IndexNIL{%
\ifx\relax#4\relax % no @ in last arg
\def\hvTemp{#3}%
\ifx\hvTemp\hvEncap\index{#1!#2!{#3}}#3\else
\ifx\hvIDXfont\hvIDXfontDefault\index{#3}#3% <-- AND THIS ONE, TOO
\else\index{#1!#2!#3@\hvIDXfont{#3}}\hvIDXfont{#3}\fi\fi%
\else\index{#1!#2!\protect#3@#4}#4\fi}
\begin{document}
Some text about \Index{foo}.
\printindex
\end{document}