Version control and collaborating with LaTeX files


Vinh Nguyen


June 13, 2011

This post finally pushed me to explore ways to version control and collaborate with others using LaTeX files. I'm assuming the collaborators also use LaTeX, which is rare in itself when your primary collaborators are scientists that work mainly with WYSISWG editors, in particular, MS Word. I will outline how I collaborate with non-LaTeX users in a future post.

One issue arises with LaTeX files. When writing prose, I tend to write continuously on a line until a line break is necessary, usually when a new paragraph begins or when I introduce long math formulas. When diff is used to compare two LaTeX files, it is hard to see where a change occured in long line since diff looks at changes in lines; this problem is well documented.

The first obvious solution is to break up your lines. A fill-type solution will probably not work too well with diff with that 80 character restriction since a small change might affect more than one line. Comments from the original post suggests using a single line for each sentence. I think this is reasonable for readability and for diff to work. However, when collaborating with others, they might not abide by this preference.

The utility wdiff is another suggested solution that looks at differences in words instead of lines. The only problem I see with it is that the entire file will be printed, with words that are added and removed "highlighted" in the text using braces and brackets; its hard to see all the changes immediately with long files. This site shows how to add additional LaTeX markup that will highlight the changes visually on a generated dvi/ps/pdf file. The utility latexdiff also carries this out, and appears to be very popular among users. The output document is marked up similar to the "Track Changes" feature of your typical WYSIWYG editors.

latexdiff install on ubuntu:

sudo apt-get install latexdiff

Moving forward, I will abide by the one sentence per line principle. However, I cannot force collaborators to do this, so will use wdiff and latexdiff to compare their changes. To assist in the first task, I can insert a new line after period using with the help of regexp-replace or replace-string on a region (two spaces to new line C-q C-j).