-
Notifications
You must be signed in to change notification settings - Fork 0
/
latex-compile.sh
executable file
·77 lines (63 loc) · 1.67 KB
/
latex-compile.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
#!/bin/bash
# Compile a LaTeX document and report warning and errors.
FileName=$(echo $1 | cut -f 1 -d .) # this should work on Linux and Mac OS X
echo "Cleaning"
"$(dirname $(realpath $0))"/latex-clean.sh
if [ "${FileName}" ] || { echo "Please provide path to your LaTeX source file."; exit 1; }
if [ -f "${FileName}.tex" ] || { echo "There is no file ${FileName}.tex"; exit 1; }
echo "Processing file ${FileName}.tex"
# run pdflatex, $1 = file.tex, $2 = pass_number
function run_pdflatex {
command="pdflatex -interaction=nonstopmode --shell-escape"
string="pdflatex pass $2"
logfile="stdouterr-pdflatex$2.txt"
if $command $1 > $logfile 2>&1; then
echo "$string OK"
else
echo "$string failed"
echo "LaTeX Errors:"
grep "! " $logfile
exit 1
fi
return 0
}
# run bibtex, $1 = file.aux
function run_bibtex {
command="bibtex"
string="bibtex"
logfile="stdouterr-bibtex.txt"
if $command $1 > $logfile 2>&1; then
echo "$string OK"
else
echo "$string failed"
echo "BibTeX Errors:"
grep "error" $logfile
exit 1
fi
echo "BibTeX warnings:"
grep "Warning" $logfile
echo ""
return 0
}
run_pdflatex $FileName.tex 1
[ "$2" == "b" ] && echo "Skipping bibtex" || run_bibtex $FileName.aux
run_pdflatex $FileName.tex 2
run_pdflatex $FileName.tex 3
run_pdflatex $FileName.tex 4
echo "LaTeX warnings:"
grep "LaTeX Warning" $logfile
grep "bad" $logfile
echo ""
echo "Overfull warnings:"
grep -A 1 "too wide" $logfile
echo ""
echo "Package warnings:"
grep "Warning" $logfile | grep "Package"
echo ""
echo "Font warnings:"
grep -A 1 "LaTeX Font Warning:" $logfile
echo ""
echo "Cleaning"
"$(dirname $(realpath $0))"/latex-clean.sh
echo "Done!"
exit 0