Auto incremented document number

Mike Marchywka marchywka at
Fri Feb 19 21:01:52 CET 2021

On Fri, Feb 19, 2021 at 07:44:19PM +0000, Philip Taylor wrote:
>    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.

Is this a versioning system or a document tracking system? You want
to get a new version for each time you run latex? 

For a lot of applications, the DB may be more hassle than it is worth.
In my c++ imeplemtation, I can do everything in text files probably
although having an in-memory data structure with a variety
of indicies. In the present case, you probably want more than a number
but detailed bibliographic info on each document. You may as well store
that as bibtex or something easily converted. A bib file works for that.
If you have a bibtex parser, someone else here IIRC at has
a conforming one, you can load all the existing entries and derive
a new document name and number, edit the bib file programmatically,
and write it back out  etc.  It could take SQL that long to parse
a query lol plus you can edit the "DB" with vi and back it up
with gzip lol.

This was interesting because I'm working on moving my bibtex
discover script to c++ ( using it now for research )
and had forgotten about this part of the bibtex

> 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


mike marchywka
306 charles cox
canton GA 30115
USA, Earth 
marchywka at
ORCID: 0000-0001-9237-455X

More information about the texhax mailing list.