# doc.sty: Print codelinenumbers in index in tt font?

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.

Example

% \iffalse
%<*driver>
\ProvidesFile{example.dtx}
%</driver>
%<class>\NeedsTeXFormat{LaTeX2e}[2009/01/01]
%<class>\ProvidesClass{example}
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{hypdoc}

\renewcommand{\main}[1]{\underline{\texttt{#1}}}

\CodelineIndex
\EnableCrossrefs

\begin{document}
\DocInput{example.dtx}
\end{document}
%</driver>
% \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
\endinput


build with

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


Result

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

-

## 1 Answer

You may try

\makeatletter
\renewcommand*{\theCodelineNo}{%
\reset@font\ttfamily\scriptsize\arabic{CodelineNo}}
\makeatother


after loading the class.

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

Writing also

\def\hdclindex#1#2#3{%
\csname\ifx\\#2\\relax\else#2\fi\endcsname{%
\hyperlink{HD.#1}{\texttt{#3}}%
\HD@savedest@add{#1}%
}%
}


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).

-
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