7

Some mathematics texts honor an unspoken tradition by providing a few strange index entries. I'd like to have an index entry that refers to itself. Here's a (N)MWE to start with. Answers may use a fancier index package, of course.

\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
  • if you use index style file add delim_t ", \\thepage"
    – touhami
    Oct 12, 2015 at 15:29

2 Answers 2

5

Here is a very simple solution (which may not be especially robust).

\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}
1
  • Works beautifully, I prefer it to @egreg 's since all the work is in the preamble. In the document there's a link to the real self reference, but only the page number for the second. But that's fine since by definition you're already on the page. Oct 12, 2015 at 16:19
2

This seems to work (needs two runs of makeindex with pdflatex in between.

\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}

enter image description here

This site is temporarily in read-only mode and not accepting new answers.

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