Skip to content

Instantly share code, notes, and snippets.

@jhofman
Last active January 28, 2016 20:23
Show Gist options
  • Save jhofman/ab37b6df68e0e0208341 to your computer and use it in GitHub Desktop.
Save jhofman/ab37b6df68e0e0208341 to your computer and use it in GitHub Desktop.
word-style "track changes" with latexdiff and git
#!/bin/bash
#
# script to show word-style "track changes" from a previous git revision
#
if [ $# -lt 2 ]
then
echo "usage: $0 <rev> <maintex>"
echo " rev is the prefix of a git revision hash"
echo " see 'git log' for revision hashes"
echo
echo " mainttex is the main source file for pdflatex, e.g. main.tex"
echo " supports flattening of \input-ed tex from main source"
echo
echo " output is in <rev>/changes.pdf"
exit 1
fi
# get the path of the current directory relative to the git root
# http://stackoverflow.com/a/16951268/76259
rel_path=`dirname $(git ls-tree --full-name --name-only HEAD main.tex)`
# get the revision to compare to
rev=$1
[ -d $rev ] || mkdir $rev
# get the name of the main tex file
maintex=$2
# pull old versions of .tex files
sections=`grep -i input $maintex | awk -F'[{}]' '{print $2}'`
for section in $maintex $sections
do
if echo $section | grep -qv '.tex$'
then
section=${section}.tex
fi
git show $rev:$rel_path/$section > $rev/$section
done
cd $rev
# symlink supporting files
for f in figures *.cls *.bib *.sty *.bst
do
ln -s ../$f .
done
# generate diff with latexdiff, clean up, and produce pdf
latexdiff --flatten $maintex ../$maintex > changes.tex
dos2unix changes.tex
grep -v '^$' changes.tex > tmp
mv tmp changes.tex
pdflatex changes.tex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment