Auto incremented document number

Philip Taylor P.Taylor at Hellenic-Institute.Uk
Fri Feb 19 20:44:19 CET 2021


Jerry wrote:
>
>> I may be missing something obvious, but why can you not (a) open a
>> tracker file for reading, and note if it is empty; then, (b) if it is
>> not empty, read an integer from it, increment the integer, close the
>> file for reading, open it for writing, and write the augmented integer
>> back.  If it was empty, treat it as if it contained zero.
> Perhaps I am misunderstanding you, but that sounds like a like more
> work than I want to invest. I was looking for an automated system.

In that case, I am very very confused !  The system /is/ "automated"; 
all you have to do is to add a tiny bit of code to your TeX source.  The 
following is written without testing, but it should be pretty close to a 
solution:

\newread \trackerin

\newwrite \trackerout


\newcount \seqno


\openin \trackerin = tracker.txt

\ifeof \trackerin

     \seqno = 0

\else

     \read \trackerin to \seqtmp

     \seqno = \seqtmp

\fi

\closein \trackerin


\advance \seqno by 1

\message {New sequence number = \number \seqno}


\immediate \openout \trackerout = tracker.txt

\immediate \write \trackerout {\number \seqno}

\immediate \closeout \trackerout


\end



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/texhax/attachments/20210219/277c4d1e/attachment-0001.html>


More information about the texhax mailing list.