-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile
executable file
·41 lines (35 loc) · 1001 Bytes
/
compile
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
33
34
35
36
37
38
39
40
41
#!/bin/sh
# compiles latex/md into pdfs
unset QT_QPA_PLATFORMTHEME
file=$(readlink -f "${1:?Must specify a filename to compile as the first argument.}")
dir=$(dirname "$file")
base="${file%.*}"
extension="${file##.*}"
cd "$dir" || exit
# sends the message (first arg) to the user and exits
abort() {
if [ "$(tty)" = "not a tty" ]; then
notify "Compile Error" "$1"
else
printf "%s\n" "$1" >&2
fi
exit 1
}
case "$file" in
*\.md)
# if the user is editing a README.md file at the same level as a .git dir
# render with gfm (Github Flavored Markdown)
# else, render with pandoc markdown
if in-gitdir && [ -d "$dir/.git" ]; then
pandoc -f "gfm" -t html5 "$file" -o "$base".pdf
else
pandoc -t html5 "$file" -o "$base".pdf
fi
;;
*\.tex) pdflatex "$file" -output-directory -jobname="$base" "$dir" ;;
*) abort "Unsupported file extension ${extension}" ;;
esac
# if mupdf is active, refresh it
# used for live-previewing latex/md
# while Im writing it
pgrep -x mupdf && pkill -HUP mupdf