-
Notifications
You must be signed in to change notification settings - Fork 18
/
generate-pdf
executable file
·55 lines (45 loc) · 1.27 KB
/
generate-pdf
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
#!/bin/sh
# Generate metamath.pdf from source file metamath.tex.
# Stop processing if error occurs (-e) and show what we're doing (-x)
set -ex
style="${1:-normal}"
style="${style%.sty}"
texfile="${2:-metamath}"
texfile="${texfile%.tex}"
if [ "$style" == 'normal' ]; then
outfile="$texfile"
else
outfile="${texfile}-${style}"
fi
# Try to remove output .pdf first - if we can't, no point in going further.
rm -f "${outfile}.pdf"
# Run pdflatex on $1.
# TODO: Add -output-directory _build
do_pdflatex () {
pdflatex -halt-on-error -interaction=nonstopmode "$1"
}
# Set up temporary directory
tempdir="temp-$outfile"
rm -fr "$tempdir"
mkdir -p "$tempdir"
cp -p "${texfile}.tex" "$tempdir"
cp -p "${style}.sty" "$tempdir/special-settings.sty"
cd "temp-$outfile"
touch metamath.ind
do_pdflatex "$texfile"
do_pdflatex "$texfile"
bibtex "$texfile"
makeindex "$texfile"
do_pdflatex "$texfile"
do_pdflatex "$texfile"
do_pdflatex "$texfile"
# Print errors not already allowed; return error code if there are any
if ! grep -Ei '(Error|Warning):' "$texfile.log" | grep -vF -f ../allowed-errors
then
echo 'PDF generation successful.'
else
echo "Failed. Here's a list of labels that changed:"
egrep -A2 "label .* changed:" *.log
exit 1 # fail
fi
cp -p "${texfile}.pdf" "../${outfile}.pdf"