I am generating a very large number of index entries containing formatting in a LaTeX document, and some of them are in regions that affect the premature tokenisation of the argument (footnotes, optional argument to \item, etc) so that I get two identical-looking entries on the same page in the .idx file, one with spaces after the formatting (eg \textit␣␣{foo} as well as \textit{foo}).
This has been dealt with in a question on index entries in footnotes and a response link to a question on named indexes but only in the case of multiple indexes (with an optional parameter to the \index command).
Is there a way to solve this for a single index? I can't see from the two pages above how to generalize the solution.
[And, incidentally, I would be interested to know where the two bogus spaces actually come from, and why the tokenisation inserts them.]
\let\oldindex\index\def\index#1{\oldindex{#1}}sure this is a duplicate I'll see if I can find – David Carlisle Jul 17 '20 at 21:36