Skip to content

Instantly share code, notes, and snippets.

@thatlittlegit
Last active September 26, 2018 12:37
Show Gist options
  • Save thatlittlegit/352b7eeb66cae27b3dd1718534edee6b to your computer and use it in GitHub Desktop.
Save thatlittlegit/352b7eeb66cae27b3dd1718534edee6b to your computer and use it in GitHub Desktop.
XeLaTeX build tool

latexxer

Builds XeLaTeX files using a five-step process, with Biber/BibLaTeX.

Usage

sh build.sh <latex file>
#!/bin/sh
# latexxer main file
#
# This code is licensed under the GNU General Public License, version 3 or
# higher. See <https://gnu.org/licenses/gpl-3.0.txt>.
FLAG1=$1
[ $# -gt 0 ] && shift
abort() {
echo "Abort." >&2
exit 1
}
error() {
echo "error"
abort
}
echo "$0 by thatlittlegit. (c) 2018, under GNU GPL 3+"
echo -n "Checking for filename..."
if [ "$FLAG1" != "--tmp" ] && ! [ -z "$FLAG1" ]
then
FILE=$FLAG1
elif [ "$FLAG2" != "--tmp" ] && ! [ -z "$FLAG2" ]
then
FILE=$FLAG2
elif [ -f .buildrc ]
then
FILE=`sed '1q' <.buildrc | tr -d '\n'`
else
echo "error (no build file found)"
abort
fi
echo "ok [$FILE]"
echo -n "Removing extension from '$FILE'..."
FILE_NX=`echo $FILE | sed 's/\..*//g'`
echo "ok [$FILE_NX]"
echo -n "Running XeLaTeX [1]..."
yes X | xelatex $* $FILE 2>/tmp/buildsh.x1 >/tmp/buildsh.x1 || error && echo "ok"
echo -n "Running Biber [2]..."
biber $FILE_NX 2>/tmp/buildsh.bt >/tmp/buildsh.bt || error && echo "ok"
echo -n "Running XeLaTeX [3]..."
yes X | xelatex $* $FILE 2>/tmp/buildsh.x3 >/tmp/buildsh.x3 || error && echo "ok"
echo -n "Running XeLaTeX [4]..."
yes X | xelatex $* $FILE 2>/tmp/buildsh.x4 >/tmp/buildsh.x4 || error && echo "ok"
echo -n "Cleaning up..."
latexmk -c $FILE 2>/dev/null >/dev/null || error
rm /tmp/buildsh.?? || error
echo "ok"
if [ "$FLAG1" = "--tmp" ] || [ "$FLAG2" = "--tmp" ] || [ "$FLAG3" = "--tmp" ]
then
echo "Copying *.pdf to /tmp..."
cp -v *.pdf /tmp | awk 'BEGIN {i=1} {print "\t"i". "$0; i=i+1}'
fi
echo "$0 finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment