Skip to content

Instantly share code, notes, and snippets.

@mKaloer
Last active August 29, 2015 14:06
Show Gist options
  • Save mKaloer/f9488142f76b29a2e2e6 to your computer and use it in GitHub Desktop.
Save mKaloer/f9488142f76b29a2e2e6 to your computer and use it in GitHub Desktop.
chktex pre-commit hook for git
#!/bin/sh
# Run chktex on 'report.tex'. Notice that this does not only test the staged files due
# to the recursive nature of chktex, but everything referenced by 'report.tex'.
# The chktex exit code cannot be used to distinguish a
# well formatted LaTeX document and a bad-formatted document, so we do that by grepping
# warings in the output. If the word "warning" has been written to the output, the output
# is printed to stdout. Also remove some chktex warnings of the form "chktex: WARNING --".
BODY=$(
output="$(chktex -q -V report.tex 2>&1 | grep -v 'chktex: WARNING --')";
warn=$(echo $output | grep Warning);
if [ "$warn" ] ;
then echo "$output" ;
fi
)
if [ -n "$BODY" ]
then
echo "$BODY"
echo "------\nPlease fix the errors before committing!"
exit 1
else exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment