I have a problem using the \index command in an argument to a user-defined command. For some reason, the problem only appears when I use the @ symbol. The following example illustrates the problem:
\documentclass[a4paper]{book}
\usepackage{makeidx}
\makeindex
\newcommand\myFoo[1]{#1}
\begin{document}
\chapter{The first chapter}
\index{one}
\index{\texttt{two}}
\myFoo{\index{one}}
\myFoo{\index{\texttt{two}}}
\printindex
\end{document}
When I typeset this source code (with the pdflatex and makeindex commands), the index looks like this:
two, 1 two, 1 one, 1
So, the "two" entry is displayed twice (in typewriter font), the "one" entry is (correctly) only displayed once. The same problem occurs when I use the @ operator.
The idx file generated by LaTeX is:
\indexentry{one}{1}
\indexentry{\texttt{two}}{1}
\indexentry{one}{1}
\indexentry{\texttt {two}}{1}
I guess the problem is caused by these two spaces before the { character in the last index entry, but I do not understand why these spaces are there.
Can somebody explain why entries with formatting commands and entries without them give different results here, and suggest a solution?
\indexin command definitions, not in command arguments. But yes, the question you linked, and especially your answer there, are very helpful. Thanks! – Hoopje Dec 03 '14 at 09:11