Skip to content

Instantly share code, notes, and snippets.

@keeferrourke
Created May 28, 2018 04:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keeferrourke/e740d420e55bc02ed48a5d80b4812de8 to your computer and use it in GitHub Desktop.
Save keeferrourke/e740d420e55bc02ed48a5d80b4812de8 to your computer and use it in GitHub Desktop.
Simple bash script to compile a LaTeX document with pdflatex, and clean up auxillary output files.
#!/bin/bash
#
# latexcompile
# Keefer Rourke <mail@krourke.org>
#
# To the extent possible under law, the person who associated CC0 with
# latexcompile has waived all copyright and related or neighboring rights
# to latexcompile.
#
# See <http://creativecommons.org/publicdomain/zero/1.0/> for a copy of
# the CC0 legalcode.
if [ $# -eq 0 ]; then
echo "usage: latexcompile FILE.tex [--open]"
echo "cleanly compile LaTeX documents to PDF without cluttering the" \
working directory."
exit 2
fi
BASE="${1%.*}"
pdflatex $1 2>/dev/null 1>&2
if [ $? -ne 0 ]; then
echo "Compilation error. Check log."
exit 1
fi
rm "$BASE.log" "$BASE.aux" "$BASE.out"
if [ $2 == "--open" ] || [ $2 == "-o" ]; then
xdg-open "$BASE.pdf"
fi
exit 0
@keeferrourke
Copy link
Author

Quick dirty script to keep me sane while working on LaTeX documents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment