[Tex/LaTex] Best LaTeX-aware diff and merge tools for subversion

latexdiffrevision control

What's a good (or preferably, in your opinion the best) way to make subversion diff'ing and merging LaTeX-aware?

I know latexdiff and latexrevision exist, but it's not clear to me how to make those part of a normal subversion merge workflow. Especially since you have to edit the resulting file to specify which changes you want. If there's some way to set up subversion or TortoiseSVN to automate this, that would be great.

I'm going to be merging some fairly large documents, and I don't expect my collaborators to have any discipline about maintaining line breaks etc. I only recently learned about this myself.

Windows tools are preferred. I do have Cygwin with X and the Windows svn client, so I can likely get UNIX tools to work.

Best Answer

Edit: Code available for both Subversion and Git here: https://github.com/suomela/gitwdiff


For diffing, I have successfully used the following approach. This is not Latex-aware, but it seems to work very well with Latex documents (and Bibtex files, too). I have used it both on Linux and Mac OS X.

It is word-based and hence does not care about line breaks. For example, you can have each paragraph as a very long line in your source code; even then, the diff output will be easy to read and concise. It uses a colour-coded output:

  • white on red background: deleted
  • bold black on yellow background: added.

It is designed for black-on-white terminals; customise the colour codes if needed.

If you have made very extensive changes, occasionally it is better to use the usual diff. Try it out and see what happens.

Usage:

Simply write svnwdiff instead of svn diff.

If you need a pager, pipe your output to less -R instead of less.

Examples:

  • You can simply write svnwdiff and you will see all your local changes.
  • You can use svnwdiff -c6445 foo.tex just like you can use svn diff -c6445 foo.tex.
  • Write svnwdiff -c6445 foo.tex | less -R if you need a pager.

Put the following shell scripts in your $PATH:

svnwdiff:

#!/bin/sh

exec svn diff --diff-cmd="mywdiff" "$@"

mywdiff:

#!/bin/sh

# Ignore all flags
while getopts uL: flag; do true; done
shift $(($OPTIND - 1))

esc=`printf '\033['`
wdiff -n -w "${esc}41;97m" -x "${esc}m" -y "${esc}1;103m" -z "${esc}m" "$@" | fgrep -C2 "$esc"

Finally, you will also need the wdiff tool. If you are using Ubuntu or Debian, just install the "wdiff" package. On Mac OS X, "port install wdiff" should do the trick.

If you are having problems getting all this working, try the following:

  1. First make sure that something like "wdiff foo bar" works.
  2. Then make sure that "mywdiff foo bar" works.
  3. Only after that try to get "svnwdiff foo" working, too.

For merging, I have found out that the best solution is to not need to merge. I tend to use email, skype, etc. to coordinate who has got the write token on which parts of the document. If all coordination efforts fail, I use the above diff tool to figure out who has done what, and integrate manually.

Related Question