-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_tex.sh
executable file
·108 lines (95 loc) · 3.63 KB
/
compile_tex.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
#!/bin/bash
#
# Copyright © 2019, 2020 Stephan Hagel (stephan.hagel@physik.uni-giessen.de)
#
# This file is part of my Master of Science project.
#
# This project is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This project is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# compile_tex.sh - Properly compiles .tex files
#
# This script is used to compile .tex files to .pdf files using the lualatex compiler.
# It includes all the neccessary commands to also automatically do the bibtex and nomcl compilation.
# This compiles the file tex/PROJECT/main.tex to a pdf and saves it as tex/PROJECT/output/PROJECT.pdf
# In order for it to find the correct directories, it has to be run directly from the src/scripts/ directory.
# It also automatically cleans up other files generated by the compiler, other than the PROJECT.pdf file.
#
# Usage:
# ./compile_tex.sh [OPTIONS]
#
#
# Available options:
# -k, --keep-all Forces the script to not clean up after itself, leaving files for debugging purposes
# -v, --verbose Prints more information about the current state of compiling.
# -h, --help Show brief help
#
KEEP_ALL=false
PRINT_VERBOSE=false
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "compile_tex.sh - Properly compiles .tex files"
echo ""
echo "This script is used to compile .tex files to .pdf files using the lualatex compiler."
echo "This compiles the file main.tex to a pdf and saves it as output/PROJECT.pdf"
echo "In order for it to find the correct directories, it has to be run directly from the projects root directory."
echo "It also automatically cleans up other files generated by the compiler, other than the PROJECT.pdf file."
echo ""
echo "Usage:"
echo "./compile_tex.sh [OPTIONS]"
echo ""
echo ""
echo "Available options:"
echo " -k, --keep-all Forces the script to not clean up after itself, leaving files for debugging purposes"
echo " -v, --verbose Prints more information about the current state of compiling."
echo " -h, --help Show brief help"
exit 0
;;
-k|--keep-all)
KEEP_ALL=true
shift
;;
-v|--verbose)
PRINT_VERBOSE=true
shift
;;
*)
break
;;
esac
done
DIRECTORY_PATH="."
MAIN_PATH="./main.tex"
if [ ! -d "$DIRECTORY_PATH" ]; then
echo "Error: The directory $DIRECTORY_PATH does not exist. Aborting."
exit 2
fi
if [ ! -f "$MAIN_PATH" ]; then
echo "Error: The file $MAIN_PATH does not exist. Aborting."
exit 3
fi
mkdir -p "${DIRECTORY_PATH}"/output/
cd "${DIRECTORY_PATH}" || exit
if [ ${PRINT_VERBOSE} = true ]; then
lualatex -shell-escape --output-directory=output/ main.tex
else
echo "Compiling..."
lualatex -shell-escape --output-directory=output/ main.tex > /dev/null
fi
echo "Done!"
cd output || exit
mv main.pdf Songbook.pdf
if [ ${KEEP_ALL} = false ]; then
echo "Cleaning up..."
rm main.* ./*.sxd
fi