-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathmake_main.sh
executable file
·208 lines (161 loc) · 3.62 KB
/
make_main.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash
FIRST_CHAPTER=1
LAST_CHAPTER=16
preamble="\documentclass[11pt]{book}
\input{style/preamble_math}
\input{style/preamble_format}"
title="\title{Unsupervised Learning}
\author{Nakul Verma}
\date{}"
REGEX_RANGE='([0-9]+)-([0-9]+)'
for ((i=$FIRST_CHAPTER;i<=$LAST_CHAPTER;i++)); do
CHAPTERS[$i]=0
done
echo "Warning: this operation will overwrite main.tex"
## Get chapters to generate
read -p "Enter chapter numbers to generate: " input
for i in ${input[@]}
do
if [[ $i =~ $REGEX_RANGE ]]; then
for ((j=${BASH_REMATCH[1]};j<=${BASH_REMATCH[2]};j++)); do
if [[ $j -le $LAST_CHAPTER ]] && [[ $j -ge $FIRST_CHAPTER ]]; then
CHAPTERS[$j]=1
else
echo "Chapter $j does not exist."
fi
done
else
if [[ $i -le $LAST_CHAPTER ]] && [[ $i -ge $FIRST_CHAPTER ]]; then
CHAPTERS[$i]=1
else
echo "Chapter $i does not exist."
fi
fi
done
## Check if want to generate the whole book
all_zero=1
for ((i=$FIRST_CHAPTER;i<=$LAST_CHAPTER;i++))
do
if [[ CHAPTERS[$i] -eq 1 ]]; then
all_zero=0
fi
done
if [[ $all_zero -eq 1 ]]; then
for ((i=$FIRST_CHAPTER;i<=$LAST_CHAPTER;i++))
do
CHAPTERS[$i]=1
done
fi
all_one=1
for ((i=$FIRST_CHAPTER;i<=$LAST_CHAPTER;i++))
do
if [[ CHAPTERS[$i] -eq 0 ]]; then
all_one=0
fi
done
## Include parts?
read -p "Include parts? [yN]: " parts
case "$parts" in
y|yes|YES|Yes|Y)
include_part=1
;;
*)
include_part=0
;;
esac
## Build main file
### preamble
echo "$preamble" > main.tex
echo "" >> main.tex
echo "" >> main.tex
### bibresource
for ((i=$FIRST_CHAPTER;i<=$LAST_CHAPTER;i++))
do
if [[ CHAPTERS[$i] -eq 1 ]]; then
echo "\addbibresource{chapter_$i/references}" >> main.tex
fi
done
echo "" >> main.tex
echo "" >> main.tex
### title
echo "$title" >> main.tex
echo "" >> main.tex
echo "" >> main.tex
### document
echo "\begin{document}" >> main.tex
if [[ include_part -eq 1 || all_one -eq 1 ]]; then
echo "\maketitle" >> main.tex
echo "\tableofcontents" >> main.tex
echo "" >> main.tex
echo "" >> main.tex
fi
### Preface
if [[ include_part -eq 1 ]]; then
echo "\include{preface/preface}" >> main.tex
echo "" >> main.tex
fi
### Part 1
if [[ include_part -eq 1 ]]; then
echo "\part{Clustering}" >> main.tex
echo "" >> main.tex
fi
for ((i=1;i<=4;i++))
do
if [[ CHAPTERS[$i] -eq 1 ]]; then
echo "\include{chapter_$i/chapter_$i}" >> main.tex
fi
done
echo "" >> main.tex
echo "" >> main.tex
### Part 2
if [[ include_part -eq 1 ]]; then
echo "\part{Dimensionality Reduction}" >> main.tex
echo "" >> main.tex
fi
for ((i=5;i<=7;i++))
do
if [[ CHAPTERS[$i] -eq 1 ]]; then
echo "\include{chapter_$i/chapter_$i}" >> main.tex
fi
done
echo "" >> main.tex
echo "" >> main.tex
### Part 3
if [[ include_part -eq 1 ]]; then
echo "\part{Density Estimation}" >> main.tex
echo "" >> main.tex
fi
for ((i=8;i<=10;i++))
do
if [[ CHAPTERS[$i] -eq 1 ]]; then
echo "\include{chapter_$i/chapter_$i}" >> main.tex
fi
done
echo "" >> main.tex
echo "" >> main.tex
### Part 4
if [[ include_part -eq 1 ]]; then
echo "\part{Ad Hoc Techniques}" >> main.tex
echo "" >> main.tex
fi
for ((i=11;i<=$LAST_CHAPTER;i++))
do
if [[ CHAPTERS[$i] -eq 1 ]]; then
echo "\include{chapter_$i/chapter_$i}" >> main.tex
fi
done
echo "" >> main.tex
echo "" >> main.tex
### Appendix
if [[ include_part -eq 1 ]]; then
echo "\part*{Appendices}" >> main.tex
echo "\include{appendix}" >> main.tex
echo "" >> main.tex
fi
### Index
if [[ include_part -eq 1 ]]; then
echo "\printindex" >> main.tex
echo "" >> main.tex
fi
echo "\end{document}" >> main.tex
echo "main file exported to ./main.tex"