[tex-eplain] Indexing and numberedlist
Oleg Katsitadze
olegkat at gmail.com
Wed Aug 1 16:41:57 CEST 2007
On Wed, Aug 01, 2007 at 01:37:18PM +0000, Adam Fenn wrote:
> I would like to add one final refinement to your macro and that is a
> hyperlink. Is that possible?
Sure, it's quite easy, assuming your index won't have ranges (they
only make sense for page numbers, not list item numbers, I think).
You need to add "page number encapsulator" to the index entry,
separated with `|' (ldxref), and pass the autogenerated hyperlink
label to it, and then define \ldxref to typeset the number as a
hyperlink. (Look at the .ldx and .lnd files to see how this works.)
Here's the code:
------------------------------>%------------------------------
\input eplain
\enablehyperlinks
% Load the color package to make hyperlinks colored.
\beginpackages
\usepackage{color}
\endpackages
\newwrite\listidxfile
\immediate\openout\listidxfile = \jobname.ldx
\newcount\ldxrefcount
\def\MyMacro#1#2#3{%
\li[ldx\the\ldxrefcount]
{#1, }% surname
{#2: }% forename
{#3}% stuff
\begingroup
% \li has advanced the numbers, so restore this item's number.
\advance\itemnumber by -1
\advance\itemletter by -1
\advance\itemromannumeral by -1
% Pass arguments through a \toks register, to avoid unneeded
% expansion during \write.
\toks0={#1, #2}%
% Write immediately, as opposed to writing during page shipout,
% otherwise item numbers and \the\toks0 will be all wrong.
\immediate\write\listidxfile{\string\indexentry{\the\toks0|ldxref{ldx\the\ldxrefcount}}{\marker}}
\endgroup
\global\advance\ldxrefcount by1
}
% Typeset list item number in the index as a hyperlink. #1 is the
% hyperlink label, #2 is the list marker.
\def\ldxref#1#2{%
\hlstart{name}{bwidth=0}{#1}#2\hlend
}
\numberedlist
\MyMacro{Surname}{Forename}{Stuff}
\MyMacro{Another Surname}{Another Forename}{Another Stuff}
\endnumberedlist
\vfill\eject
\readindexfile{l}
\bye
------------------------------%<------------------------------
You can add various options to \hldest and \hlstart to suit your
purposes (see "Explicit hyperlinks" section of the manual). I've
added options to remove the box around hyperlinks (I hate them!) and
included the color package so that hyperlinks are colored.
Process the file with something like:
$ pdftex test && makeindex test.ldx -o test.lnd && pdftex test
Cheers,
Oleg
More information about the tex-eplain
mailing list