Hello again,

I'm struggling with the eplain features for generating tables of
content and I'm hoping someone here can help. The problem I have is
the generated parts of the title are not expanded before being written
the macros used to generate the title have been redefined by the time

I've searched this group's archives for a solution but none seems to
be available (or my search criteria is simply inadequate;). I've
spent some time trying to get this to work however I've failed each
time. I think my failures are due to my lack of understanding of the
nuances of TeX's macro expansion rules. I've re-read the expansion
rules in chapter 20 of the TeXBook but the rules and chapter seem
somehow inadequate (I just don't appreciate the subtleties!)

Here's some plain TeX that illustrates the problem. The TeX below
generates a multi-page (102 pages) document, each page of which
contains a 1-line title that is to be inserted into a table of
contents. I'll just say, for those new to TeX, that the code must be
populated.

% ---- start of TeX input -----
\input eplain

% declare, and initialize some global things
\newcount\sectionNumber
\newtoks\toktitle

% the following control sequence (cs) aka macro generates the pages of
the document
\def\doPageContent#1{
\toktitle={Section #1}
\writenumberedtocline{1}{\the\toktitle}{}
\centerline{Section #1}
\medskip
This paragraph is filler text positioned at the the top of page \the
\pageno\ just
}

% The desired effect is to have entries as follows:
% Section 5 ............................. 5
% where the left part of the line is the section title, and the right
side is
% the page number. Note the the '5' in the title is supposed to be
generated!
\def\tocentry#1#2#3#4{#2 -- (#1)(#3) \leaders\hbox to 1em{.}
\hfill#4\hfil\par}
% not really germain but set up roman numeral page numbers
\pageno=-1
% an uninspired title ...
\bigskip
% finish the page and eject
\vfil\eject

% Here we generate the body of the document ...
\pageno=1
\sectionNumber=1
% create a 100 page document
\loop
\doPageContent{\the\sectionNumber}
\ifnum\sectionNumber<100
\vfill\eject
\repeat

\bye
---- End of TeX input ----

Note I've used \writenumberedtocline because it's the only one that
seems to expand one of its parameters. I was hoping to use the
expanded parameter to get the paragraph title expanded (the title is
stored in the token list). I have no other reason to use this call
and could just as easily use \writetocentry or \writenumberedtocentry
if only I could get the arguments expanded before the call.

The toc file contains entries that look like this:

\tocentry {1}{Section \the \sectionNumber }{}{1}
\tocentry {1}{Section \the \sectionNumber }{}{2}
\tocentry {1}{Section \the \sectionNumber }{}{3}

I wanted the entries to look like this:

\tocentry {1}{Section 1}{}{1}
\tocentry {1}{Section 2}{}{2}
\tocentry {1}{Section 3}{}{3}

In other words, I wanted the expanded title written to the table of
contents file not the unexpanded title.

Any help is greatly appreciated. Thank you, in advance, for your
time.

regards
eds.
.

• Follow-Ups:

## Relevant Pages

• Re: nested macro expand order
... i feel confused on nested macro. ... evaluted at first expand macro. ... I fail to see how macro expansion is relevant to the code above. ... (funcall expander form env))) ...
(comp.lang.lisp)
• rpm and yum problems after fc2 to fc3 update
... I checked my rpm version ... error: Unterminated {: {lua: ... Macro %__policy_tree failed to expand ...
(Fedora)
• Re: Go ahead. Stop programming. This ensures you from any mistakes.
... It is not surprising -- in case of error, you leave resources unreleased. ... The only difference would be that the macro ... may expand to different code in release / debug versions. ... where allocation and deallocation occurs in one routine is not applicable. ...
(microsoft.public.dotnet.languages.csharp)
• Re: nested macro expand order
... i feel confused on nested macro. ... evaluted at first expand macro. ... I fail to see how macro expansion is relevant to the code above. ... If you want to observe how macros are expanded, you can use *macroexpand-hook* ...
(comp.lang.lisp)