alkaa/roles/scripts/files/compiledoc
2022-12-22 15:19:12 +01:00

34 lines
742 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"]; then
tectonic -X build
else
params=""
( grep -q minted $file) && params="$params -Z shell-escape"
tectonic -X compile "$params" $file
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" \
-o "$base".pdf "$file" ;;
tex) textype "$file" ;;
esac