-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.bash
More file actions
62 lines (44 loc) · 1.55 KB
/
build.bash
File metadata and controls
62 lines (44 loc) · 1.55 KB
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
#!/bin/bash
# any arguments provided?
if [ -z "$1" ]; then
echo "Usage failed: no arguments provided"
exit 1
fi
# for all arguments (.tex files) given
for arg in "$@"; do
# is the provided argument a .tex file?
if [[ "$arg" != *.tex ]]; then
echo "Usage failed: provided file must be a .tex file"
exit 1
fi
# get top level dir of git repo
repo_root=$(git rev-parse --show-toplevel 2>/dev/null)
# are we in a git repo?
if [ -z "$repo_root" ]; then
echo "Usage failed: not in git repo"
exit 1
fi
# get current dir relative to git root
curr_path=$(pwd | sed "s|$repo_root/||")
# change dir to git root or exit if fail
cd "$repo_root" || exit 1
# find path for .tex file
file="$arg"
fname=$(basename "$file" .tex)
latex_path="$curr_path/$file"
latex_path="${latex_path%/$fname.tex}"
latex_path="${latex_path#$(pwd)/}"
pdf_path="pdf/${latex_path#latex/}"
# compile .tex --> .pdf
# echo "Running pdflatex on: $latex_path/$fname.tex"
pdflatex -interaction=nonstopmode $latex_path/$fname.tex > /dev/null
# latexmk -pdf -interaction=nonstopmode $latex_path/$fname.tex > /dev/null
# pdflatex -interaction=nonstopmode $latex_path/$fname.tex
# delete extra .aux .log .out
# $(rm $fname.aux $fname.log $fname.out)
$(rm $fname.aux $fname.log)
# create necessary directories if they do not exist in latex
$(mkdir -p $pdf_path)
# move compiled .pdf file to pdf dir via absolute path
$(mv "$fname.pdf" "$pdf_path")
done