[tex-eplain] Typesetting index.
Oleg Katsitadze
olegkat at gmail.com
Tue Jan 8 05:30:56 CET 2008
[Sorry for the late reply.]
On Wed, Jan 02, 2008 at 02:21:00PM -0500, John Culleton wrote:
> it would be more convenient to do it at the point of creation of an \idx or
> \sidx tag.
>
> What is the best method for this purpose?
The "encapsulator command" feature of MakeIndex. Eplain makes it a
little easier by providing the "pagemarkup" option for the indexing
commands (see "4.12.1.2 Modifying index entries"). Below is a
complete example:
,----
| \input eplain
|
| \def\encapdef#1{{\bf #1}}
| \def\encapex#1{{\it #1}}
| \def\encapweird#1{%
| {\it
| \idxparserange{#1}%
| \ifx\idxpagei\empty
| % The argument is a single page number.
| \underbar{#1}%
| \else
| % The argument is a page range.
| \underbar{\idxpagei}\idxpagerangedelimiter\underbar{\idxpageii}%
| \fi}%
| }
|
| This is the definition of \idx[pagemarkup=encapdef]{my term}.
|
| This is the definition of \idx[pagemarkup=encapex]{my other term}.
|
| This is the start of the definition of
| \idx[pagemarkup=encapweird,begin]{yet another term}.
|
| \vfil\eject
|
| This is the end of the definition of
| \idx[pagemarkup=encapweird,end]{yet another term}.
|
| \readindexfile{i}
|
| \bye
`----
For the explanation of \encapweird, see "7.12 Page list and page range
parsers".
I'm guessing you're going to have lots of these indexing commands, and
it'd be a drag to repeat "pagemarkup=..." every time. Below are the
defs I once used to simplify this:
,----
| % Helpers to create `main' terms.
| \def\main#1{{\bf #1}}%
| \def\sidxmain{\let\sidxmain at cmd\sidx \@getoptionalarg\@finsidxmain}%
| \def\idxmain{\let\sidxmain at cmd\idx \@getoptionalarg\@finsidxmain}%
| %
| \def\@finsidxmain{%
| \ifx\@optionalarg\empty
| \toks@={[pagemarkup=main]}%
| \else
| \toks@=\expandafter{\expandafter[\@optionalarg,pagemarkup=main]}%
| \fi
| \expandafter\sidxmain at cmd\the\toks@
| }%
`----
The idea here is to embed "pagemarkup=..." into the option lists of
\sidx and \idx, so that you can still add other modifiers (like
"begin" and "end"), but don't have to write "pagemarkup=..." every
time.
HTH,
Oleg
More information about the tex-eplain
mailing list