-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·134 lines (113 loc) · 3.17 KB
/
build.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/zsh
if [[ "$1" == "--no-color" ]]; then
shift
nocolor="nocolor"
fi
if [[ "$nocolor" != "nocolor" ]] && [ -t 2 ]; then
BOLD="\e[1m"
ERROR="\e[1;31m"
WARNING="\e[1;38;5;208m"
SUCCESS="\e[1;32m"
INFO="\e[1;34m"
RESET="\e[0m"
else
BOLD=""
ERROR=""
WARNING=""
SUCCESS=""
INFO=""
RESET=""
fi
log() {
eval "STYLE=\"\${$1}\""
print -u 2 "${STYLE}$1: $2${RESET}"
}
prepare_figures() {
for name in meta reports reports-best-fit platforms countries continents flow share comparable-reports; do
rsvg-convert -f pdf -o "figure-${name}.pdf" "../figure/${name}.svg"
done
}
check_bibtex() {
# Surface actionable information from BibTeX's output
local warnings=$(
grep -e '^Warning--' "$1.blg" |
grep -ve 'no number and no volume' |
grep -ve 'page numbers missing' |
grep -ve 'can'"'"'t use both author and editor fields')
if [[ -n $warnings ]]; then
log ERROR "Please fix the following BibTeX warnings:\n$warnings"
exit 1
fi
}
check_latex() {
# Surface actionable information from LaTeX's output
local warnings=$(
grep -e '^LaTeX Warning: Reference `' "$1.log")
if [[ -n $warnings ]]; then
log ERROR "Please fix the following LaTeX warnings:\n$warnings"
exit 1
fi
}
local LATEX_ENGINE=pdflatex
do_build() {
log INFO "$LATEX_ENGINE $1"
$LATEX_ENGINE -interaction=batchmode "$1"
log INFO "bibtex $1"
bibtex -terse "$1"
check_bibtex "$1"
log INFO "$LATEX_ENGINE $1"
$LATEX_ENGINE -interaction=batchmode "$1"
while ( grep -q '^LaTeX Warning: Label(s) may have changed' "$1.log" ); do
log INFO "$LATEX_ENGINE $1"
$LATEX_ENGINE -interaction=batchmode "$1"
done
check_latex "$1"
}
do_wordcount() {
pandoc report.tex -f latex --quiet -t plain -s -o report.txt
local WITHOUT_REFS="$(wc -w report.txt | cut -wf 1-2 | xargs)"
pandoc report.tex -f latex --quiet -C --bibliography=bibliography.bib -t plain -s -o report.txt
local WITH_REFS="$(wc -w report.txt | cut -wf 1-2 | xargs)"
log INFO "$WITHOUT_REFS words without, $WITH_REFS words with references"
}
prep_arxiv() {
# Make sure working directory exists.
[ ! -d ../arxiv ] && mkdir ../arxiv
# Combine all LaTeX sources into one.
log INFO "Stage arxiv"
latexpand report.tex -o ../arxiv/report.tex || exit "$?"
# Include the bibliography.
cp report.bbl ../arxiv/report.bbl
cp figure-*.pdf ../arxiv/
# Package it all up
log INFO "Create archive"
(cd .. && zip -r arxiv.zip arxiv/*)
# Make sure the paper still builds.
log INFO "Build archive version"
unset TEXINPUTS
(cd ../arxiv && pdflatex report) || exit "$?"
(cd ../arxiv && pdflatex report) || exit "$?"
(cd ../arxiv && pdflatex report) || exit "$?"
}
target=${1:-report}
if [ $# -ne 0 ]; then
shift
fi
case $target in
figure )
prepare_figures
;;
report )
do_build report
;;
wordcount )
do_wordcount
;;
arxiv )
prep_arxiv
;;
* )
log ERROR "\"$target\" is not a valid build target!"
exit 1
;;
esac