6

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

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}
  • 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. – Ethan Bolker Oct 12 '15 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.