forked from mohuangrui/ucasthesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artratex.sh
110 lines (107 loc) · 3.58 KB
/
artratex.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
#!/bin/bash
set -e
#---------------------------------------------------------------------------#
#- LaTeX Automated Compiler -#
#- <By Huangrui Mo> -#
#- Copyright (C) Huangrui Mo <huangrui.mo@gmail.com> -#
#- 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"
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
#-
Tmp="Tmp"
Tex="Tex"
if [[ ! -d $Tmp/$Tex ]]; then
mkdir -p $Tmp/$Tex
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=$Tmp $FileName || exit
#-
#-> Build references and links
#-
if [[ -n $BibCompiler ]]; then
#- fix the inclusion path for hierarchical auxiliary files
sed -i -e "s|\@input{|\@input{$Tmp/|g" $Tmp/"$FileName".aux
#- extract and format bibliography database via auxiliary files
$BibCompiler $Tmp/$FileName
#- insert reference indicators into textual content
$TexCompiler -output-directory=$Tmp $FileName || exit
#- refine citation references and links
$TexCompiler -output-directory=$Tmp $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 ./$Tmp/"$FileName".pdf || exit
echo "---------------------------------------------------------------------------"
echo "$TexCompiler $BibCompiler "$FileName".tex finished..."
echo "---------------------------------------------------------------------------"