为了确保我已索引了应该索引的内容,我想在文档草稿中为每个索引项添加脚注。以下 MNWE 是我尝试过的。更新的命令\index
正确地创建了索引条目,但没有生成脚注。\marginpar
而不是也\footnote
失败了。也是如此\marginnote
。
\documentclass{article}
\usepackage{marginnote}
\usepackage{imakeidx} % needed in the real document
\usepackage{refcount} % needed in the real document
\let\oldindex\index
\renewcommand{\index}[1]{%
%\footnote{INDEXING #1}
\marginnote{#1}
\oldindex{#1}
}
\makeindex[intoc] % needs imakeidx
\begin{document}
Here is an entry\index{entry} to index\index{index}.
Check that margin notes work\marginnote{This is a margin note}
Check that footnotes work\footnote{This is a footnote}
\printindex
\end{document}
答案1
您必须\renewcommand{\index}
在开始文档时延迟:
\documentclass{article}
\usepackage{imakeidx} % needed in the real document
\usepackage{refcount} % needed in the real document
\AtBeginDocument{%
\NewCommandCopy{\oldindex}{\index}%
\renewcommand{\index}[1]{%
\footnote{INDEXING #1}%
\marginpar{#1}%
\oldindex{#1}%
}%
}
\makeindex[intoc] % needs imakeidx
\begin{document}
Here is an entry\index{entry} to index\index{index}.
\printindex
\end{document}
原始答案\LetLtxMacro
用于解释原因何时使用 \LetLtxMacro?但现在\NewCommandCopy
更受青睐。
这里并不是真正需要它,但是当命令有(或似乎有)可选参数时,最好这样做。
如果您还想支持可选参数\index
,那么您可以使用xparse
它来让事情变得更容易。
\documentclass{article}
\usepackage{imakeidx} % needed in the real document
\usepackage{refcount} % needed in the real document
\AtBeginDocument{%
\NewCommandCopy{\oldindex}{\index}%
\RenewDocumentCommand{\index}{om}{%
\footnote{INDEXING #2}%
\marginpar{#2}%
\IfNoValueTF{#1}{\oldindex{#2}}{\oldindex[#1]{#2}}%
}%
}
\makeindex[intoc] % needs imakeidx
\begin{document}
Here is an entry\index{entry} to index\index{index}.
\printindex
\end{document}
(我\marginpar
一直使用,因为\marginnote
如果在同一行,会导致条目重叠)。
答案2
这是我为了完全相同的目的而使用的方法。保留 \index 不变:
\newcommand{\indx}1{\colorbox{yellow}{\footnotesize #1}\index{#1}}%检查
%\newcommand{\indx}1{\index{#1}} %标准 \index
\item to toggle perspective view \indx{perspective view},
\item store and select camera positions (snapshots). Only the camera and the view angle (zoom) are stored, not the result type.
\item Legend and status bar can be moved freely on the \indx{Legend!move} screen with the left mouse button pressed.