Auto incremented document number

Philip Taylor P.Taylor at Hellenic-Institute.Uk
Sun Feb 21 11:38:52 CET 2021


Philip Taylor wrote:

> There was a spurious " sp" in the code as posted at "\seqno = \seqtmp 
> sp"; this should, of course, have read simply "\seqno = \seqtmp", as 
> \seqtmp contains a dimension, not an integer.  A better version is 
> currently under development.

which version is now released below.  Modulo as-yet-unencountered bugs, 
I regard this as the final version.  Sequence numbers will start at 0.1, 
0.2, ..., 0.65535, and each time that the program is told that the 
present run is the final run for the current sequence, the sequence 
number will be rounded up to the next integer (so in the case above, 
rounded up to 1.0, after which sequence numbers will be 1.1, 1.2, ..., 
1.65535).  The mechanism for informing the program that any given run is 
the final run for the current sequence is as before:

     TeX \count 0 = 0 \input <whatever>

The program will use the e-TeX extension "\dimexpr" if present, but is 
fully functional in Knuthian TeX.

/Philip Taylor

--------

/\newread \trackerin
\newwrite \trackerout

\newcount \major
\newcount \minor
\newcount \pttosp \pttosp = 65536
\newdimen \seqno

\openin \trackerin = \jobname.seqno
\ifeof \trackerin
     \seqno = 0 sp
\else
     \read \trackerin to \seqtmp
     \seqno = \seqtmp
\fi
\closein \trackerin

\ifx \dimexpr \undefined
     \ifnum \count 0 = 1
         \advance \seqno by 1 sp
     \else
         \divide \seqno by \pttosp
         \multiply \seqno by \pttosp
         \advance \seqno by 1 pt
     \fi
     \minor = \seqno
     \major = \seqno
     \divide \major by \pttosp
     \multiply \major by \pttosp
     \advance \minor by -\major
     \divide \major by \pttosp
\else
     \ifnum \count 0 = 1
         \advance \seqno by 1 sp
     \else
         \advance \seqno by 1 pt
         \seqno = \dimexpr \seqno / \pttosp * \pttosp \relax
     \fi
     \minor = \seqno
     \major = \dimexpr \seqno / \pttosp \relax
     \advance \minor by -\dimexpr \major pt\relax
\fi

\message {New sequence number = \the \major .\the \minor}

\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/20210221/7d5327aa/attachment.html>


More information about the texhax mailing list.