Skip to content

Instantly share code, notes, and snippets.

@arthurd2
Last active April 17, 2016 02:25
Show Gist options
  • Save arthurd2/1503e7e368f9eca25b77 to your computer and use it in GitHub Desktop.
Save arthurd2/1503e7e368f9eca25b77 to your computer and use it in GitHub Desktop.
Easy integration with GIT and Latexdiff
#!/bin/bash
TMPDIR=$(mktemp -d /tmp/git-latexdiff.XXXXXX)
ORIDIR=`pwd`
TEX=$1
VER=$2
if [ -z "$2" ];then
VER='HEAD'
fi
if [ -z "$1" ];then
TEX=`grep 'begin{document}' *.tex | grep -m 1 begin | cut -d\: -f1`
fi
git clone . "$TMPDIR/"
cd "$TMPDIR"
git checkout $VER
latexdiff --config="PICTUREENV=(?:picture|algorithm|eqnarray|comment|tikzpicture|DIFnomarkup)[\w\d*@]*" --flatten "$TEX" "$ORIDIR/$TEX" > diff.tex
latex -interaction=nonstopmode diff.tex &> /dev/null
bibtex diff.aux
latex -interaction=nonstopmode diff.tex &> /dev/null
pdflatex -interaction=nonstopmode diff.tex &> /dev/null
evince diff.pdf
rm -rf $TMPDIR
echo
echo "$0 $TEX $VER"
echo
@whophil
Copy link

whophil commented Mar 14, 2016

Thanks for this, it was very useful. I ran into a problem with the variable name TMPDIR, since that name is used by Ghostscript (which in my TeX files is called by epstopdf). Ghostscript was throwing an error about being unable to write a temporary file during the EPS to PDF conversion process. It took me awhile to figure out what the problem was, so I thought it might be worth sharing that info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment