[texhax] Sections question

Pierre MacKay pierre.mackay at comcast.net
Wed Jan 30 18:58:38 CET 2008

Robert Wilson wrote:

>I'd like to reference the last page of a section without referencing  
>the next section, just like \lastpage, but with sections instead of  
>the whole document. Does anyone know of a package like this?
1.  At the end of each section, write the number of the last page to an 
external file
(This is using plain TeX, I don't know how it would look in LaTeX)

  % front matter has negative values in \count0, otherwise \count0 is 
set up for next 
  % page.  \endpage was set by reading endpage.tex at start of this 
run.  See below
  \ifnum\count0 > 0 % Don't bother with front matter
    \endcount=\count0\ifskipblank\global\advance\endcount by -1
    \message{doing blank page}\fi % blank verso page if needed
    \ifnum\endcount=\endpage \advance\notecount by -1 % was set up for 
next note
    \message{====lastpage=\the\endcount    ====lastnote=\the\notecount}%
    \else\message{END PAGE NOT CORRECT--RUN AGAIN}\fi

2.  Rerun if necessary.

3. Read the external file at the start of each run, and set the value of 
\the\endpage where you need it.  Notice that even if endpage.tex doesn't 
exist, TeX won't choke.

\closein\endread % reset input pointer to start of file.
\input endpage
The file endpage.tex reads simply: 
\endpage =70

Pierre MacKay

More information about the texhax mailing list