用定理编号替换索引中的页码

用定理编号替换索引中的页码

我想创建一个引用定理编号而不是页码的索引。

以下示例创建带有页码的常用索引:

\documentclass[ngerman, 12pt]{article}
\usepackage{makeidx}
\makeindex

\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}
This theorem is about apples \index{apple} and bananas\index{banana}.
\end{theorem} 

\begin{theorem}
This theorem is about apples \index{apple} and pies\index{pie}.
\end{theorem} 

\newpage

\begin{theorem}
This theorem is about bananas\index{banana}.
\end{theorem} 

\printindex

\end{document}

结果如下:

索引
苹果 1
香蕉 1 馅饼
2

然而,我需要索引中的定理编号,即

索引
苹果,1,2
香蕉,1,3 馅饼
,2

有人知道怎么做吗?非常感谢您的支持!

答案1

\index写出 的值\thepage。只需将其更改为 即可\thetheorem

\documentclass[12pt]{article}
\usepackage{etoolbox}
\usepackage{makeidx}
\makeindex

\makeatletter
\patchcmd\@wrindex{\thepage}{\thetheorem}{}{}
\makeatother

\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}
This theorem is about apples\index{apple} and bananas\index{banana}.
\end{theorem} 

\begin{theorem}
This theorem is about apples\index{apple} and pies\index{pie}.
\end{theorem} 

\newpage

\begin{theorem}
This theorem is about bananas\index{banana}.
\end{theorem} 

\printindex

\end{document}

在此处输入图片描述

相关内容