# [texhax] index entries in verbatim text?

Ilya N. Golubev gin at mo.msk.ru
Fri Oct 17 16:43:22 CEST 2008

In latex document have large (possibly spanning many pages) stretches
of verbatim text, something like program source, normally to be
written inside verbatim' environment.  Index entries are to point to
locations in the middle of such text.

Is there a way to write \index' commands to achieve this?

They certainly must not insert vertical spacing or otherwise alter the
printed appearance of verbatim text.  So the trivial way, splitting
verbatim',

\begin{verbatim}
TEXT BEFORE
LINE TO POINT TO
\end{verbatim}
\index{KEY}
\begin{verbatim}
TEXT AFTER
\end{verbatim}

does not work.  Between these verbatim' environments vertical spacing
is inserted.  It does not look like just

\begin{verbatim}
TEXT BEFORE
LINE TO POINT TO
TEXT AFTER
\end{verbatim}

\verb' command refuses to process multiple- line stretches of text.
So at best have to use it on each and every line of text to format.
This certainly allows to put \index' command at arbitrary point
without breaking anything.

And this is also not for regular use.  Not only such a \verb' quoting
tedious and error- prone.  The text to be formatted verbatim is
generally program code, its language may be pretty hairy, may use just
any character, so selecting quote character for \verb' command is
hard to automate.

alltt' environment is checked to be useless.  \index' in it is
ignored, leaves nothing in index.  (Inclined to consider this a bug of
the alltt' package, defeating the very purpose of it.)

Is there environment like verbatim' that one can split arbitrarily so
that \index' will point to arbitrary line in it?
`