-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
Β·221 lines (180 loc) Β· 6.1 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/zsh
scriptname=$(basename $0)
# Handle --no-color early to simplify setup.
if [[ "$1" == "--no-color" ]]; then
shift
nocolor="nocolor"
fi
if [[ "$nocolor" != "nocolor" ]] && [ -t 2 ]; then
BOLD="\e[1m"
RED="\e[1;31m"
ORANGE="\e[1;38;5;208m"
GREEN="\e[1;32m"
BLUE="\e[1;34m"
RESET="\e[0m"
else
BOLD=""
RED=""
ORANGE=""
GREEN=""
BLUE=""
RESET=""
fi
# --------------------------------------------------------------------------------------
show_help() {
{
printf "${BOLD}${scriptname} [--no-color] [<target>]${RESET}"
printf " with target one of these:\n"
printf " ${BOLD}venv${RESET} install & activate Python virtual env\n"
printf " ${BOLD}build${RESET} recreate the PDF document (default)\n"
printf " ${BOLD}lua${RESET} recreate PDF document with LuaLaTeX\n"
printf " ${BOLD}clean${RESET} delete auxiliary files\n"
printf " ${BOLD}arxiv${RESET} prepare submission to ArXiv\n"
printf " ${BOLD}acm${RESET} prepare submission to ACM\n"
printf " ${BOLD}-h, help${RESET} print this message\n"
printf "\n"
printf "Note that ${BOLD}venv${RESET} installs a new virtual environment only\n"
printf "if \"$(pwd)/.venv\" doesn't exist.\n"
} >&2
}
show_info() {
printf "${BLUE}INFO: $1${RESET}\n" >&2
}
show_success() {
printf "${GREEN}SUCCESS: $1${RESET}\n" >&2
}
show_warning() {
printf "${ORANGE}WARNING: $1${RESET}\n" >&2
}
show_error() {
printf "${RED}ERROR: $1${RESET}\n" >&2
}
# --------------------------------------------------------------------------------------
do_venv() {
local installing=0
if [[ -d "$VIRTUAL_ENV" ]]; then
show_info "Already running inside Python virtual environment!"
return
elif [[ ! -d ./.venv ]]; then
show_info "Creating virtual environment in '.venv'"
installing=1
python3 -m venv .venv
fi
# Since activate is not being sourced in an interactive shell, PS1 is not
# defined and the resulting prompt a bit bare. Extracting PS1 from an
# interactive shell (which only executes one command) helps avoid that.
DEFAULT_PS1=$(/bin/zsh -i -c "echo \"[[[\$PS1]]]\"")
show_info "Activating virtual environment in '.venv'"
source ./.venv/bin/activate
PS1="(.venv) ${DEFAULT_PS1:3:(-3)}"
export PS1
if [[ $installing == 1 ]]; then
show_info "Installing required Python packages."
pip install -r supplements/requirements.txt
fi
show_info "'.venv' is activated, use 'exit' to deactivate!"
exec /bin/zsh -f -i
}
# --------------------------------------------------------------------------------------
export TEXINPUTS=.:emo-graphics/:images/:
local LATEX_ENGINE=pdflatex
check_bibtex() {
# Surface actionable information from BibTeX's output
local warnings=$(
grep -e '^Warning--' main.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
show_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 `' main.log)
if [[ -n $warnings ]]; then
show_error "Please fix the following LaTeX warnings:\n$warnings"
exit 1
fi
}
do_build() {
$LATEX_ENGINE main
bibtex main
check_bibtex
$LATEX_ENGINE main
while ( grep -q '^LaTeX Warning: Label(s) may have changed' *.log ); do
$LATEX_ENGINE main
done
check_latex
}
# --------------------------------------------------------------------------------------
do_clean() {
rm -f source/comment.cut
rm -f source/missfont.log
for suffix in aux bbl blg fdb_latexmk fls log out pdf; do
rm -f "source/main.$suffix"
done
rm -f .DS_store source/.DS_store supplements/.DS_store
rm -rf arxiv
rm -f acm.zip arxiv.zip
}
# --------------------------------------------------------------------------------------
prep_arxiv() {
# Make sure that the paper builds and the working directory exists.
show_info "Build article"
( cd source && do_build $@ )
[ ! -d arxiv ] && mkdir arxiv
[ ! -d arxiv/images ] && mkdir arxiv/images
[ ! -d arxiv/emo-graphics ] && mkdir arxiv/emo-graphics
# Combine all LaTeX sources into one and inject pdflatex marker.
show_info "Stage files"
( cd source && latexpand main.tex -o ../arxiv/article.tex )
sed -i '' '2i\
\\pdfoutput=1\
' arxiv/article.tex
sed -i '' '9i\
\\graphicspath{{images/}{emo-graphics/}}\
' arxiv/article.tex
# Include the emo package, the bibliography, and all image as well as emoji.
cp source/emo.sty arxiv
cp source/emo.def arxiv
cp source/main.bbl arxiv/article.bbl
cp source/images/*.{jpg,png} arxiv/images
cp source/emo-graphics/emo-*.pdf arxiv/emo-graphics/
# Package it all up
show_info "Create archive"
zip -r arxiv.zip arxiv/*
# Make sure the paper still builds.
show_info "Build archive version"
unset TEXINPUTS
(cd arxiv && pdflatex article)
(cd arxiv && pdflatex article)
}
# --------------------------------------------------------------------------------------
prep_acm() {
#( cd source && do_build $@ )
#mv source/main.pdf pdf/main.pdf
#do_clean
#zip -r acm.zip pdf source supplements build.sh
}
# --------------------------------------------------------------------------------------
target=${1:-build}
shift
case $target in
venv ) do_venv $@ ;;
build ) ( cd source && do_build $@ ) || exit 1 ;;
lua ) LATEX_ENGINE=lualatex
( cd source && do_build $@ ) || exit 1 ;;
clean ) do_clean $@ ;;
arxiv ) prep_arxiv $@ ;;
acm ) prep_acm $@ ;;
-h | help ) show_help >&2 ;;
*)
show_error "\"$target\" is not a valid build target!"
show_help
exit 1
;;
esac
show_success "Happy, happy, joy, joy!"