# [texhax] Two problems with \sidx

Barbara Beeton bnb at ams.org
Tue May 10 17:14:42 CEST 2011

On Tue, 10 May 2011, D. R. Evans wrote:

I have two issues (using eplain TeX):

1. If I have the following explicit inline text in my file, it gives no error:
{\sc nop}\sidx{{\sc nop} gate
This prints "NOP" in small caps and inserts the text "NOP gate" into the index.

However, if I define \nop as:
\def\nop{{\sc nop}\sidx{{\sc nop} gate}}
Then when the compiler reaches "\nop" in the text, TeX throws an error:
! Incomplete \iffalse; all text was ignored after line 1415.

I don't understand why this happens, nor how to fix it.

can't answer this one quickly; if no one

2. When I place the text inline:
{\sc nop}\sidx{{\sc nop} gate
then although the text "NOP gate" appears in the index, it does so *at the
start* of the index.

this one's easy though ...

If I look in the *.ind file, it begins:

----

\begin{theindex}

\item {\sc nop} gate, 21

\indexspace

\item BB84, 79

----

So it looks like makeindex is putting the entry in completely the wrong place.

The *.idx file has the following:
\indexentry{{\sc nop} gate}{21}
so my guess is that makeindex is sorting this entry according to either the
second "{" or the "\", which I suppose makes sense, but I haven't been able
think of a way around this: any sneakiness I've been able to think of
begins with "\" and so sorts incorrectly.

makeindex does no real parsing of the lines
in the .idx file until after they're sorted.
it performs a straight ascii sort on the text
provided, so, yes, the sort is on the open
brace, so it goes at the beginning of the .ind
file.

So how can I force the index entry to appear in the correct place in the
index?

give it a sort key:

\sidx{nop gate@{\sc nop} gate}

if you index this (or any multi-word term)
in more than one place, make sure that all
instances in the input are exactly the same;
spacing as well as spelling and tex commands
must be identical, or they'll sort separately,
even though they look the same when the index
is printed out.
-- bb