-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_pdflatex
executable file
·82 lines (65 loc) · 1.94 KB
/
_pdflatex
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
#!/bin/bash
LOG_DIR=".log"
# export PDF_COMPILER="lualatex"
[ -z "$PDF_COMPILER" ] && PDF_COMPILER="pdflatex"
SINK=''
# unset PDF_FILENAME
CLEAN=false
build() {
TEXFILE="$1"
job_name="$(echo "$TEXFILE" | sed 's,\.[^.]*,,')"
# job_name="${texfile%.tex}"
echo $PDF_COMPILER
# Option: -interaction=nonstopmode
mkdir -p "$LOG_DIR"
case "$PDF_COMPILER" in
lualatex) lualatex -output-directory="$LOG_DIR" \
"$TEXFILE" $SINK || return;;
pdflatex) pdflatex -output-directory="$LOG_DIR" \
"$TEXFILE" $SINK || return;;
esac;
[ -z "$PDF_FILENAME" ] && PDF_FILENAME="$job_name.pdf"
[ -f "$LOG_DIR/$job_name.pdf" ] && \
mv "$LOG_DIR/$job_name.pdf" "$PDF_FILENAME"
}
main () {
mkdir -p "$LOG_DIR"
echo $1
$CLEAN && {
rm -r "$LOG_DIR"
exit 0;
}
[ -z "$1" ] && {
echo "Not enough arguments! Expects $0 'texfile'"
exit 1
}
# $WATCH && {
# Check: https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes#181543
# watchexec -e md make build "$1";
# exit 0;
# }
build "$1"
}
_usage() {
printf "Usage: $0 [-sc] <texfile> \n\t OPTIONS:\n"
printf "\t\t : \topens the pdf file with 'gio open'.\n"
printf "\t\t -s, --silent: \tcompiles with minimal output.\n"
printf "\t\t -c, --clean: \tremoves compile files.\n"
printf "\t\t -o, --output: \toutput filename\n"
# printf "\t\t watch: \trecomplies when file is changed.\n"
}
# Read arguments
POSITIONAL=()
while [[ $# -gt 0 ]]; do
case $1 in
--print|-p) PRINT=true ;;
-h|--help) _usage; exit 2 ;;
-c|--clean) CLEAN=true ;;
-s|--silent) SINK="> /dev/null" ;;
-o|--output) PDF_FILENAME="$2"; shift ;;
--compiler) PDF_COMPILER="$2"; shift ;;
-*) echo "Invalid option '$1'" > /dev/stderr; exit 1 ;;
*) POSITIONAL+=("$1") ;;
esac; shift;
done
main "${POSITIONAL[@]}"