Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to make an symbol index which is sorted by occurence of symbol.

For example: Something like

... $\omega$\index{$\omega$} ... $A^P_k$\index{$A^P_k$} ... $\{\}$\index{$\{\}$}

should produce an index which first mentions $\omega$ then $A^P_k$ and then $\{\}$.

I did not find any option for makeidx, so I tried to use a workaround and define a command which does that for me:

\newcounter{occurrence}
\newcommand{\is}[1]{\index{\arabic{occurrence}@{#1}}\addtocounter{occurrence}{1}}

In fact this works to some extend but some symbols get rejected (I do not know which one) and some will not be printed appropriate for example \is{$\langle \rangle$} results in the entry "hAB".

share|improve this question
    
You find a transcript of MakeIndex workings in the .ilg file. –  egreg Jan 15 '12 at 10:12
add comment

2 Answers

up vote 12 down vote accepted

The problem is that \index expands its contents, so with \is{$\langle\rangle$} you get, in the .idx file,

\indexentry{0@{$\delimiter "426830A \delimiter "526930B $}}{1}

and, in the .ind file,

\item {$\delimiter 426830A \delimiter 526930B $}, 1

(notice that the double quotes get lost).

Now TeX finds \delimiter followed by the number 426830, which is hexadecimal "6834E and since it's in normal operations, it typesets the math code "0068: in position "68 of font family 0 there's an h. Similarly, 526930 is hexadecimal "80A52, but in position "80 there's no character! So you get a roman h, followed by italics A and B. Wow!

A way out is telling TeX not to interpret the characters:

\newcommand{\is}[1]{%
  \index{\arabic{occurrence}@\detokenize{#1}}%
  \stepcounter{occurrence}}
share|improve this answer
add comment

You can control the order of the things in the index by providing some additional information to the argument of the \index command.

By writing \index{<sort information by>@<information>}, you tell \index to put <information> in the index but sort it by <sort information by>.

For example, using the following:

  • \index{.a omega@$\omega$}
  • \index{.a alpha@$\alpha$}
  • \index{.b APK@$A^P_k$}
  • \index{.c \{\}@$\{\}$}
  • \index{a}
  • \index{A}

The entries in the index should be as follows:

  • $\alpha$;
  • $\omega$;
  • $A^P_k$;
  • ${}$;
  • A;
  • a.

In this example, I use . as a prefix for index material with mathematical content (it effectively forces the mathematical stuff before the letters), and <letter> as a presorting criterion.

The following shows how to adjust the \index command to make it 'sort' the indexes by occurrence. This solution is equivalent to the solution that was posted by egreg.

\makeatletter

\newcount\index@counter
\let\old@index\index
\def\myindex@#1#2{%
    \old@index{#1@#2}%
}
\def\index#1{%
    \expandafter\myindex@{\the\index@counter}{#1}%
    \advance \index@counter by 1\relax
}
\makeatother
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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