alkaa/roles/scripts/files/compiledoc

37 lines
979 B
Bash

#!/usr/bin/env sh
# takes a file and compiles it into a pdf file, if possible
# inspiration from https://github.com/LukeSmithxyz/voidrice/blob/master/.local/bin/compiler
file=$(readlink -f "$1")
dir=${file%/*}
base="${file%.*}"
ext="${file##*.}"
cd "$dir" || exit 1
compile_tex() { \
if [ -e "$dir/../Tectonic.toml" -o -e "$dir/../../Tectonic.toml" ]; then
tectonic -X build
else
params=""
( grep -q minted $file) && params="$params -Z shell-escape-cwd=$dir"
tectonic -X compile$params $file
rm "$base.aux" "$base.bbl" "$base.bcf" "$base.blg" "$base.log" "$base.out" "$base.run.xml" "$base.toc" "$base.xdv"
fi
}
case "$ext" in
md) pandoc -t pdf \
--pdf-engine tectonic \
-f gfm \
-V linkcolor:blue \
-V geometry:a4paper \
-V geometry:margin=2cm \
-V mainfont="Liberation Sans" \
-V monofont="Liberation Mono" \
--highlight-style tango \
--include-in-header ~/.local/bin/inline_code.tex \
-o "$base".pdf "$file" ;;
tex) compile_tex ;;
esac