3

What is the best way to get the "marker" for the current item in a list in the eplain format?

\numberedlist
  \li Here's an item
  \li And this is another and it's marker is: \marker
\endnumberedlist

I've tried using "\marker" but from what I can tell, by the time that is expanded, the item number has already been incremented. I tried reading the eplain.tex source but I'm not proficient enough to understand it.

4

The eplain manual says in section "4.6 Lists":

You can give \li an optional argument, a cross-reference label. It’s defined to be the "marker" for the current item. This is useful if the list items are numbered. You can produce the value of the label with \xrefn. See Section 4.9 [Cross-references], page 15.

Applied to the example:

\numberedlist
  \li Here's an item
  \li[this] And this is another and it's marker is: \xrefn{this}
  \li A third item
\endnumberedlist
\bye

The result after two eplain runs:

Result

With \enablehyperlinks the reference will actually become a link.

  • Thanks, Heiko. I was aware of that mechanism but for some reason it didn't occur to me to use it "within" the \li. – acarlow Jun 3 '14 at 19:45
2

I came up with two alternative solutions.

Using e-tex's \numexpr:

\def\currentitemnum{\the\numexpr \number\itemnumber-1 \relax}

\numberedlist
  \li Here's an item
  \li And this is another and it's marker is: \currentitemnum
  \li A third item
\endnumberedlist

\bye

...And another using the xint package:

\input xint.sty \relax

\def\currentitemnum{\xintDec{\number\itemnumber}}

\numberedlist
  \li Here's an item
  \li And this is another and it's marker is: \currentitemnum
  \li A third item
\endnumberedlist

\bye
  • With release 1.1 from 2014/10/28 of xint there is smaller package xintcore which already contains \xintDec. This being said, your first proposal is the better one, as ultimately \xintDec boils down to it (\xintDec is able to handle arbitrarily big numbers but \numexpr can't go beyond 2147483647). In the first method (but not the second), you don't actually need \number. – user4686 Nov 29 '14 at 17:23
1

I know that this thread was tagged as eplain but I mean that it would be useful to show the same problem solved in OPmac only for comparison. OPmac is another simple macro package based on plain TeX like eplain.

First. The mentioned problem doesn't occur, because \itemnum has its current value:

\input opmac

\begitems \style n
* This is first item.
* This second item has a number \the\itemnum.
* This is the last item.
\enditems

\bye

items

Of course, you can add the reference stuff for the item in the list too:

\input opmac

\begitems \style n
* This is first item.
* \label[this]\wlabel{\the\itemnum}This second item has its number.
* This is the last item.
\enditems

The item \ref[this] is mentioned at the page \pgref[this].
% prints as: The item 2 is mentioned at the page 1.

\bye

If you declare \hyperlinks\Blue\Blue then the references will actually become a link.

  • Thanks for the pointer to OPmac. I shall definitely take a look at it. – acarlow Jun 4 '14 at 7:32
  • Could you please explain the purpose of \wlabel? It is not mentioned in the opmac manual and I'm afraid my TeX coding skills aren't yet sufficient to understand the source code. – acarlow Jun 4 '14 at 22:10
  • The \wlabel{text} creates the connection between text and previously declared label. When you type \ref[label] then text is printed. Because you can type \ref[label] before the referenced object then \wlabel writes data to the *.ref file. – wipet Jun 5 '14 at 6:25
  • Ok, I understand now. I wonder why the definition of "\startitem" doesn't include this, similar to \chap, \sec, etc? – acarlow Jun 5 '14 at 15:27
  • You can set arbitrary text for references by \wlabel, for example \wlabel{\the\itemnum}, \wlabel{\athe\itemnum)}, wlabel{item (\romannumeral\itemnum)} or whatever you want. – wipet Jun 6 '14 at 4:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.