forked from mohuangrui/ucasthesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compile.sh
75 lines (75 loc) · 3.52 KB
/
Compile.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
#* *************************************************************************
#* bash scripts for compile latex
#* *************************************************************************
#! /bin/bash
#* *************************************************************************
#* pre information
#* *************************************************************************
if [[ "$#" == "1" ]];then
File_Name=`echo *.tex`
elif [[ "$#" == "2" ]];then
File_Name="$2"
else
echo "*************************************************************************"
echo "Usage: "$0" Compiler(specify \"x\" or \"p\") File_Name(if omitted, auto search)"
echo "Compiler \"x\" for \"xelatex\" and \"p\" for \"pdflatex\" (specify without quotes)"
echo "if compile failed, use \"X\" to terminate the terminal..."
echo "*************************************************************************"
exit
fi
#* *************************************************************************
#* get the file name to compile
#* *************************************************************************
File_Name=${File_Name/.tex}
#* *************************************************************************
#* get the compiler
#* *************************************************************************
if [[ $1 == 'p' ]];then
CompileName="pdflatex"
elif [[ $1 == 'x' ]];then
CompileName="xelatex"
else
echo "*************************************************************************"
echo "wrong compiler parameter, use \"pdflatex\" as current compiler"
CompileName="pdflatex"
echo "*************************************************************************"
fi
#* *************************************************************************
#* temperary directory
#* *************************************************************************
#* set the temp directory name
Tmp="Tmp"
if [[ ! -d $Tmp ]];then
mkdir -p $Tmp
fi
#* *************************************************************************
#* include subdirs to compile path
#* *************************************************************************
export TEXINPUTS=".//:$TEXINPUTS"
export BIBINPUTS=".//:$BIBINPUTS"
export BSTINPUTS=".//:$BSTINPUTS"
#* *************************************************************************
#* compile target file
#* *************************************************************************
$CompileName -output-directory=$Tmp $File_Name || exit
#* *************************************************************************
#* if use bibtex, need following commands
#* *************************************************************************
bibtex ./$Tmp/$File_Name
$CompileName -output-directory=$Tmp $File_Name || exit
$CompileName -output-directory=$Tmp $File_Name || exit
#* *************************************************************************
#* open the generated pdf file
#* *************************************************************************
System_Name=`uname`
if [[ $System_Name == "Linux" ]]; then
PDFviewer="gnome-open"
elif [[ $System_Name == "Darwin" ]]; then
PDFviewer="open"
else
PDFviewer="open"
fi
$PDFviewer ./$Tmp/"$File_Name".pdf || exit
echo "*************************************************************************"
echo "use $CompileName Compile "$File_Name".tex finished!"
echo "*************************************************************************"