-
Notifications
You must be signed in to change notification settings - Fork 2
/
compile.sh
executable file
·45 lines (37 loc) · 1.7 KB
/
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
#!/usr/bin/env bash
# Needs pdflatex
# Tested on Debian 11 WSL with pdflatex through: apt install texlive-latex-extra texlive-lang-european
if [[ $*\ != *--logs\ * ]]; then
echo -e "\e[34mINFO:\e[0m Loggfiler rensas som standard om inte pdfLaTeX stöter på olösliga problem. Använd flaggan --logs för att spara dem."
fi
# See https://stackoverflow.com/questions/15854559/looping-over-directories-in-bash
for path in *; do
# if not a directory, skip
[ -d "${path}" ] || continue
# We remove some files to get a clean compilation.
# (&>/dev/null discards any output message)
rm *.aux &>/dev/null
rm *.pdf-*.png &>/dev/null
# Set working directory for proper output placement
cd "$path"
echo -e "\e[36mBearbetar mapp:\e[0m $path"
# Tell LaTeX to look for .sty-files, etc. in the parent folder
export TEXINPUTS=::$(pwd)/..
# Compiles all .tex-files in the current directory
if [[ ! -z `ls *.tex` ]]; then
for file in *.tex
do
echo -e " - \e[35mBearbetar fil:\e[0m $file"
# First run generates the aux file, then used by the second run (for "sidspalt" generation)
pdflatex -halt-on-error "$file" &>/dev/null || { echo -e "\e[31mFel vid bearbetning av:\e[0m $path/$file. Se loggfilen för mer info." ; exit 1; }
pdflatex -halt-on-error "$file" &>/dev/null || { echo -e "\e[31mFel vid bearbetning av:\e[0m $path/$file. Se loggfilen för mer info." ; exit 1; }
done;
fi
# Optional cleanup (not run on pdflatex error, since the code above will force-exit the script)
if [[ $*\ != *--logs\ * ]]; then
rm *.log &>/dev/null
rm *.aux &>/dev/null
fi
# Go back up
cd ..
done