I would like to index some text elements that may contain code, for example:
foo of type \code{bar}
where \code
is something like \texttt
. But when I stick this text into \index
, the collation is different between code and normal text:
\index{foo of type \code{bar}}
\index{foo of type abc}
\index{foo of type unknown}
The collation is wrong, and to get the correct collation, I would need to say:
\index{foo of type bar@foo of type \code{bar}}
\index{foo of type abc@foo of type abc}
\index{foo of type unknown@foo of type unknown}
However, this is tedious to maintain.
Is it possible to write a single command that creates the stripped "bare" text for the collation? Ideally, something like:
\myindex{abc \code{def} ghi}
that becomes
\index{abc def ghi@abc \code{def} ghi}
?
It would be acceptable if the mechanism is only able to strip one particular command (such as \code
above).
Small example to reproduce:
\documentclass{article}
\usepackage{makeidx}
\makeindex
\begin{document}
\index{aba}
\index{abc}
\index{abe}
\index{ab\texttt{b}}
\index{ab\texttt{d}}
\printindex
\end{document}
This collates incorrectly. I would like a macro I could use in place of \index
that would produce the correct collation order "aba", "abb", "abc", "abd", "abe".