Last active
August 29, 2015 14:06
-
-
Save mKaloer/f9488142f76b29a2e2e6 to your computer and use it in GitHub Desktop.
chktex pre-commit hook for git
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
#!/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