summaryrefslogtreecommitdiffstats
path: root/.scripts/compiler
blob: ca7455dc60c21241c6c4a8b149c74c4f88fd7435 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash

# This is a compilation handler, so to speak, which I have vim run.
#
# It compiles a document to pdf

file=$(readlink -f "$1")
ext="${file##*.}"
base="${file%.*}"

textype() { [ grep -i addbibresource "$file" ] && bib=1

if sed 5q "$file" | grep -i -q 'xelatex' > /dev/null 2>&1; then
	[ -z ${bib+x} ] || (xelatex "$base" && break)
	xelatex "$base" &&
	biber "$base" &&
	xelatex "$base" &&
	xelatex "$base"
else
	[ -z ${bib+x} ] || (pdflatex "$base" && break)
	pdflatex "$base" &&
	biber "$base" &&
	pdflatex "$base" &&
	pdflatex "$base"
fi ;}

case "$ext" in
	rmd) echo "require(rmarkdown); render('$file')" | R --vanilla ;;
	tex) textype "$file" ;;
	md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;;
esac