Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've used amsmidx to create a separate notational index.

\usepackage{amsmidx}
\makeindex{idx}
\makeindex{nidx}
\newcommand{\idx}[1]{\index{idx}{#1}}
\newcommand{\nidx}[1]{\index{nidx}{#1}}

I need to index symbols like $\int_{\mathcal{D}}$, $\int^{\underline{\mathcal{D}}}$ (resp an end, an enriched coend). But doing so breaks everything. If I type

\nidx{$\int^{\mathcal{C}}$}

and then run makeindex nidx, it will accept but then on the next pass I'm told there is a missing $. Indeed, when I look in the nidx.ind file I see

\item  ^{\mathcal  {C}}$, 6

I thought the issue might be that makeindex doesn't know how to alphabetize these entries but

\nidx{int@$\int^{\mathcal{C}}$}

causes makeindex nidx to reject the entry. (But then everything else compiles at least.)

Any idea what's going wrong?

share|improve this question
add comment

1 Answer

The \index macro tries hard not to expand its argument, but if you give it as an argument to another command this protection does not work any more; you should do

\newcommand{\idx}{\index{idx}}
\newcommand{\nidx}{\index{nidx}}

so that the call \nidx{int@$\int$} will be first transformed into

\index{nidx}{int@$\int$}

but without absorbing the main argument; now \index will apply correctly its protection mechanism.

The problem, of course, might present again in case \nidx{int@$\int$} is buried as argument to another command; in such cases, I hope rare, put \protect\int instead of \int.

What other commands need this protection if the index entry appear in the argument to a command? It's hard to make a list; surely \mathcal doesn't, but \int and \underline do. Just look at the produced idx files and it will be quite obvious which ones.

share|improve this answer
    
Brilliant, thank you! That sorted me out. I didn't need to protect any of this but I'll remember for the future. –  Emily Riehl Feb 18 '13 at 18:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.