7

Please compile the following MWE. As you will then see, the typesetting of $\mu^{\otimes\downarrow n}$ in the index is strange!

\documentclass{article}
\usepackage{amsmath}
\usepackage{imakeidx}
\makeindex
\begin{document}
\begin{align}\index{$\mu^{\otimes\downarrow n}$}
x
\end{align}
\printindex
\end{document}

NB: No problem for equation instead of align or if $\index{$\mu^{\otimes\downarrow n}$}$ is placed before \begin{align}.

What's wrong here?

Karlo
  • 3,257
lpdbw
  • 8,330
  • 1
    I can confirm this. The idx file contains \delimiter "3223379, which prints as a large bracket, instead of \downarrow. This occurs for other AMS environments including gather and multline, but as @lpdbw says it is fine for equation – Andrew Swann Aug 15 '12 at 08:36

1 Answers1

6

Normally the argument of \index is read verbatim, but ams alignments act like command arguments and defeat verbatim so the argument is read as command tokens and the entry expands to

 \indexentry{$\mu ^{\otimes \delimiter "3223379 n}$}{1}

which messes up the index. You could use

\index{$\mu^{\otimes\protect\downarrow n}$}

which would work, but produces different index entry to the command when used in equation or other normal environments. Probably the simplest way to ensure that all uses of this produce the same index entry is to use

\mbox{\index{$\mu^{\otimes\protect\downarrow n}$}}

where the \mbox is just there to force the argument into a macro argument so that the verbatim processing is turned off consistently.

David Carlisle
  • 757,742
  • Sorry, I still don't understand why \downarrow is transfomed into \delimiter "3223379!? – lpdbw Aug 15 '12 at 09:49
  • 1
    That's its definition:-) plain tex defines \def\downarrow{\delimiter"3223379 } The hex number tells TeX which font(s) to extract the symbol from at normal and large sizes – David Carlisle Aug 15 '12 at 09:52
  • 1
    latex defines it as \DeclareMathDelimiter{\downarrow} {\mathrel}{symbols}{"23}{largesymbols}{"79} which is easier to read but it makes the same definition in the end. – David Carlisle Aug 15 '12 at 09:54
  • See also http://tex.stackexchange.com/a/41144/4427 – egreg Aug 15 '12 at 10:36
  • @egreg, oh it's an exact duplicate. Still This one has a title that makes it more likely it would be found again I doubt anyone but you (remembering your previous answer) would have spotted that:-) "wow" yes it's pretty amazing it goes through so many wrong expansions and produces something that produces output at all. – David Carlisle Aug 15 '12 at 11:06
  • @DavidCarlisle It's not really an exact duplicate; but also in this case I'd recommend something like \index{...@...} for correct alphabetizing. If you try \index{\detokenize{$\mu^{\otimes\downarrow n}$}} there will be spaces after the control sequences. – egreg Aug 15 '12 at 12:01
  • 1
    To get the same index entry \indexentry{$\mu^{\otimes\downarrow n}$}{...} is written by \index{$\mu^{\otimes\downarrow n}$}, if \index can read its argument in verbatim manner (outside of align), or by \index{$\string\mu^{\string\otimes\protect\downarrow n}$}, if \index and its argument is already read before \index is executed (inside align or \mbox). \string does not append a space after a control sequence name, but \protect or \detokenize do. – Heiko Oberdiek Aug 15 '12 at 12:03
  • yes the spaces issue is why I suggested using the \protect in argument form (so you get the same spaces always), \detokenize is essentially the same thing (or at least, has the same issues). I agree though for any symbolic entry using a @ field to help the sorting is wise. – David Carlisle Aug 15 '12 at 12:05
  • @HeikoOberdiek yes I thought about suggesting that but decided it was simpler to suggest turning off verbatim and using the same argument everywhere (then it doesn't really matter so much about whether spaces are added as they are added consistently) – David Carlisle Aug 15 '12 at 12:22
  • @David Carlisle: OK, I understand your above comment about the definition of \downarrow in LaTeX and plain TeX. Just why then does this definition produce something else in in the index? I certainly missed something in your explanations ... – lpdbw Aug 15 '12 at 12:30
  • 2
    See egreg's great answer in the link from his comment. basically the " means hex-number in Tex but (by default) it is a quote character for makeindex, so it quotes the next thing, which is a digit, which just produces itself, so makeindex carries on but produces something without the " which then gets interpreted by TeX as a decimal number and anything that happens after that is purely accidental.... – David Carlisle Aug 15 '12 at 12:34
  • 1
    @DavidCarlisle Then I would consider something like \newcommand*{\Index}[1]{\index{\detokenize{#1}}} to avoid trouble with macro expansion. – Heiko Oberdiek Aug 15 '12 at 14:23
  • @HeikoOberdiek, Good plan. – David Carlisle Aug 15 '12 at 14:36