# How to “\DoNotIndex \,” in a dtx file?

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

\DoNotIndex{\,}


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:

\DoNotIndex{\,,\addtocounter}

-
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 \}. –  karlkoeller Jul 20 '13 at 17:03
\#, \\$, \%, \^, \_, \~, \ , and \& are also problematic. See here for explanation and possible workarounds. –  Robert Jul 20 '13 at 17:13
@Robert thanks, I was not aware of them. –  karlkoeller Jul 20 '13 at 18:06

\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
%<*driver>
\documentclass{ltxdoc}
\CodelineIndex
\EnableCrossrefs
\IndexPrologue{}
\DoNotIndex{\,}
\expandafter\DoNotIndex\expandafter{\string\{}
\expandafter\DoNotIndex\expandafter{\string\}}
\begin{document}
\DocInput{\jobname.dtx}%
\end{document}
%</driver>
% \fi
%    \begin{macrocode}
%<*package>
\relax \, \thinspace \{ \}
%</package>
%    \end{macrocode}
%
% \PrintIndex
% \Finale


-