[texhax] indexing problem

Uwe Lueck uwe.lueck at web.de
Sun May 21 23:12:42 CEST 2006

As I contributed to the thread some weeks ago -- 

Oleg Katsitadze <olegkat at gmail.com> schrieb am 20.05.2006 14:12:20:
> Hi,
> As nobody answered your question, I try to give you some
> clues.  Hope I'm not too late.
late as well -- 

> Since I am a plain TeX user, I can only guess at what LaTeX
> does and why what you want is not working, but I can't give
> you a proper LaTeX solution.
> First of all, take a look at the file with the same basename
> as your document and the extension `.idx'.  This is the
> intermediate file where LaTeX dumps all your index entries.
> This should clarify many things for you.
> You'll notice that in the entries from the text body, the
> macros like \pie and \ind are written "as is" (unexpanded),
> while in the entries from the footnote these macros are
> replaced by their definitions.
> The reason for this is as follows.  Normally, when TeX reads
> an argument of a macro, each token in the argument is parsed
> and converted into internal representation.  This means,
> among other things, that a string like "\ind" in the
> argument will become a single token for the macro \ind, not
> the four characters "\", "i", "n", and "d".
> On the other hand, LaTeX's \index macro is designed in a way
> that allows it to read the argument verbatim.  That is, a
> string like "\ind" in the argument of \index remains a
> four-character string "\ind", not the single token for the
> macro \ind.
> The consequence of the above is that in the text body, the
> argument of \index becomes a _verbatim_ string, and you can
> see that in the .idx file.  And what happens when \index is
> placed inside \footnote?  Well, \footnote does not read it's
> argument verbatim, therefore all macros (like \ind) in its
> argument become single tokens, not the verbatim strings.
> This means that by the time \index inside \footnote starts
> reading it's argument, all instances of \ind, etc., have
> already been converted into single tokens, and that's what
> \index gets.  When \index then writes its argument to the
> .idx file, these macros are expanded, which you can also see
> in the .idx file for the entries coming from the footnote.
> The outcome is that two instances of the same index entry
> appearing in the body and in the footnote are regarded by
> MakeIndex as different.  Even though they result in the same
> text in LaTeX, MakeIndex doesn't know that.
> Another consequence is that when you, as you say, define
> \pie as a@\textbf{PROTO-INDO-EUROPEAN}, the sorting doesn't
> work.  This is because, inside text body, \pie is written
> out _verbatim_ and MakeIndex doesn't see what you want it to
> see -- it sees `\pie' instead of a@\textbf{PROTO-INDO-EUROPEAN}.
... (well-explained!) ...

> One solution might be making \index parse its argument
> non-verbatim, plus expanding the first token of the argument
> (e.g., \pie).
> Unfortunately, I don't know how to do this in LaTeX, but in
> plain TeX you can define something like this:
>   \let\oldindex\index
>   \def\index#1{\oldindex{#1}}
> (Putting it after \makeindex in LaTeX seems to work, see the
> attached file.)  This works because the redefined \index now
> reads and parses its argument non-verbatim before passing it
> on to the original \index, so \pie will become a token
> regardless of whether it is inside a footnote or text body;
> it will be expanded when \oldindex writes it to the .idx
> file, so MakeIndex will see, e.g.,
> a@\textbf{PROTO-INDO-EUROPEAN} instead of \pie.
> But keep in mind that all macros inside the argument of the
> new \index are now expanded when written to the .idx file,
> which might cause problems with some macros.  Furthermore,
> \index and \oldindex read their arguments differently,
> therefore don't mix them.  Finally, probably my solution is
> seriously flawed since I'm not familiar with LaTeX; and
> certainly there are better solutions around (hopefully
> someone will point them out).
... the index package (for LaTeX) provides a well-tested 
solution to the problem. (At least I have been using it for 
many weeks even with index in footnotes.) ... 

> Hope this helps,
> Oleg
> PS. In the sample you provided I see lines like this:


> PPS. I think there are packages/classes providing \footnote
> which does not read its argument at all (memoir.cls?).  With
> such a package, \index would work the same both in the text
> body and in the footnote, so a better solution might be
> possible.

If I remember correctly, \vfootnote as defined in The TeXbook 
is such a variant of \footnote. Maybe footmisc reimplements it. 
Sorry, I am away from my PC and my manuals ... 


More information about the texhax mailing list