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}}

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

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?


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!

| improve this answer | |

Maybe you can try svn (or svn-multi, svn-info, etc.) package.


| improve this answer | |

You can do the same using my "svn-multi" package:

\date{\svntoday \svnhour:\svnminute}

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

| improve this answer | |

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.