Still more indexing woes. LaTeX indexing, while superficially easy to use, turns out to be rather finicky, especially for anchor placement—that is, where the index (hyper)link actually points to.
Let’s see what I have found to circumvent some of the difficulties.
Naïvely, I expected the \index command to ignore surrounding spaces and glue itself to whatever came next. But, you’ve guessed, that’s not how LaTeX works (and I should’ve known). If an \index entry lies alone on a line, LaTeX considers it followed by a space, which, of course, detaches it from what follows. There’s no obvious problem until you manage to get a paragraph that starts at the top of the page. Then, your index entries that precede it may actually be left on the previous page. The solution is to glue the \index to the following text using % signs.
Let’s examine the following LaTeX snippet:
Notice the % at the end of lines:
LaTeX ignores all leading white spaces (from the start of the line to the start of the text) and lines ending with % (without spaces before) are considered as a line continuing line, that is, without a newline. The net effect is that the use of %, as shown in the image, is that all \index entries are seen as contiguous. More, they’re all using the same anchor: the start of the paragraph. If the paragraph starts at the top of the page, the index entries will point on the same page, not on the preceding page, as they would if they weren’t by %.
You can define “see” and “see also” entries:
Note also melange@Mélange in the first highlighted line. Unfortunately makeindex, the default indexer isn’t very smart about sorting, as it doesn’t know about accentuated letters—because all languages in the world are written only in plain ASCII. The trick is to use a “@” substitution: melange is used for sorting, Mélange is displayed.
Indexing also allows ranges. Entries ending with |( will start a range. Ranges are closed with exactly matching index entries, except ending in |).
I did not expect indexing to be such a woe. But, eventually, I figured out its two main problems: 1) it knows nothing about accentuated letters, and 2) it’s vulnerable to (non rigid) white spaces.