2

Following a related question, I have problems with giving the see macro (from makeidx) math input. The MWE:

\documentclass[a4paper,12pt]{article} 
\usepackage{makeidx}
\makeindex
\begin{document}
Test
\index{\string{$\mu$-recursive}}\index{recursive|see \string{$mu$-recursive}}

\printindex
\end{document}

The error messages in line 3 and 7:
Something like "Extra } or missing \endgroup".

What is the problem? As shown in the source code, I already evaluated the math content later by using \string.

2
  • I’m going to remove my answer (although you have accepted it) because it is wrong. The correct answer, however, is longer, and I cannot anticipate when I’ll have the time to write it. But perhaps someone else will answer in my place! :-)
    – GuM
    Oct 13, 2018 at 9:29
  • It looks like I cannot delete an accepted answer: please “un-accept” it, because, I repeat, it is wrong.
    – GuM
    Oct 13, 2018 at 9:31

2 Answers 2

0

Using \string is completely wrong.

\documentclass[a4paper,12pt]{article}
\usepackage{makeidx}
\makeindex

\begin{document}

Test\index{mu-recursive@$\mu$-recursive}\index{recursive|see {$\mu$-recursive}}

\printindex

\end{document}

Note how the format sort@entry is used for helping MakeIndex to correctly sort a non alphabetic entry.

enter image description here

2

\string is not like a command with an argument: with \string{ you are actually turning the opening brace into an ordinary character, thus making the ensuing } unbalanced. On the other hand, for the purpose of writing to a file, in this particular context you don’t need \string at all, since all the tokens that you want to write, including \mu, happen to be unexpandable:

\documentclass[a4paper,12pt]{article} 
\usepackage{makeidx}
\makeindex
\begin{document}
Test: \texttt{\meaning\mu}%
\index{$\mu$-recursive}\index{recursive|see{$\mu$-recursive}}

\printindex
\end{document}

In general, however, you shouldn’t use \string, but rather \protect: indeed, the latter can be safely applied to unexpandable tokens, while, at the same time, inhibiting premature expansion of expandable ones. In other words, unlike \string, \protect doesn’t require you to know the type (expandable vs. unexpandable) of the control sequence you want to apply it to.

\documentclass[a4paper,12pt]{article} 
\usepackage{makeidx}
\makeindex
\begin{document}
Test: \texttt{\meaning\mu}%
\index{$\protect\mu$-recursive}\index{recursive|see{$\protect\mu$-recursive}}

\printindex
\end{document}
1
  • In my specific original case, I tried this strateg once, but apparently did not generate new index files with makeindex,. Instead I trusted in TeXWorks "Remove Aux files...", which did not remove the faulty Ind files. The problem is solved. Thank you! Oct 13, 2018 at 7:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .