# Conflict between tabu and index when using LaTeX formatting in index [duplicate]

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}


## marked as duplicate by David Carlisle, user13907, Andrew, Svend Tveskæg, moeweApr 10 '15 at 11:02

• Thank you, @DavidCarlisle. I did some experimentation, and for the tabu* environment it appears that I need to do both. I need to add \string and I need to use your \hmm command. 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 9:33
• well it's probably a duplicate of the other question in that case, maybe you could leave a comment on one or both of the answers there. (It's the same issue and affects any use of \index inside 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