-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildshow.sh
executable file
·69 lines (59 loc) · 2.02 KB
/
buildshow.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
#!/bin/bash
#################################################
# Script to build latex and bibtex files to pdf #
# by Moritz Hoffmann #
#################################################
# Helper function. Moves tmp files to a subdir
clear_dir(){
mv -f *.log *.aux *.bib *.bbl *.bcf *.blg *.lof *.lot *.toc *.out *.glo *.glg *.gls *.glsdefs *.ist *.acn *.acr *.alg *.xml output/
}
# Check for one input parameter specifying file or filename of .tex and .bib file.
if [ $# -eq 0 ]
then
echo "ERROR: Please provide input file or filename as parameter"
exit
fi
# Check for mandatory packages to build pdf.
NEEDED="texlive texlive-lang-german texlive-bibtex-extra texlive-latex-extra texlive-generic-extra biber"
printf "\n"
for pkg in $NEEDED; do
if dpkg --get-selections | grep -q "^$pkg[[:space:]]*install$" >/dev/null; then
echo -e "CHECK: $pkg is already installed"
else
echo -e "ERROR: $pkg not installed. Install it manually in order to continue."
exit 1;
fi
done
printf "\n"
# Check if commands 'pdflatex' and 'bibtex' are available.
# Not need anymore because of check for 'texlive'-related packages above.
#command -v pdflatex >/dev/null 2>&1 || { echo >&2 "pdflatex is not installed. Exiting..."; exit 1; }
#command -v bibtex >/dev/null 2>&1 || { echo >&2 "bibtex is not installed. Exiting..."; exit 1; }
file="$1"
filename="${file%%.*}"
# Clear dir
clear_dir
# Proper order for building latex sources with bibtex extra.
# Show output of last build only.
#{
pdflatex "$filename"
makeglossaries "$filename"
pdflatex "$filename"
makeglossaries "$filename"
#bibtex "$filename"
biber "$filename"
pdflatex "$filename"
#} &> /dev/null
pdflatex "$filename"
printf "\n"
# Move all output files in an output directory. Keep copy of output pdf.
mkdir -p output
# Clear dir
clear_dir
cp "$filename".pdf output/
# Open output pdf with system's default pdf viewer.
# Supress output of default pdf viewer, so latex build logs are visible on the console.
{
gnome-open "$filename.pdf"
} &> /dev/null
exit