引用自身的索引条目

引用自身的索引条目

有些数学教材通过提供一些奇怪的索引条目来尊重一种不言而喻的传统。我想要一个引用自身的索引条目。这是一个 (N)MWE 开头。当然,答案可能会使用更花哨的索引包。

\documentclass[10pt]{article}

\usepackage{makeidx}
\makeindex
\begin{document}

This paragraph references itself. The index entry should point here,
and to itself. \index{self-reference}

In this short document, the index on page 2 should read

self-reference, 1, 2

\printindex

\end{document}

答案1

这是一个非常简单的解决方案(可能不是特别强大)。

\documentclass[10pt]{article}

\newcommand\mycommand[1]{#1, \thepage}
\usepackage{makeidx}
\makeindex
\begin{document}

This paragraph references itself. The index entry should point here,
and to itself. \index{selfreference|mycommand} 

In this short document, the index on page 2 should read

self-reference, 1, 2

\printindex

\end{document}

答案2

这似乎有效(中间需要运行makeindex两次pdflatex

\documentclass[10pt]{article}

\usepackage{makeidx}
\makeindex

\newcommand{\selfreference}{\string\selfreference}

\begin{document}

This paragraph references itself. The index entry should point here,
and to itself. \index{self-reference@self-reference\selfreference}

In this short document, the index on page 2 should read

self-reference, 1, 2

\renewcommand{\selfreference}{\index{self-reference@self-reference\string\selfreference}}
\printindex

\end{document}

在此处输入图片描述

相关内容