4

I'm trying to create an index of notation for my paper. I'd like to sort the index items chronologically by order of appearance. In other words, if I have the symbol $Z$ occurring on the second page, the symbol $C$ on the 8th page and the symbol $P$ on the last page I would like the index to appear as

Z, 2 
C, 8
P, 97

Do you know how to do it automatically?

Marco Daniel
  • 95,681
  • 2
    Welcome to TeX.SE.

    It is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. I realize it is not complicated but any time you can save those trying to help would be helpful.

    – Peter Grill Jan 23 '12 at 17:44

1 Answers1

5

here's an approach that uses labels for the symbols and \pageref to keep them in input order. the \pagerefs need to be expanded before writing to the .idx file; ordinarily index material is written out verbatim. this even permits multiple page references to the same symbol; in such a case, only the first appearance should get a label.

the routine needs some more work, since at the moment it trims off leading zeros from \pageref numbers, so if there are any entries on pages 1-9 they will be out of order in an index for a book of up to 99 pages, etc. (it would probably be best to normalize on 3-digit page numbers.) i'll work on that when time permits, but if someone else gets there first, go for it!

i'm also not sure what would happen with a symbol first introduced in a preface, or on some other page numbered with roman numerals. another open problem.

\documentclass{book}
\usepackage{makeidx}
\makeindex
\newcommand{\xindex}[2]{\expandafter\index\expandafter{\pageref{#1}#2}}
\begin{document}
\chapter{One}
some text $Z$\label{not:Z}\xindex{not:Z}{@$Z$} some more text.

\newpage
some text $C$\label{not:C}\xindex{not:C}{@$C$} some more text.

\newpage
some text $P$\label{not:P}\xindex{not:P}{@$P$} some more text.
and a second reference to a symbol that first appeared on a previous page
$C$\xindex{not:C}{@$C$} some more text.

\printindex

\end{document}