-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgit-latexdiff-helper
executable file
·96 lines (79 loc) · 3.1 KB
/
git-latexdiff-helper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# This tool is written by Richard Darst and released under the Gnu
# General Public License version 2 or later.
DEFAULT_LATEX=pdflatex
DEFAULT_LATEXDIFF=latexdiff
DEFAULT_PDFVIEWER=evince
set -e
[ ! -z "$GLD_CONT" ] && set +e # do not stop on errors
[ ! -z "$V" ] && set -x
[ ! -z "$V" ] && env
[ ! -z "$V" ] && pwd
[ ! -z "$V" ] && echo "$@"
# General note:
# ${NAME:-expansions} uses expansion as a default if NAME is empty
LATEX=${LATEX:-$DEFAULT_LATEX}
LATEXDIFF=${LATEXDIFF:-$DEFAULT_LATEXDIFF}
if [ ! -f "$1" -o ! -f "$2" ] ; then
echo "Input files: $1, $2"
echo "Input files are not found. Are you running properly?"
echo ""
echo "Usage:"
echo " git config --global difftool.latexdiff.cmd '$0 \"\$LOCAL\" \"\$REMOTE\"'"
echo " git config --global alias.latexdiff \"difftool -t latexdiff\""
echo " git latexdiff [V1..V2] filename.tex"
echo " Must be run with only FILE.tex, it obviously doesn't work on non-tex files."
echo ""
echo "Environment variables for customization (OUTPUT=x.pdf git latexdiff ...):"
echo " OUTPUT: filename to write to"
echo " PDFVIEWER: PDF viewer to launch"
echo " LATEX: The latex compiler, latex or pdflatex"
echo " LDOPTS: Command line options to latexdiff"
echo " V: Verbose mode, set to anything for level1, V=2 for full output."
echo " GLD_CONT: Do not stop on errors (don't \"set -e\" in bash)."
echo " Sometimes useful when latex or bibtex has an error."
fi
# This is based on
# http://tex.stackexchange.com/questions/1325/using-latexdiff-with-git,
# with many more improvements.
TMPDIR=$(mktemp -d tmp.git-latexdiff.XXXXXXXX)
#echo $TMPDIR
$LATEXDIFF $LDOPTS "$1" "$2" > $TMPDIR/diff.tex 2>/dev/null
# chdir to the directory we were in when we ran the git latexdiff command
cd "$GIT_PREFIX"
OLDPWD="`pwd`"
# All the miscelaneous text .aux, etc, files will go into here - our
# temporary directory, to not clutter our working directory
export TEXMFOUTPUT=$TMPDIR
# We have to put the actual compilation commands in a function in
# order to do conditional redirection. Bash doesn't have a better
# means of doing this.
_runlatex () {
echo "running"
echo $LATEX
$LATEX -interaction nonstopmode -output-directory $TMPDIR $TMPDIR/diff.tex || true
# Run bibtex + latex again if we have the \bibliography command.
if grep -q '\\bibliography[^a-zA-Z]' $TMPDIR/diff.tex ; then
bibtex $TMPDIR/diff
$LATEX -interaction nonstopmode -output-directory \
$TMPDIR $TMPDIR/diff.tex || true
fi
$LATEX -interaction nonstopmode -output-directory $TMPDIR $TMPDIR/diff.tex \
|| true
echo "done"
}
# Either run without redirection if $V==2 or else redirect everything away.
if [ "$V" = 2 ] ; then _runlatex
else _runlatex &> /dev/null
fi
# Copy output back to where it belongs.
cd "$OLDPWD"
OUTPUT=${OUTPUT:-diff-`basename $2`.pdf}
cp $TMPDIR/diff.pdf "$OUTPUT"
echo "Result is in $OUTPUT"
[ ! -z "$V" ] && echo " --> in `pwd`"
if [ ! -z "$DISPLAY" ] ; then
PDFVIEWER=${PDFVIEWER:-$DEFAULT_PDFVIEWER}
"$PDFVIEWER" "$OUTPUT" &> /dev/null
fi
rm -rf "$TMPDIR"