0

This question already has an answer here:

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}

marked as duplicate by David Carlisle, egreg xetex Nov 13 '15 at 9:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • This is a "feature" must be a duplicate I'll see if I can find but the easiset thing is to use \newcommand\foo[1]{#1} and then use \foo for \foo{\index{...} when you don't use \emph then they'll all be the same. the reason is that \index tries 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 9:14
  • Thank you! From what I understood from your reply is that i have to wrap all index-commands in an empty command. This works and I will update my question for anyone who has the same problem. – Martin Mueller Nov 13 '15 at 9:34
  • any given index argument should be always in, or always not-in an argument so that space is the same) It's best not to put the answer in the question, you could self-answer but I'm trying to see the duplicate (I know I've answered before:-) – David Carlisle Nov 13 '15 at 9:38

Browse other questions tagged or ask your own question.