Consider the following document:
\documentclass{memoir}
\usepackage{tabu}
\makeindex
\begin{document}
This is the \emph{aaa} variable.\index{aaa variable@\emph{aaa} variable}
\begin{tabu}{l}
\emph{aaa}\index{aaa variable@\emph{aaa} variable}
\end{tabu}
\printindex
\end{document}
In this document I use the index string \index{aaa variable@\emph{aaa} variable} twice, once outside a tabu environment, once inside it. The result is that the generated .idx file contains these lines:
\indexentry{aaa variable@\emph{aaa} variable}{1}
\indexentry{aaa variable@\emph {aaa} variable}{1}
which means that \printindex will print two entries in the index, rather than just one.
What can I do?
EDIT
A comment referred me to a related question where a \string in front of \emph in the tabu environment would solve the problem, and indeed it does.
But if I need to use the tabu* environment instead of tabu this still not works.
Replacing tabu with tabu* and \index{aaa variable@\emph{aaa} variable} with \index{aaa variable@\string\emph{aaa} variable} inside the environment, gives me this content in the .idx file:
\indexentry{aaa variable@\emph{aaa} variable}{1}
\indexentry{aaa variable@\string \emph {aaa} variable}{1}
tabu*environment it appears that I need to do both. I need to add\stringand I need to use your\hmmcommand. Doing just one of them doesn't work. But now I have a solution - so what do I do with this question? If you turn your comment into an answer, I'll acknowledge it. – oz1cz Apr 10 '15 at 09:33\indexinside the argument of a command, or inside the body of an environment that uses such a command internally (tabu, tabularx, ams alignments, ....) – David Carlisle Apr 10 '15 at 10:22