Using latexdiff with git

The most complete and general solution today is probably git-latexdiff, here:

https://gitlab.com/git-latexdiff/git-latexdiff

The script internally checks out the full tree for the specified revisions, and calls latexdiff with the --flatten option (or can call latexpand), hence this works if the document is split into multiple .tex files.

The script contains many special-cases to make it work for as many cases as possible (it received contributions from more than 10 contributors, most of them being "make it work for my use-case too").

Note: I'm the main author.


Do you mean something like the following?

~/bin/git-latexdiff

#!/bin/bash
TMPDIR=$(mktemp -d /tmp/git-latexdiff.XXXXXX)
latexdiff "$1" "$2" > $TMPDIR/diff.tex
pdflatex -interaction nonstopmode -output-directory $TMPDIR $TMPDIR/diff.tex
evince $TMPDIR/diff.pdf
rm -rf $TMPDIR

~/.gitconfig

[difftool.latex]
        cmd = git-latexdiff \"$LOCAL\" \"$REMOTE\"
[difftool]
        prompt = false
[alias]
        ldiff = difftool -t latex

You can then use the diff by running git ldiff HEAD~1, for example.


There is another option which has become available since the answers here were written. I think that it will be preferred by some as it does not require any additional packages.

Beginning in version 1.0.1, latexdiff has come with a version of latexdiff-vc which supports git. Simply running

    latexdiff-vc [ latexdiff-options ] [ latexdiff-vc-options ] -r [rev1] [-r rev2] file1.tex [ file2.tex ...]

will run latexdiff on the specified versions from its best guess of the version control system in use. The --git option specifies that it should assume git. This can also be specified by running latexdiff-git, which has git as the default VCS.

The option --pdf will run pdflatex (and bibtex if necessary) on the output.

See the latexdiff manual for more information.