[texhax] math symbols in makeindex

Morten Høgholm morten.hoegholm at gmail.com
Wed Jul 27 21:07:45 CEST 2005

On Mon, 25 Jul 2005 17:32:13 +0200, Zbigniew Nitecki  
<zbigniew.nitecki at tufts.edu> wrote:

> Using the MakeIndex package to create an index, I wanted to have an
> entry, as if it were an ordinary R, but printed as a blackboard bold
> R.  The following indexing entry in the text
>      \index{R@$\mathbb{R}$}
> (following the rules on p. 652 of the Latex Companion, 2nd ed.) was
> rejected.  Here is the
> entry from the ilg file:
>      !! Input index error (file = Calculus.idx, line = 32):
>     -- Extra `@' at position 5 of first argument.
> The line referred to in the idx file is
>      \indexentry{R@$\@mathbb {R}$}{17}
> So the program itself seems to add an extra @, which creates an
> error.  How do I avoid the
> problem?

The problem here is that \mathbb expands to \protect\@mathbb and then  
\@mathbb does the real work. What you can do is to insert a \protect in  
front of the command.

However this problem, which Lars alerted me to, is really that \mathbb and  
others are built like robust commands, only they are not quite right. A  
robust command \foo expands to \protect\foo<space> (yes, that space is  
part of the command name) and then \foo<space> does the real work. So as  
you can see, \mathbb is close!

To fix your current document without adding \protect all over the place  
you can add something like this to your document just before  

% some tools...
\def\@let at cc#1#2{%
\def\@def at cpx#1{\expandafter\edef\csname#1\endcsname}
\def\@exp at not@c#1{\expandafter\noexpand\csname#1\endcsname}

\@for\reserved at a:=mathrm,mathnormal,mathcal,mathbf,mathsf,mathit,%
             \@def at cpx{\reserved at a}{\noexpand\protect\@exp at not@c{\reserved at a\space}}%
             \@let at cc{\reserved at a\space}{@\reserved at a}%

This turns all \@math<XX> commands into \math<XX><space> (also covers  
amssymb). If you have more of these \math<XX> commands then add them to  
the comma separated list. The \@undefined part is a safety valve because I  
have changed the LaTeX sources to do it The Right Way(TM) and so such  
redefinitions would be disastrous. There should be a release in the not  
too distant future.

Hope this helps,

More information about the texhax mailing list