# LaTeX packages for use with revision control

I use revision control (Subversion, to be exact) to keep track of the edits to my LaTeX documents. Is there a LaTeX package that interfaces with revision control? Specifically, it would be nice to see the revision number and time and date inside the document. (Obviously, I'd turn this off in the final version.) Also, it might be nice to get a PDF showing what was added and removed in a given revision.

-

Yes, there are packages called svn and svninfo, as well as a few for other version-control systems. See the UK TeX FAQ: you can have something like \SVNdate $Date$ which will use the value of the Date SVN variable in your document, or have footers containing the date and version number in the document. I don't think either of them shows diffs, though.

-
1 vote up. Yes these are very useful and I have been using them for a long time now. You can have these "tracking" information for each of your main tex document and for any subsidiary tex documents. This way you can keep control when you have made changes in one specific file. Unfortunately, there's no way to have these tracking information for your pictures in case you update them. – yCalleecharan Sep 19 '10 at 19:49
@yCalleecharan: that depends very much on what format your pictures are in – SamB Dec 2 '10 at 20:53

For systems like CVS or Subversion, which modify source files, the TeX FAQ's bare-bones answer is my favourite:

\def\RCS$#1: #2${\expandafter\def\csname RCS#1\endcsname{#2}}
\RCS$Revision: 1.13$ % or any RCS keyword
\RCS$Date: 2010/04/02 18:20:00$
...
\date{Revision \RCSRevision, \RCSDate}


It's not very sophisticated, but you're only going to use it for draft versions, so this is a case where simple and robust beats pretty.

Systems like Mercurial or Git don't modify source files. In such cases, a good solution is to generate a file which can be \input into a source document. In the case of Mercurial, I use a Makefile rule like:

hg.id: .hg
hg parent --template '\\def\\HgNode\{{node|short}}\n\\def\\HgDate\{{date|rfc3339date}}\n\\def\\HgAuthor\{{author|person}}\n' >$@  I \input that file into the document, and use \HgDate and \HgNode in \date commands or footnotes. Update: the OP also mentioned changes between versions. That turns out to be a bit tricky in LaTeX, but the TeX FAQ has a discussion of the various (not completely satisfactory) possibilities. Edit: More recent versions of Mercurial require the { characters in the template to be escaped. I modified the answer to include that. Edit: hg parent is better than hg tip, as it gives the correct result if you're formatting an old (tagged?) version of the repository. -  Mercurial has keyword extension with functionality similar to rcs keywords. – Mekk Aug 5 '10 at 0:51 For the last part of your question, I like the Perl script latexdiff. This generates LaTeX documents displaying linebreak-insensitive differences, with changebars and other visual markup. (Alas, the implementation is quite hacky, relying on complex regular expressions for parsing, so it's worth ensuring one has Perl 5.8.10 or later installed for greater regular expression nesting depth.) - and the extension latexdiff-vc can handle cvs, rcs, and svn as well – Suresh Jul 26 '10 at 23:53 Does latexdiff work if the doc is split into many files and \include'd? – Leo Liu Aug 15 '10 at 11:41 I have not personally used it for multi-file documents, so can't comment. – András Salamon Sep 7 '10 at 17:32 @Leo: It's something of a nuisance, but texdiff is intended to handle this case. texdiff happily creates unbound macros, so you need to put some boilerplate in your code to handle them. – Charles Stewart Oct 4 '10 at 9:00 @Charles nice. Thanks for the link. – Leo Liu May 21 '11 at 8:01 show 1 more comment For Git and Mercurial the only packaged option for writing revision information to the output document is the vc-bundle, which works without keyword substitution by writing to an \input’ed file. For rendering a diff document a commit hook could be used that calls latexdiff-vc. Just inspecting diffs word-based instead of line based can be done with wdiff, or dwdiff. Git has a helpful diff mode with --color-words git diff --color-words  -  this package work really well for me. I use the \GITHash macro. :D – Mica Feb 2 '11 at 22:50 The vc-bundle doesn't seem to provide scripts for Mercurial. (The 3 vc systems supported are Bazaar, git and svn). Does anybody have the scripts adjusted for working with Mercurial? – Rabarberski Jun 19 '12 at 9:41 Keyword substitution is frowned on by revision control purists and is not facilitated in some modern systems such as Git and Darcs. Solution recommended to me is to have a script generate the information and then write it to a file. Then add the information from file using \input. - It is not because it is frowned upon. The whole thing just doesn't make sense and git in fact offers a much more powerful way than those offered by svn or rcs. Despite this I still don't use it. – Leo Liu Aug 15 '10 at 11:46 How about \verbatiminput and not \input, all those special chars tend to break things if you are not careful. – Johan Aug 16 '10 at 6:01 To get the revision id, date and time inside the document you need to use keyword substitution. Once you've set up your repository to do the substitution you can then insert $Id$, $Revision$, $Date$ or other keywords which will then be replaced when the file is committed. - To do this I don't use a LaTeX package, but I play with a Makefile and some simple shell scripts. (But that also mean that this is a Unix/Linux/Cygwin hack). Add something like this a Makefile SVN_INFO=svn.info.tex svninfo:$(shell svn info > $(SVN_INFO) )  Then add something like this in a .tex file \section{SVN info} {\scriptsize \verbatiminput{svn.info.tex}}  Maybe with a check so you don't get a error if you don't want to include this svn info. \IfFileExists{svn.info.tex} { ..... }  This can be changed to include some kind of diff if you rather would like that. Add something like this in your Makefile to include a diff between the current version and verison 40. DIFF_INFO=diff.info.tex DIFF_REV=40 diffinfo:$(shell svn diff --revision $(DIFF_REV)$(NAME).tex > $(DIFF_INFO) )  Then add something like this to your .tex. \IfFileExists{diff.info.tex} { \newpage \begin{landscape} \section{Diff} {\scriptsize \verbatiminput{diff.info.tex}} \end{landscape} }  And this can then be enhanced with whatever shell scripts you feel like, so I don't see any problem doing more or less the same for other systems like git. /Have fun - If your document uses multiple source files like \include and \input I recommend to use the 'svn-multi' package. For a changelog feature you need to use scripts like mentioned earlier, because a svn client is required to receive the log information from the server. - there is a nice package called gitinfo for the use with git. In combination with some easy Makefile gymnastics, this gives pretty nice results, all explained well in the manual of the package. - For better diff-s in git, set .gitattributes to *.tex diff=tex. Configuration in my repo: $ cat .gitattributes
*.tex    diff=tex

-
 Nice, I didn't know there's a default filter for tex in git - of course there's also latexdiff+git – Tobias Kienzler Mar 14 at 10:28

Regarding highlighting differences between documents under version control, there is also a discussion here: texdiff for multi-file documents in subversion

As I mentioned in that post, if you have multi-file projects in Subversion and want to highlight differences the only reliable solution I found is first to flatten the document and then run latexdiff on that document. I created a batch file that does everything, from flattening to creating a PDF highlighting the differences, automatically with one click. You can find a little tutorial and download the batch on my website http://www.jwe.cc/2012/02/workflow-with-subversion-and-latex/.

-