-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatexBuild_lua.sh
executable file
·96 lines (85 loc) · 2.82 KB
/
latexBuild_lua.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
#!/bin/bash -f
# Initial preparation
LERR="ERROR"
LWRN="WARNING"
CC=$( which lualatex )
BB=$( which bibtex )
EXPAND=$( which latexpand )
ROOT=$( echo $1 | sed "s#\.tex##g" )
REPO=$( echo $3 )
NAME=$( echo $REPO | tr '/' '\n' | tail -n1 )
ZIP=$( which zip )
HERE=$( pwd )
TRASH=/dev/null
FILELIST=files_$ROOT.log
GIT=$( which git )
# user-defined latex compiler
######################### Custom routines #######################################
function sanityCheck(){
if [[ -z $CC ]]; then echo $LERR: Latex compiler not found.; exit 1; else echo "$CC found."; fi
if [[ -z $BB ]]; then echo $LERR: Bibtex not found.; exit 1; else echo "$BB found."; fi
if [[ -z $EXPAND ]]; then echo $LERR: Latexpand not found.; exit 1; else echo "$EXPAND found."; fi
if [[ -z $ZIP ]]; then echo $LERR: zip not found.; exit 1; else echo "$ZIP found."; fi
if [[ -z $TRASH ]]; then echo $LERR: /dev/null not found.; exit 1; else echo "$TRASH found."; fi
if [[ -z $GIT ]]; then echo $LERR: git not found.; exit 1; else echo "$GIT found."; fi
}
function switchTextToBibtex() {
# switch back from using .bbl file to using bibtex file in case
# this is being done.
echo "Hello world"
sed -i "s/^%\\\\bib/\\\\bib/g" $ROOT.tex
# sed -i "s/%^\\\\bibliography{/\\\\bibliography{/g" $ROOT.tex
sed -i "s/^\\\\bibsubimport/%\\\\bibsubimport/g" $ROOT.tex
}
function compileSequence() {
# compile assuming .bib file is being used
$CC $ROOT.tex
$BB $ROOT.aux
$CC $ROOT.tex
$CC $ROOT.tex |\
awk '/ \*File List\*/{flag=1;next}/\*\*\*\*\*\*\*\*\*\*\*/{flag=0}flag {print $1; }' |\
xargs -I '{}' bash -c "ls {} 2>$TRASH" |\
grep -v "\.tex$\|\.out$\|\.aux$" > $FILELIST
}
function switchBackToPureLatex() {
# modify main file to use generated .bbl file
# Make sure there's a commented line that inputs the .bbl file.
sed -i "s/^\\\\bib/%&/" $ROOT.tex
sed -i "s/^\\\\bib/%&/" $ROOT.tex
sed -i "s/^%\\\\bibsubimport/\\\\bibsubimport/" $ROOT.tex
}
function updateUploadDirectory() {
[[ -d "./upload_$ROOT" ]] && rm ./upload_$ROOT/*.*
[[ -e "./upload_$ROOT.zip" ]] && rm ./upload_$ROOT.zip
bash -c "\
$EXPAND $ROOT.tex > upload_$ROOT/$ROOT.tex 2>$TRASH && \
cat $FILELIST | cpio -pdm upload_$ROOT/ \
"
$ZIP -r upload_$ROOT.zip upload_$ROOT/ -x upload_$ROOT/.git*
}
function createUploadPackage() {
if [[ -d "./upload_$ROOT" ]]; then
updateUploadDirectory
else
if [[ -z "$REPO" ]]; then
echo $LWRN: remote git repository not provided.
mkdir upload_$ROOT
else
$GIT clone $REPO
mv $NAME upload_$ROOT
fi
updateUploadDirectory
fi
}
###############################################################################
grep "^\\\\listfiles$" $ROOT.tex
if [[ $? -eq 0 ]]; then
sanityCheck
switchTextToBibtex
compileSequence
switchBackToPureLatex
$CC $ROOT.tex
createUploadPackage
else
echo $LERR: $ROOT.tex does not contain command \\listfiles at the top.
fi