# Subversion keyword string inside LaTeX document

I put a subversion keyword string inside my LaTeX document. It looks like:

$LastChangedDate: 2011-01-16 18:09:33 +0100 (nie)$


and it gets replaced (simple textual substitution) every time I make a commit to the repository. Also when I get an older version of the document, the date is also reverted to the time when that version was commited.

I wanted to make it look nicer in the output, so decided to make following definition:

\def\LastChangedDate: #1-#2-#3 #4:#5:#6 #7 (#8) {\year=#1\month=#2\day=#3\date{\today{} #4:#5}}
\newenvironment{subversionparse}{\catcode$=0}{\catcode$=3}

\begin{subversionparse}
$LastChangedDate: 2011-01-16 18:09:33 +0100 (nie)$
\end{subversionparse}


Firstly it defines LastChangedDate macro which parses the following text and sets the date as TeX "today" date, and then defines \date as "today" followed by time. This makes the output nicely localized, in my case: "16 stycznia 2011 18:09".

Then a new environment is made to temporarily change $ character to escape character, so that $LastChangedDate gets parsed as real macro.

Now, I am happy that I managed to get this working. What potential problems do you see with this approach? Maybe there are other, simpler ways of doing the same thing?

-
For package solutions see “LaTeX packages for use with revision control”. –  Caramdir Jan 16 '11 at 17:23
Accepting Ulrich's answer because it actually points out potential improvements. Thanks for all answers! –  liori Apr 18 '11 at 19:26

You should not manually re-set the catcode of $ to 3, because you do not know if it was 3 in the first place. (At least, onlyamsmath and nag set $ to active, and pgf does fancy stuff, too, though maybe pgf only does so locally.) Let the \endgroup take care of it: catcode assignments are local.

From memory, a safe way using delimited arguments should be:

\def\svnparse{\def\svnp@rse $##1${\svnp@rs@ #1\@nil}\svnp@rse}


with \svnp@rs@ using delimited arguments similar to your code. The key is to redefine \svnp@rse at runtime, so you pick up the currently active catcode of $ (unless we are in an argument already). The further indirection is just to make sure that third parties can still hook into or patch your commands. BTW, ingenious use of resetting the escape char! Tip of the hat to you! - Maybe you can try svn (or svn-multi, svn-info, etc.) package. http://www.ctan.org/tex-archive/help/Catalogue/entries/svn.html - You can do the same using my "svn-multi" package: \svnid{$Id\$}
\date{\svntoday \svnhour:\svnminute}


It does all the catcode magic for you and also works with multiple source files, e.g. include files.

-

The vc bundle has a neat way to include revision information like this. And since the formatting is done by an awk script, it's easy to manipulate it into giving you custom formats and so on.

-