git pre-commit hook for tex checking
[shutils.git] / git / pre-commit-texcheck
1 #!/bin/sh
2
3 set -e
4
5 [ "$#" > "0" ] && cd "$1"
6
7 tmpdir=$(mktemp -d)
8 cleanup()
9 {
10 rm -r "$tmpdir"
11 }
12
13 for f in $(find -name "*.tex"); do
14 # Only main tex files are interesting
15 grep -q "\documentclass" "$f" || continue
16
17 if ! pdflatex -output-directory "$tmpdir" $f < /dev/null > /dev/null; then
18 echo >&2 "pdflatex failed on '$f'."
19 cleanup
20 exit 1
21 fi
22 done
23
24 cleanup