summaryrefslogtreecommitdiffstats
path: root/.scripts/compiler
blob: c6fc8b871bcbdee71fb11aa67535aea48418e31f (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
32
#!/bin/bash

# This is a compilation handler, so to speak, which I have vim run.
#
# It compiles a document to pdf
#
# 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.

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

textype() { \
	command="pdflatex"
	( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex"
	$command "$base" &&
	grep -i addbibresource "$file" &&
	biber "$base" &&
	$command "$base" &&
	$command "$base"
	}

case "$ext" in
	rmd) echo "require(rmarkdown); render('$file')" | R --vanilla ;;
	tex) textype "$file" ;;
	md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;;
	*) sent "$file" 2>/dev/null & ;;
esac