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.

  • provide major & minor version numbers in a file
  • use a subversion tool to determine the last commit revision to the current folder or tree
  • combine the version and revision numbers to make a definitive version reference
  • save this (and any other information you want) to a TeX file as \newcommand \svnversion{1.2.345}
  • include this file in the preamble of your main LaTeX document
  • 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:

  • download the script from the site and copy it to somewhere in your path e.g. /usr/local/bin
  • make sure you have the pysvn module installed; download form pysvn.tigris.org if not
  • go to where your LaTeX document is stored; it should be in part of a subversion tree
  • create the file sversion.txt to contain the major minor number of your project e.g. 1.2
  • now run the script sversion (or whatever you called it in step 1); this should create a local file sversion.tex
  • in the preamble of your LaTeX document add a line like \include{sversion}
  • you should now be able to use the variable names like \svnrevision and \svnversion to render appropriate numbers
  • 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.