voidrice/.scripts/compiler

33 lines
870 B
Text
Raw Normal View History

2018-04-11 00:48:45 +00:00
#!/bin/bash
# This is a compilation handler, so to speak, which I have vim run.
#
# It compiles a document to pdf
2018-07-25 16:14:38 +00:00
#
# If you put the sequence `xelatex` somewhere in the first 5 lines of a .tex
# file, it will be compiled with `xelatex` rather than `pdflatex`.
#
# If it detects an `addbibresource` line, it will run `biber` and perform
# multiple compiles to get the references correct.
2018-04-11 00:48:45 +00:00
2018-07-24 17:34:38 +00:00
file=$(readlink -f "$1")
2018-04-11 00:48:45 +00:00
ext="${file##*.}"
base="${file%.*}"
2018-07-25 16:14:38 +00:00
textype() { \
command="pdflatex"
( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex"
$command "$base" &&
grep -i addbibresource "$file" &&
2018-07-24 17:34:38 +00:00
biber "$base" &&
2018-07-25 16:14:38 +00:00
$command "$base" &&
$command "$base"
}
2018-04-11 00:48:45 +00:00
case "$ext" in
rmd) echo "require(rmarkdown); render('$file')" | R --vanilla ;;
2018-07-24 17:34:38 +00:00
tex) textype "$file" ;;
2018-04-11 00:48:45 +00:00
md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;;
2018-07-25 16:14:38 +00:00
*) sent "$file" 2>/dev/null & ;;
2018-04-11 00:48:45 +00:00
esac