Tuesday 18 June 2013

How to visulise the changes in a LaTeX file or project in mercurial

Using mercurial to keep track of changes and share a LaTeX project is very useful and I've had good use of it writing scientific articles with colleagues. The only problem I've found with this is that it is hard to visualise that changes made.  There is a tool for doing something similar,  latexdiff  though it does not integrate into mercurial. One integration for git can be found at Yngve's blog, though it only works for git.

Therefore I decided to write my own python program, using latexdiff,  for comparing changes across different mercurial revisions or the current change. This python program can be found on SourceForge under the project named Hg Diff Latex.
It requires latexdiff (should come with any normal latex installation) and python. It is designed to work on Linux, Mac and Windows, though I haven't had the time to test it thoroughly on anything else then Linux. It should be set as executable for the commands below to work (if not add python in front)


Help for the program can be found using

diffLatex.py -h

If you want to compare the current version in the repository with a previous one, here number 23, and display it in Okular the command would be

diffLatex.py -r 23 -o main.tex

where main.tex is the main file in you latex document.
If you instead want to use the viewer acroread the command would be

diffLatex.py -r 23 -v acroread main.tex

Comparing the changes currently made to the latest in the repository, and opening in Okular
 
diffLatex.py -o main.tex

A neat thing that can be done is to compare to old versions, old1 and old2, (remember to commit your changes before you do this) :

hg update -r old1 # Changing the repository state to old1
diffLatex.py -r old2 -o main.tex
hg update # To get back to the newest  

Here it doesn't matter if old1 is larger than old2, just keep track of what the colours represent.

If there are any issues or comments I would really  like to hear them either here, or on SourceForge.





No comments:

Post a Comment