[texhax] Two problems with \sidx

Heiko Oberdiek heiko.oberdiek at googlemail.com
Tue May 10 17:13:48 CEST 2011


On Tue, May 10, 2011 at 08:35:41AM -0600, 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.

\sidx reads its argument verbatim, but catcode changes does not
have an effect if used inside other stuff like a definition.
Thus \sc is read as command and executed if \nop is called.
But \sc is not robust (in LaTeX sense) and breaks.

> I don't understand why this happens, nor how to fix it.
> 
> 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.
> 
> If I look in the *.ind file, it begins:
> 
> ----
> 
> \begin{theindex}
> 
>   \item {\sc nop} gate, 21
> 
>   \indexspace
> 
>   \item BB84, 79

You have to specify a sort key, otherwise the symbols in front
of "nop" are seen first.

\def\nop{%
  {\sc nop}%
  \sidx{nop gate\idxsortkeysep{\string\sc\space nop} gate}%
}

Yours sincerely
  Heiko Oberdiek


More information about the texhax mailing list