How useful would it be to include a document version that can increment itself every-time the document file is updated into a subversion repository. Being able to show a revision number on selected pages of Latex documents must prevent the confusion that arises during project documentation as both project and documentation evolve. It is easy enough for the document author to track revisions (embedded in comments) but being able to actually print out a dynamic revision is much more difficult.

Example document version numbering

Example of a document with version number

The idea for this came from an article by Lex Spoon who provided the basic Latex technique for providing a variable that could be rendered and a perl script. Here I will outline a similar solution using python, extending the concept somewhat.
  1. provide major & minor version numbers in a file
  2. use a subversion tool to determine the last commit revision to the current folder or tree
  3. combine the version and revision numbers to make a definitive version reference
  4. save this (and any other information you want) to a TeX file as \newcommand\svnversion{1.2.345}
  5. include this file in the preamble of your main LaTeX document
  6. you can then reference the version anywhere you wish with the variable \svnversion
Lex Spoon provides a perl script which automates this for you, possibly integrating with your build process; my python script (which uses pysvn) has more mundane ambitions and is available on the AFC Commercial OSS download site. To get this working:
  1. download the script from the site and copy it to somewhere in your path e.g. /usr/local/bin
  2. make sure you have the pysvn module installed; download form if not
  3. go to where your LaTeX document is stored; it should be in part of a subversion tree
  4. create the file sversion.txt to contain the major minor number of your project e.g. 1.2
  5. now run the script sversion (or whatever you called it in step 1); this should create a local file sversion.tex
  6. in the preamble of your LaTeX document add a line like \include{sversion}
  7. you should now be able to use the variable names like \svnrevision and \svnversion to render appropriate numbers
  8. simply run sversion at any-time to update the version numbers
You could even move the files into a more global location for the project and run sversion in that folder.
This blog post was posted to Technobabble on Monday October 17th, 2011 at 5:15PM

Leave a Comment

All comments are moderated and hidden until reviewed; please preview before posting. You can use bbcode in the comment: e.g. [b]This is bold[/b], [url][/url], [code python]import this[/code]
Preview Posting...
Previewing comment, please wait a moment...
Search for Posts
Possibly related posts
Popular Tags
Recent Comments
As you mention, it is true that an unregistered record cannot be used in the (Select *) method of setting ...
© 2013 Andy Ferguson