TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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
up vote 5 down vote accepted

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!

share|improve this answer

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


share|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.

share|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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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