# Makeindex error when ! used in \index in align environment

See MWE below. The symbol ! in the \index causes an error. This is only the case in align environments (not in equation). So it seems to have to do something with amsmath. If ! is put in an \mbox there is no error. But then of course the font size is not adjusted to subindices. Curiously enough, \index{$C_{K!!}$} (two exclamation marks) doesn't cause any error.

\documentclass{article}
\usepackage{amsmath}
\usepackage{imakeidx}
\makeindex
\begin{document}
\begin{align}
y\index{$C_{K!}$}
\end{align}
\printindex
\end{document}


Any solutions suggested?

-

For makeindex the symbol ! has a specific meaning.

The manual of makeindex (texdoc makeindex) has the following example / explanation:

To produce a subentry, the argument of the \index command should contain both the main entry and the subentry, separated by a ! character.

Page 7:  \index{gnat!size of}  || gnat, 32
Page 32: \index{gnat}          ||     anatomy, 35
Page 35: \index{gnat!anatomy}  ||     size of, 7
\index{gnus!good}     || gnus
||    good, 35


To print out the symbol ! the manual shows

To put a !, @, or | character in an index entry, quote it by preceding the character with a ".

So the correct usage of your example is:

\begin{align}
y\index{$C_{K"!}$}
\end{align}


The quoted character can be changed my setting up the following line in the style file:

 quote '+'


Now the quoted character is +. E.g. for German language it's important than "a becomes ä.

-