Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

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}
share|improve this answer
    
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
1  
\#, \$, \%, \^, \_, \~, \ , 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
add comment

\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

Result

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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