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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to print the index numbers which are referring to a code line number instead of a page in typewirter font.

I know that I can change \main, but on this way I can’t change the format of the auto indexed commands.


% \iffalse



% \fi
% \DoNotIndex{\newcommand}
% \section{Usage}
% \DescribeMacro{\test} This is a stupid example
% for \cmd{\test}, but it prducec the right index
% formatting.
% \StopEventually{\PrintIndex}
% \section{Implementaion}
% \begin{macro}{\test}
% This is how Test is defined
%    \begin{macrocode}
\newcommand{\test}{Some text}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\supertest}
% And here \cmd{\test} is used in another macro
%    \begin{macrocode}
\newcommand{\supertest}{\test{} without sense}
%    \end{macrocode}
% \end{macro}
% \Finale

build with

pdflatex example.dtx
makeindex -s gind.ist -o example.ind example.idx
pdflatex example.dtx



But it should be
\test . . . . . . 1,1,2
(with 1 underlined)

share|improve this question
up vote 1 down vote accepted

You may try


after loading the class.

Indeed, in the index writing process, the class uses directly \number\c@CodelineNo, so this should work.

Writing also


will use typewriter type for the line numbers in the index, but consecutive line numbers will not be printed correctly (they form a unique link, so also the comma will be printed in typewriter type). This can be cured by calling makeindex with the -r option (that disables page ranges formation).

share|improve this answer
I tried it, but the font change affects only the line numbering in the implementation part but not the numbers in the index. – Tobi Sep 20 '11 at 12:36
This seems to be quite difficult to solve. :( – egreg Sep 20 '11 at 13:19
My idea was to find the lines in doc.sty that generate the entry and change them to add |texttt but I failed to find these lines … – Tobi Sep 20 '11 at 13:35
Unfortunately doc and hypdoc don't use the standard \index command, but do their own writing. – egreg Sep 20 '11 at 14:17
And can we (or better: you …) hack/patch into it? Could you please point me the relevant lines, so I can have a look myself. – Tobi Sep 20 '11 at 15:09

Your Answer


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.