Last active
March 14, 2016 09:07
-
-
Save whophil/7752874fa5f2f7f9abf0 to your computer and use it in GitHub Desktop.
Shell script to run latexdiff against a TeX file (with specified commit hash) from the current repository.
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 CTRADITIONAL --append-context2cmd="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
Seems to have some issues with
\abstract{}
the environment (abstract text is currently not marked up).There is some discussion of this here https://www.researchgate.net/post/How_can_I_track_changes_in_LaTeX_especially_abstractenvironment