I'm using \EnableCrossrefs in a dtx file. In the index I now have \, indexed. I tried \DoNotIndex{{\,}} and \DoNotIndex{\thinspace} without success.

Is there a way to prevent the inclusion of \, in the index?


Just putting


should work, no need for redundant braces.

If you want to add more things that don't need to be indexed, you can simply add a comma:

  • I suspect this doesn't work
    – Joseph Wright
    Jul 20 '13 at 16:42
  • @karlkoeller Wow, that's spooky, this really works! I didn't try this, because i thought this will never ever work! ;-)
    – Josef
    Jul 20 '13 at 16:58
  • AFAIK, it doesn't work only for \{ and \}. Jul 20 '13 at 17:03
  • 3
    \#, \$, \%, \^, \_, \~, \ , and \& are also problematic. See here for explanation and possible workarounds.
    – Robert
    Jul 20 '13 at 17:13

\DoNotIndex{\,} works by accident:

  1. \DoNotIndex changes the catcode of \ to 12 (other) and adds \,, to the list of excluded commands, the token register \index@excludelist. The second comma is the separator.

  2. Macro \ifnot@excluded then looks for the string consisting of a backslash \, the macro name part and the separator comma , in the list for a match using LaTeX's \@@in in the end. Because \, contains already a comma, the algorithm gets confused does not interpret the comma as macro name, but as separator comma. Therefore \, is found in the list of excluded commands.

  • Also \{ and \} work with a trick. Because \DoNotIndex changes the catcode of the backslash \, the curly braces are not properly nested anymore. Also catcode 12 (other) is needed for the curly braces. Thus \string helps as the example shows.

An example that shows the exclusion of \,, \{, and \}:

% \iffalse
% arara: pdflatex: {draft: yes}
% arara: makeindex: {style: gind}
% arara: pdflatex
% \fi
%    \begin{macrocode}
\relax \, \thinspace \{ \}
%    \end{macrocode}
% \PrintIndex
% \Finale


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.