-
Notifications
You must be signed in to change notification settings - Fork 7
/
run.sh
111 lines (108 loc) · 3.71 KB
/
run.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
109
110
#!/bin/bash
set -e
#---------------------------------------------------------------------------#
#- LaTeX Automated Compiler -#
#- <By Huangrui Mo> -#
#- <Modified by Hao XIE> -#
#- Copyright (C) Hao XIE <[email protected]> -#
#- This 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. -#
#---------------------------------------------------------------------------#
#---------------------------------------------------------------------------#
#->> Preprocessing
#---------------------------------------------------------------------------#
#-
#-> Get source filename
#-
if [[ "$#" == "1" ]]; then
FileName=`echo *.tex`
elif [[ "$#" == "2" ]]; then
FileName="$2"
else
echo "---------------------------------------------------------------------------"
echo "Usage: "$0" <l|p|x>< |a|b> <filename>"
echo "TeX engine parameters: <l:lualatex>, <p:pdflatex>, <x:xelatex>"
echo "Bib engine parameters: < :none>, <a:bibtex>, <b:biber>"
echo "---------------------------------------------------------------------------"
exit
fi
FileName=${FileName/.tex}
#-
#-> Get tex compiler
#-
if [[ $1 == *'l'* ]]; then
TexCompiler="lualatex"
else
if [[ $1 == *'p'* ]]; then
TexCompiler="pdflatex"
else
TexCompiler="xelatex -shell-escape"
fi
fi
#-
#-> Get bib compiler
#-
if [[ $1 == *'a'* ]]; then
BibCompiler="bibtex"
elif [[ $1 == *'b'* ]]; then
BibCompiler="biber"
else
BibCompiler=""
fi
#-
#-> Set compilation out directory resembling the inclusion hierarchy
#-
Cache="cache"
Contents="contents"
if [[ ! -d $Cache/$Contents ]]; then
mkdir -p $Cache/$Contents
fi
#-
#-> Set LaTeX environmental variables to add subdirs into search path
#-
export TEXINPUTS=".//:$TEXINPUTS" # paths to locate .tex
export BIBINPUTS=".//:$BIBINPUTS" # paths to locate .bib
export BSTINPUTS=".//:$BSTINPUTS" # paths to locate .bst
#---------------------------------------------------------------------------#
#->> Compiling
#---------------------------------------------------------------------------#
#-
#-> Build textual content and auxiliary files
#-
$TexCompiler -output-directory=$Cache $FileName || exit
#-
#-> Build references and links
#-
if [[ -n $BibCompiler ]]; then
#- fix the inclusion path for hierarchical auxiliary files
sed -i -e "s|\@input{|\@input{$Cache/|g" $Cache/"$FileName".aux
#- extract and format bibliography database via auxiliary files
$BibCompiler $Cache/$FileName
#- insert reference indicators into textual content
$TexCompiler -output-directory=$Cache $FileName || exit
#- refine citation references and links
$TexCompiler -output-directory=$Cache $FileName || exit
fi
#---------------------------------------------------------------------------#
#->> Postprocessing
#---------------------------------------------------------------------------#
#-
#-> Set PDF viewer
#-
System_Name=`uname`
if [[ $System_Name == "Linux" ]]; then
PDFviewer="xdg-open"
elif [[ $System_Name == "Darwin" ]]; then
PDFviewer="open"
else
PDFviewer="open"
fi
#-
#-> Open the compiled file
#-
$PDFviewer ./$Cache/"$FileName".pdf || exit
echo "---------------------------------------------------------------------------"
echo "$TexCompiler $BibCompiler "$FileName".tex finished..."
echo "---------------------------------------------------------------------------"