\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}