3

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}
This theorem is about bananas\index{banana}.
\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!

1

1 Answer 1

5

\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}
This theorem is about bananas\index{banana}.
\end{theorem} 

\printindex

\end{document}

enter image description here

6
  • How did you change the value to \thethorem? Because if I execute your code, I still get an index showing the page numbers.
    – Jack
    Commented Sep 14, 2019 at 8:50
  • @Jack Really? The exact code?
    – egreg
    Commented Sep 14, 2019 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
    Commented Sep 14, 2019 at 10:17
  • @Jack In the example code, ngerman does nothing at all, except printing a warning on the console. Maybe you added babel?
    – egreg
    Commented Sep 14, 2019 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
    Commented Sep 14, 2019 at 10:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .