this code produces two entries for the sub-item in the Index:
\documentclass{scrbook}
\usepackage{imakeidx}
\makeindex
\begin{document}
A word\index{A word!Subitem@\emph{Subitem}} and another word\index{A word!Subitem@\emph{Subitem}} and an \emph{italic word\index{A word!Subitem@\emph{Subitem}}}.
\printindex
\end{document}
The source of the problem seems to me the \emph{} envelopping the \index containing an \emph. (Same thing happens when I use \italics, b.t.w.)
The .idx-file has a strange whitespace after the \emph:
\indexentry{A word!Subitem@\emph{Subitem}}{1}
\indexentry{A word!Subitem@\emph{Subitem}}{1}
\indexentry{A word!Subitem@\emph {Subitem}}{1}
Is this a bug or is there a solution apart from changing to xindy?
== Solution == With the solution provided below I understand now, that all is correct, when I wrap the \index-command in an empty newcommand. So this produces the correct output:
\documentclass{book}
\usepackage{imakeidx}
\newcommand\findex[1]{\index{#1}}
\makeindex
\begin{document}
A word\findex{A word!Subitem@\emph{Subitem}} and another word\findex{A word!Subitem@\emph{Subitem}} and an \emph{italic word\findex{A word!Subitem@\emph{Subitem}}}.
\printindex
\end{document}
\newcommand\foo[1]{#1}and then use\foofor\foo{\index{...}when you don't use\emphthen they'll all be the same. the reason is that\indextries to read its argument verbatim , but that fails in the argument of any command. or don't put any index in the argument and use{\em\index{zzz}\/}instead of\emph– David Carlisle Nov 13 '15 at 09:14