index entry referring to itself

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}

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

Tags:

Indexing