How to fix symbol index entry?

All my entries in the symbol index involving $\|\cdot\|$ get rejected. For instance {\index{symbol}{normx@{$\|\cdot\|_X$}}}.

How can I fix this?

-
Can you please add to your question a minimal working example illustrating the problem? –  Gonzalo Medina May 28 '12 at 4:17
Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. –  Peter Grill May 28 '12 at 4:54

The symbol | is special within the \index command as it deals with special page ranges. You need to hide this from TeX using something like

\newcommand{\norm}{\|}


Also note that \index takes only one argument which is the index entry. If you want to also print this entry in text, you need to use the following format:

...blah blah symbol\index{symbol} blah blah...


virtually duplicating the typeset component and index entry. Here's your MWE with a the above modifications:

\documentclass{article}
\usepackage{makeidx}% http://ctan.org/pkg/makeidx
\newcommand{\norm}{\|}
\makeindex
\begin{document}
See $\|\cdot\|_X$\index{normx@$\norm\cdot\norm_X$} and the norm\index{norm}.

\printindex
\end{document}


Consider reading through Leslie Lamport's MakeIndex : An Index Processor For LaTeX.

-

Special characters for MakeIndex should be quoted: so to index |x| you have to write

\index{"|x"|}


The " character before a special character makes it lose its meaning. However \" is not treated in a particular way (it's an accent command), so your entry should be

\index{"\"|x"\"|}


or \index{normx@"\"|x"\"|} if you want a string for specifying the alphabetic order.

If you use more entries with | than entries such as \index{abc|see def} you can create a personal MakeIndex style containing just one line

encap '*'


Call this file mystyle.ist and call MakeIndex as

makeindex -s mystyle.ist filename


This will disable the special feature of | (whose role is taken by *) and so you can type \index{normx@$\|x\|$} without other precautions.

-