Skip to content

Instantly share code, notes, and snippets.

@late-in-autumn
Last active February 23, 2017 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save late-in-autumn/c218a5b24cec98559fa02995b4c5e337 to your computer and use it in GitHub Desktop.
Save late-in-autumn/c218a5b24cec98559fa02995b4c5e337 to your computer and use it in GitHub Desktop.
#!/bin/bash
## latexbuild.sh: a simple wrapper around latexmk and various LaTeX-related tools
## automated shadow build of LaTeX files, making working directory clean
## Depends on: latexmk, xetex, synctex, coreutils, bash
## Usage: latexbuild.sh <filename>
FILENAME=$1
BASENAME=$(basename ${FILENAME}|cut -d. -f1)
if [ -d ./build ]
then
cd build
else
mkdir build
if [ $? -eq 0 ]
then
cd build
else
echo "Error creating shadow build directory, exiting."
cd ..
exit -2
fi
fi
latexmk -xelatex -verbose -file-line-error -synctex=0 -interaction=nonstopmode ../${FILENAME}
if [ $? -ne 0 ]
then
echo "Error occurred, see build/${BASENAME}.log for details"
cd ..
exit -1
fi
mv ${BASENAME}.pdf ..
if [ $? -ne 0 ]
then
echo "Error moving output PDF to working directory, PDF can still be retrieved in build/ directory."
cd ..
exit -3
fi
cd ..
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment