Auto incremented document number

Mike Marchywka marchywka at hotmail.com
Fri Feb 19 18:26:58 CET 2021


On Fri, Feb 19, 2021 at 05:08:38PM +0000, Philip Taylor wrote:
>    Jerry wrote:
> 
> I have no idea if this is possible, so I thought I would ask.
> 
> I work for a municipality. I need to create several documents that need to be numbered in consecutive order, i.e., SWI-100, SWI-101,
>  SWI-102, etcetera. Is there any latex package that can keep track of the last used number and increment it in each new document? Si
> nce all of the papers are not written simultaneously, it would need to "remember" the last used number and increment it at a future
> date. I can do this with a regular MS Access database or MySQL, but I cannot figure out how to do it with LaTeX.
> 
>    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.
>    --

I was hoping someone would have a cool answer but I'll offer my own :)
I am trying to track my self-published works generally with
bib entries as "techreport." Ideally I will have polished publications
at some point but for now it lets me track and respond quickly
with something someone can cite if desired. For example,
in response to a conversation the prior day, I posted
this abstract that could eventually be the basis for a
real tech report,  

https://www.linkedin.com/posts/marchywka_clotting-paradox-abstract-activity-6760889521887350784-B9ZH

If you download it and look at the extended info you can find the
techreport bibtex entry but on the headers there should be
a document serial number. This is created by a script I have called
"newproj" that sets up a new directory, copies a skeleton file 
and gives it a serial number. The part of the script
is this. Note that is starts off with a flakey error- you should
get ONE date and parse that. This can generate wierd results 
around midnight, when vampires come out :) The serial number
thing though works AFAICT. The rest of this is for my
automated embedded bibtex to make it easily citeable without
a DOI or "real" publisher.  There are a lot of other kluges
as in my old bibtex downloader script but the c++ implementation
can be a lot better :)  

get_serials()
{
# 4 digit year
# FIXME TODO this has serial boundary problems, 
# good place for double check locking? lol
# should get one date and go with that. 
date=`date`
year=`date --date="$date" +%Y`
moname=`date --date="$date"  +%B`
mono=`date --date="$date"  +%m`
day=`date  --date="$date" +%d`
date=`date --date="$date" +"%B %d %Y"`

x=`cat "$INDEX_FILE" | grep TECHREPORT | tail -n 1 | sed -e 's/.*MJM-//'| sed -e 's/[-,]/ /g' `

last_year=`echo $x | awk '{print $1}'`
last_serial=`echo $x | awk '{print $2}'`
if [ "$last_year" != "$year" ]
then
serial="001"
else
serial=$[ $last_serial + 1 ]
while [  ${#serial} -lt 3 ] ; do  serial="0$serial" ; done
fi
status found serial info  $year $serial
last_trno="MJM-$last_year-$last_serial"
}


When the project is finally ready to make, the index file is
updates with a more or less complete bibentry for the project,
( not just a serial number), 

status sending to "$INDEX_FILE"
fbackupfn "$INDEX_FILE"
print_bib_entry >> "$INDEX_FILE"




The skeleton file also opens files for things like page count and
a release list that is included in the draft pdf files. 
fwiw. 





>    Philip Taylor

-- 

mike marchywka
306 charles cox
canton GA 30115
USA, Earth 
marchywka at hotmail.com
404-788-1216
ORCID: 0000-0001-9237-455X


More information about the texhax mailing list.