20

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.

2
  • git supports word diffs, that is, not the entire line gets highlighted, only the portion of the line that has been changed. It might be an option if Subversion isn't mandatory.
    – Pieter
    Oct 16, 2010 at 6:32
  • I'm not sure to understand what you are asking for. Can you make an example? Oct 16, 2010 at 7:02

2 Answers 2

9

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.

3
  • svn lock should solve the token issue
    – TH.
    Oct 16, 2010 at 22:47
  • The diff part here sounds good. But it feels to me like this is only a partial answer. Unfortunately my collaborators are probably going to be working on the document simultaneously. If this is still the best answer in a few days I'll mark it accepted.
    – Paul
    Oct 17, 2010 at 22:26
  • 1
    I love it! Great solution @Jukka. (I use homebrew instead of macport, so it's brew install wdiff.)
    – Memming
    Mar 16, 2012 at 14:26
0

On windows there is a tool called Beyond Compare (http://www.scootersoftware.com/), it is a good diff and merge tool.

3
  • Unfortunately Beyond Compare is not free (starts at $30). For me this is a problem.
    – Paul
    Oct 17, 2010 at 22:18
  • 1
    Well you asked for the best tool... not the best open source tool, and in this case BC is actually a little better than meld, kdiff3 and kompare.
    – Johan
    Oct 18, 2010 at 5:26
  • does it support synctex?
    – peter
    Jan 21, 2021 at 4:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .