-
-
Save whophil/3c826a3f1790f56284102af608c26f75 to your computer and use it in GitHub Desktop.
Produces a diff PDF of a LaTeX repo against a specified hash using latexdiff.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Shell script to run latexdiff against the same file from a specified commit hash. | |
# Example: | |
# ./git-latexdiff.sh main.tex 12dfa1a | |
# $1 is the name of the old tex file (relative to the remote repo) | |
# $2 is the hash of the commit that we'd like to compare against | |
# paths | |
DIFFDIR=$(mktemp -du ./git-latexdiff.XXXXXX) | |
ORIDIR=`pwd` | |
# command line arguments | |
TEX=$1 | |
VER=$2 | |
# get the name of the TeX file without extension | |
TEXNAME=$(basename "$TEX") | |
EXTENSION="${TEXNAME##*.}" | |
TEXNAME="${TEXNAME%.*}" | |
# if no hash is specified, use head | |
if [ -z "$2" ];then | |
VER='HEAD' | |
fi | |
# if no file is specified, guess from file with `begin{document}'' | |
if [ -z "$1" ];then | |
TEX=`grep 'begin{document}' *.tex | grep -m 1 begin | cut -d\: -f1` | |
fi | |
# clone current repo into DIFFDIR, checkout version hash | |
git clone . "$DIFFDIR/" | |
cd "$DIFFDIR" | |
git checkout $VER | |
git reset --hard | |
# run latex, bibtex, latex, pdflatex (for refs) | |
latex -interaction=nonstopmode "$TEX" $OPTIONS | |
bibtex main.aux | |
latex -interaction=nonstopmode "$TEX" $OPTIONS | |
pdflatex -interaction=nonstopmode -shell-escape "$TEX" $OPTIONS | |
# run latexdiff on tex files (with flatten option) | |
latexdiff --flatten "$TEX" "$ORIDIR/$TEX" > latexdiff.tex | |
# run latex, bibtex on latexdiff | |
latex -interaction=nonstopmode latexdiff.tex $OPTIONS | |
bibtex latexdiff.aux | |
# run latexdiff on bbl files | |
latexdiff --t CFONT --append-textcmd="abstract" $TEXNAME.bbl $ORIDIR/$TEXNAME.bbl > latexdiff.bbl | |
# run latex, pdflatex to get final product | |
latex -interaction=nonstopmode latexdiff.tex $OPTIONS | |
pdflatex -interaction=nonstopmode -shell-escape latexdiff.tex $OPTIONS | |
# move latexdiff to the original directory | |
mv latexdiff.pdf $ORIDIR/latexdiff-$2.pdf | |
cd $ORIDIR | |
# rm -rf $TMPDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment