[tex-eplain] Indexing and numberedlist

Oleg Katsitadze olegkat at gmail.com
Sat Jul 28 13:56:40 CEST 2007


On Sat, Jul 28, 2007 at 09:08:36AM +0000, Adam Fenn wrote:
> I have a small macro which automatically puts an entry in the index.
> However, I wish the index to refer to the number produced by the
> numberedlist environment and not to the page number. Is there a way of
> doing this?

You probably don't need all the complexity of the indexing macros for
this, you can write out index entries directly, like this:

------------------------------%<------------------------------
\input eplain

\newwrite\listidxfile
\immediate\openout\listidxfile = \jobname.ldx

\def\MyMacro#1#2#3{%
  \li
  {#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}{\marker}}
  \endgroup
}


\numberedlist
\MyMacro{Surname}{Forename}{Stuff}
\MyMacro{Another Surname}{Another Forename}{Another Stuff}
  \numberedlist
  \MyMacro{Nested Surname}{Nested Forename}{Nested Stuff}
    \numberedlist
    \MyMacro{Another Nested Surname}{Another Nested Forename}{Another Nested Stuff}
    \endnumberedlist
  \endnumberedlist
\endnumberedlist

\bye
------------------------------%<------------------------------

I don't know if you need to index items from nested lists, but if you
do then lettered nested lists will output `\char 97', etc., breaking
index sorting, so you'd need either to redefine \printitemletter or to
use numbers in all levels.  You'd also need to print "fully qualified"
item numbers, that is, include numbers of all upper-level list items
(like "1.2.4").  You'll need to define your own \numberedlist to store
upper level's number somewhere before calling the "real"
\numberedlist, and redefine \numberedmarker to fetch and print all
those numbers.

If you need nested list indexing and the above paragraph doesn't make
sense, let me know, I'll try to help.

Cheers,
Oleg


More information about the tex-eplain mailing list