Skip to content

Instantly share code, notes, and snippets.

@dmsul
Last active April 12, 2019 03:25
Show Gist options
  • Save dmsul/a0a912ae64390aa122a2b7d2c71d3e6e to your computer and use it in GitHub Desktop.
Save dmsul/a0a912ae64390aa122a2b7d2c71d3e6e to your computer and use it in GitHub Desktop.
A small script to easily use Git with `latexdiff`
#!/bin/bash
# Special flag to clean up the mess
# Example: ./git-latexdiff.sh -c
# Deletes all the files created by this script; be careful, it will delete
# files with the names `old.tex` and `diff.tex` even if they weren't created
# by this script.
if [[ "$1" == "-c" ]] ; then
latexmk -C diff.tex
rm old.tex diff.tex
exit 0
fi
# Otherwise...
# First arg is filename (e.g., main.tex)
# Second arg is git revision (e.g., HEAD^)
# Example: ./git-latexdiff.sh my_thesis.tex HEAD
# This creates a diff PDF between your current file and the last time you made a commit.
if [[ -z "$2" ]] ; then
echo 'Error: Two few arguments!'
exit 1
fi
git show $2:$1 > old.tex
latexdiff old.tex $1 > diff.tex
latexmk diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment