git pre-commit hook for tex checking
authorStefan Huber <shuber@sthu.org>
Fri, 13 Dec 2013 12:38:27 +0000 (13:38 +0100)
committerStefan Huber <shuber@sthu.org>
Fri, 13 Dec 2013 12:38:27 +0000 (13:38 +0100)
git/pre-commit-texcheck [new file with mode: 0755]

diff --git a/git/pre-commit-texcheck b/git/pre-commit-texcheck
new file mode 100755 (executable)
index 0000000..29547fe
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+set -e
+
+[ "$#" > "0" ] && cd "$1"
+
+tmpdir=$(mktemp -d)
+cleanup()
+{
+    rm -r "$tmpdir"
+}
+
+for f in $(find -name "*.tex"); do
+    # Only main tex files are interesting
+    grep -q "\documentclass" "$f" || continue
+
+    if ! pdflatex -output-directory "$tmpdir" $f < /dev/null > /dev/null; then
+        echo >&2 "pdflatex failed on '$f'."
+        cleanup
+        exit 1
+    fi
+done
+
+cleanup