I want to generate an index that entry that points ONLY to itself, not any other place in the text. That is, I want a command \phoneyindex{Smith, John} which when put in the preamble generates an index entry to John Smith pointing ONLY to the page in the index on which it occurs.

Any ideas?

1 Answer 1


The question is quite Knuthian! Index entries may be written in the form

 \index{John Smith|cmd}

where \cmd is a command that is applied to the page number value. A first approach would be to use


and issue

 \index{John Smith|mypageout}

somewhere in your document so the printed page number x is replaced by \mypageout{x}, which is just current output of \thepage. However, as you point out, at page boundaries \thepage is often off by 1, due to the way page building works. Alternatively, you can use the \label/\pageref mechanism as follows: define a \mypageout macro that discards its second argument and makes a label from the first, and use this with a first argument in the command part of the \index


You then call this with \phoneyindex{John Smith}{phoneyj}, where the phoneyj is the label you wish to use. This is now correct on entries just after page boundaries.

Page 5

Page 5

Page 6

Page 6





\phoneyindex{Allan Smith}{phoneya}
\phoneyindex{John Smith}{phoneyj}




  • This worked perfectly in one instance, but in another (where the item was near the top of the page) the page number was off by one (it had the previous page number). Is there any way around this? May 3, 2017 at 21:29
  • 1
    Indeed you are right. I have now updated my answer with a better method - the cost: you have to specify a label name for each entry. May 4, 2017 at 6:48

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.