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
For systems like CVS or Subversion, which modify source files, the TeX FAQ's bare-bones answer is my favourite:
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
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
For the last part of your question, I like the Perl script
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
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
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
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.
Edit: As Brent Longborough, the author of gitinfo, pointed out there is now a new version available: gitinfo 2
It simplifies the whole handling in a considerable way. Check it out!
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
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
Then add something like this in a .tex file
Maybe with a check so you don't get a error if you don't want to include this svn info.
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.
Then add something like this to your .tex.
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.
If your document uses multiple source files like
This is a hack to say the least, but I can just as well show some code.
I write the current revision and information on which files have been modified into drafts in the following way.
I build the documents with Latexmk. In
To make it better integrated with the continuous compilation mode (
This populates a file named
Note the regular expression that converts all
Then I have a LaTeX package
Finally, in the document I have
in the preamble, and
In practice I include the
I think this solution will disappear shortly in favor of PythonTeX and Python bindings to Mercurial (EDIT: the CLI is actually the only official API; see below), but that was not available (at least not to my knowledge) when I hacked up the Perl version. I will keep it as long as it continues to work; it is only a few lines of copy+paste now that it is set up.
EDIT: I started looking at a PythonTeX version as well, but I soon realized it will not actually simplify things much; if at all. It adds files to be tracked for Latexmk, requires additional compilation runs, and includes some quirks for getting import paths correct, as it is currently written.
Anyway, this was the initial attempt (note that this is not updated to handle underscores as the Perl version, since I found that bug after I abandoned the Python version):
The Mercurial CLI is called by design, since it is the official and stable API for Mercurial.
The path kludge is there to be able to collect document related scripts in a certain directory. If
In the preamble of the LaTeX document, I add:
and where I want to render the info, I run
All in all, the Perl version bypasses several steps since Latexmk is already running in that environment. To get a clearer solution, it would probably be easier to spend time with the Perl function, or alternatively continue with the Python script, but call it from
For better diff-s in git, set
Configuration in my repo:
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/.