# Replace page numbers in index by theorem numbers

I would like to create an index that refers to theorem numbers instead of the page numbers.

The following example creates the usual index with page numbers:

\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}
\end{theorem}

\printindex

\end{document}


The result looks like this:

Index
apple, 1
banana, 1, 2
pie, 1

However, I would need the theorem numbers in the index instead, i.e.

Index
apple, 1, 2
banana, 1, 3
pie, 2

Has anyone an idea how to do this? Thank you very much for your support!

\index writes out the value of \thepage. Just change it to \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}
\end{theorem}

\printindex

\end{document}


• How did you change the value to \thethorem? Because if I execute your code, I still get an index showing the page numbers.
– Jack
Sep 14 '19 at 8:50
• @Jack Really? The exact code? Sep 14 '19 at 8:56
• Yes. And if I compare your code with mine, the only difference I can identify is that you have deleted the "ngerman" from the documentclass
– Jack
Sep 14 '19 at 10:17
• @Jack In the example code, ngerman does nothing at all, except printing a warning on the console. Maybe you added babel? Sep 14 '19 at 10:35
• It is fine, that you have removed ngerman. But still, how did you change the value of the index from \thepage to \thetheorem - I do not find this part in your code.
– Jack
Sep 14 '19 at 10:43