summaryrefslogtreecommitdiff
path: root/gup/pdf.gup
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-06-07 02:14:31 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2017-06-07 02:14:31 +0200
commite7b84f8b87da8ea1add3cda9ba3a07cf1f86e7b6 (patch)
treef0d2de6986e4fa66ebe90f30a81fcf943c9c7a45 /gup/pdf.gup
parentff8deaa9ed63e6bd067c45c75966a24f7bfcaab3 (diff)
downloaduni-e7b84f8b87da8ea1add3cda9ba3a07cf1f86e7b6.tar
uni-e7b84f8b87da8ea1add3cda9ba3a07cf1f86e7b6.tar.gz
uni-e7b84f8b87da8ea1add3cda9ba3a07cf1f86e7b6.tar.bz2
uni-e7b84f8b87da8ea1add3cda9ba3a07cf1f86e7b6.tar.xz
uni-e7b84f8b87da8ea1add3cda9ba3a07cf1f86e7b6.zip
Much more extensive pdf compiling
Diffstat (limited to 'gup/pdf.gup')
-rwxr-xr-xgup/pdf.gup76
1 files changed, 72 insertions, 4 deletions
diff --git a/gup/pdf.gup b/gup/pdf.gup
index 3b3aa3a..96f46ca 100755
--- a/gup/pdf.gup
+++ b/gup/pdf.gup
@@ -1,9 +1,77 @@
1#!/usr/bin/env zsh 1#!/usr/bin/env zsh
2 2
3base=(${2%.pdf}.(md|lhs)([1])) 3ret=0
4 4
5gup -u ${base} preamble.tex 5logged() {
6 printf ">>> ā€˜%sā€™ in %s\n" "$*" $(pwd) >&2
7 ${@}
8 ret=$?
9 printf ">>> %d\n" $ret >&2
10}
6 11
7for i ({0..1}); do 12typeset -a cleanupList
8 pandoc -t latex -o $1 -V "geometry=margin=2cm" -V "fontfamily=libertine" -H preamble.tex --listings --latex-engine=lualatex ${base} >&2 13cleanupList=()
14cleanup() {
15 for cmd in ${cleanupList}; do
16 eval $cmd
17 done
18}
19trap cleanup EXIT
20
21base=(${2%.pdf}.(md|lhs|tex)([1]))
22metadata=(${2%.pdf}.meta.yml([1]N))
23
24gup -u ${base} ${metadata} preamble.tex
25
26buildDir=$(pwd)
27
28base=${base:A}
29metadata=${metadata:A}
30cd ${base:h}
31
32input=${base}
33
34typeset -a extraArgs
35extraArgs=(-R -V "geometry=margin=2cm" -V "fontfamily=libertine" -H ${buildDir}/preamble.tex --listings --latex-engine=lualatex --filter=pandoc-citeproc --biblatex)
36
37
38if [[ -n ${metadata} ]]; then
39 input=$(mktemp)
40 cleanupList+=("rm -v ${input}")
41
42 logged pandoc -f markdown -t native -s ${metadata} | head -n -1 >>${input}
43 logged pandoc -R -t native ${base} >>${input}
44
45 extraArgs+=(-f native)
46fi
47
48# logged pandoc ${extraArgs} -t latex ${base} | cat -n >&2
49
50compileDir=$(mktemp -d)
51cleanupList+=("cd /" "rm -rfv ${compileDir}")
52
53logged pandoc ${extraArgs} -t latex -o ${compileDir}/${base:t:r}.tex ${input} >&2
54
55cd ${compileDir}
56for f (bib); do
57 printf "Checking for ā€˜%sā€™\n" ${base:h}/${f} >&2
58 [[ -e ${base:h}/${f} ]] || continue
59 logged rsync -av ${base:h}/${f} .
60done
61
62max=5
63runs=0
64run=true
65while ${run} && [[ ${runs} -lt ${max} ]]; do
66 output=$(mktemp)
67 cleanupList+=("rm -v ${output}")
68 logged lualatex ${base:t:r}.tex >${output} </dev/null
69 ( return $ret ) || { logged cat ${output}; break }
70 grep -C 2 -i "warning" ${output}
71 run=false
72 grep -Eq $'(\\(re\\)run Biber)|(Please rerun LaTeX)' ${output} && run=true
73 [[ -e ${base:t:r}.bcf && runs -eq 0 ]] && logged biber ${base:t:r}
74 runs=$((runs + 1))
9done 75done
76
77cp -v ${base:t:r}.pdf $1