Auto incremented document number

Philip Taylor P.Taylor at Hellenic-Institute.Uk
Sat Feb 20 19:11:42 CET 2021


Philip Taylor wrote:

> Jonathan Fine wrote:
>
>> For example, what if producing the report requires several 
>> typesetting runs?
> A valid point, and not one that my proposed solution would directly 
> address.

Addressed in the code below.  For a normal run, the user just says "TeX 
<whatever>, and the output will be a non-zero decimal such as 2.00001, 
2.00002, etc.    For the final run, the user says "TeX \count 0 = 0 
\input <whatever>", the code will then round the counter up to the next 
exact integer, so the output will be (e.g.,) "3.0".  The only assumption 
is that not more than 65535 iterations will be required before a final run.

Philip Taylor
--------
\newread \trackerin

\newwrite \trackerout


{

\catcode `\p = \catcode `\1

\catcode `\t = \catcode `\1

\global \def \nodimen #1pt{#1}

}


\newdimen \seqno


\openin \trackerin = \jobname.seqno

\ifeof \trackerin

\seqno = 0 sp

\else

     \read \trackerin to \seqtmp

\seqno = \seqtmp sp

\fi

\closein \trackerin


\ifnum \count 0 = 1

\advance \seqno by 1 sp

\else

\divide \seqno by 65536

\multiply \seqno by 65536

\advance \seqno by 1 pt

\fi


\message {New sequence number = \expandafter \nodimen \the \seqno}


\immediate \openout \trackerout = \jobname.seqno

\immediate \write \trackerout {\the \seqno}

\immediate \closeout \trackerout


\end

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/texhax/attachments/20210220/b1e7f77d/attachment.html>


More information about the texhax mailing list.