-
Notifications
You must be signed in to change notification settings - Fork 0
/
changes.sh
executable file
·295 lines (233 loc) · 7.92 KB
/
changes.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/bash
function sort_latex {
current_dir=$(pwd)
cd /home/HOME/Documents/thesis_changes
# rescue git folder from flattening
mv -f .git ../
# rename vimos and muse figures as they have the same name
for instr in vimos muse
do
for f in $( ls */$instr/* )
do
mv $f $( echo $f | sed 's/\//_/g' | sed 's/_/\//' )
done
rm -r */$instr
done
# flatten
find . -mindepth 2 -type f -exec mv -i -f '{}' . ';'
mv -f ../.git ./
# remove references to folders
for f in $( ls *.tex )
do
sed 's/introduction\///g' $f | sed 's/chapter2\///g' \
| sed 's/chapter4\///g' | sed 's/chapter5\///g' \
| sed 's/conclusions\///g' | sed 's/appendix\/appendix2\///g' \
| sed 's/vimos\//vimos_/g' | sed 's/muse\//muse_/g' \
| sed 's/acknowledgements\///g' | sed 's/abstract\///g'> temp
mv temp $f
done
# flatten latex documents
for f in abstract origionality acknowledgements introduction chapter2 \
chapter4 chapter5 conclusions appendix2
do
sed -i "s/\\include{"$f"}/$(sed -e 's/[\&/]/\\&/g' \
-e 's/$/\\n/' $f.tex | tr -d '\n')/" thesis.tex
rm $f.*
done
# Removing unnecessary double \ from above sed command
sed -i 's/\\\\b/\\b/g' thesis.tex
sed -i 's/\\\\c/\\c/g' thesis.tex
# remove uneeded files
rm -r abstract
rm -r acknowledgements
rm -r introduction
rm -r chapter2
rm -r chapter4
rm -r chapter5
rm -r conclusions
rm -r appendix*
rm *.aux
rm *.bbl
rm *.blg
rm *.dvi
rm *.lof
rm *.log
rm *.out
rm *.pdf
rm *.toc
rm *.sh
rm *.py
cd $current_dir
}
function update {
echo "Updating copies of old and most recent repos"
current_dir=$(pwd)
cd /home/HOME/Documents/thesis
cp -r * /home/HOME/Documents/thesis_changes_new/
git stash
git checkout 44c3183a0115766126279a6a011dd4c437e8d7ea
cp -r * /home/HOME/Documents/thesis_changes_old/
git checkout master
git stash pop
cd $current_dir
}
function run_all_plots {
echo 'This function needs to called from Ubuntu on Windows utility'
current_dir=$(pwd)
cd /home/joshwarren/Documents/thesis
cd chapter2
python produce_plots2.py
cd ../chapter4
python produce_plots2.py
python plot_resolved_lambda_R.py
cd ../chapter5
python produce_plots2.py
cd /home/joshwarren/MUSE_project/analysis
python compare_atlas3d.py thesis
python BPT_muse.py
cd /home/joshwarren/VIMOS_project/analysis
python BPT.py
cd $current_dir
}
function correct_latex {
echo "Correcting the LaTeX produced by latexdiff"
changes_file=/home/HOME/Documents/thesis_changes/changes.tex
dos2unix $changes_file
cat $changes_file | tr '\r' '\n' > tmp
mv tmp $changes_file
# remove indents
cat $changes_file | sed "s/^[ \t]*//g" > tmp
mv tmp $changes_file
# Remove all comments (begining of line first (remove preceding and
# following newline), then inline)
# cat $changes_file | tr '\n' '~' | sed 's/~mxc/qwerty/g' \
# | sed -r 's/(\b|[^\\])\%[^~]*~/\1/g' | sed 's/~\%[^~]*~//g' \
# | sed -r 's/(\b|[^\\])\%[^~]*~/\1/g' |tr '~' '\n' \
# | sed 's/qwerty/~mxc/g' > tmp
# mv tmp $changes_file
cat $changes_file | tr '\n' '~' | sed 's/~mxc/qwerty/g' \
| sed -r 's/(\b|[^\\])\%[^~]*/\1/g' | tr '~' '\n' \
| sed 's/qwerty/~mxc/g' > tmp
mv tmp $changes_file
# Max of 1 empty line
cat $changes_file | tr '\n' '~' | sed 's/~~~*/~~/g' | sed 's/~mxc/qwerty/g' \
| tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
mv tmp $changes_file
# Remove uncessary newlines
cat $changes_file | tr '\n' '~' | sed 's/~mxc/qwerty/g' \
| sed 's/\({[^}^~]*\)~~*/\1/g' | sed 's/~~*}/}/g' | tr '~' '\n' \
| sed 's/qwerty/~mxc/g' > tmp
mv tmp $changes_file
cat $changes_file | tr '\n' '~' | sed 's/\. *~*\}/\.\}/g' | \
sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
mv tmp $changes_file
cat $changes_file | tr '\n' '~' | sed 's/~*\}\\DIF/\}\\DIF/g' | \
sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
mv tmp $changes_file
cat $changes_file | tr '\n' '~' | sed 's/mbox{~*/mbox{/g' | \
sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
mv tmp $changes_file
cat $changes_file | tr '\n' '~' | sed 's/hspace{0}~*/hspace{0pt} /g' | \
sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
mv tmp $changes_file
cat $changes_file | tr '\n' '~' | sed 's/}~*\\DIFaddend/}\\DIFaddend/g' | \
sed 's/}~*\\DIFdelend/}\\DIFdelend/g' | \
sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
mv tmp $changes_file
# Re-add necessary newlines
cat $changes_file | tr '\n' '~' | sed 's/end *\\end/end~\\end/g' | \
sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
mv tmp $changes_file
cat $changes_file | tr '\n' '~' | sed 's/ *\\subs/~~\\subs/g' | \
sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
mv tmp $changes_file
# Correcting error in old version
sed -i 's/Con topoulos1956/Contopoulos1956/g' $changes_file
# Remove empty del and add enviroments
cat $changes_file | tr '\n' '~' | sed 's/\\DIFdelbegin *~* *\\DIFdelend *//g' \
| sed 's/\\DIFaddbegin *~* *\\DIFaddend *//g' \
| sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
mv tmp $changes_file
# Correct output of latex diff - change newline to ~
# cat $changes_file | tr '\n' '~' | sed 's/\. *~*\}/\.\}/g' \
# | sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
# mv tmp $changes_file
# cat $changes_file | tr '\n' '~' | sed 's/\.~\%.*~~\}/\.\}/g' \
# | sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
# mv tmp $changes_file
# cat $changes_file | tr '\n' '~' | sed 's/\}~*\\DIF/\}\\DIF/g' | \
# sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
# mv tmp $changes_file
# To include Windows style newlines
# cat $changes_file | sed -r ':a;N;$!ba;s/\.\r\n\r\}/\.\}/g' > tmp
# mv tmp $changes_file
# cat $changes_file | sed -r ':a;N;$!ba;s/\. \r\n\r\}/\.\}/g' > tmp
# mv tmp $changes_file
# cat $changes_file | sed -r ':a;N;$!ba;s/\.\n\%.*\r\n\r\}/\.\}/g' > tmp
# mv tmp $changes_file
# cat $changes_file | tr '\n' '~' | sed 's/~\}/\}/g' | sed 's/\}~[^~]/\}/' \
# | sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
# mv tmp $changes_file
# cat $changes_file | sed ':a;N;$!ba;s/\.\r\n\r\}/\.\}/g' > tmp
# mv tmp $changes_file
# cat $changes_file | tr '\n' '~' | sed 's/{~*/\{/g' \
# | sed 's/~mxc/qwerty/g' | tr '\~' '\n' | sed 's/qwerty/~mxc/g' > tmp
# | sed 's/\}~\\DIF/\}\\DIF/g'
# | sed 's/~*\}/\}/g'
# diff tmp $changes_file
# mv tmp $changes_file
}
function thesify {
echo "Producing PDF document changes.pdf"
current_dir=$(pwd)
cd /home/HOME/Documents/thesis_changes
pdflatex -interaction=batchmode changes.tex
bibtex changes
pdflatex -interaction=batchmode changes.tex
pdflatex -interaction=batchmode changes.tex
if [ `whoami` = 'warrenj' ]
then
open changes.pdf
else
cygstart changes.pdf # opens thesis.pdf with cygwin
fi
cd $current_dir
}
function create_changes {
echo "Running latexdiff utility"
current_dir=$(pwd)
cd /home/HOME/Documents/thesis_changes
rm -rf /home/HOME/Documents/thesis_changes/*
## --------------------=========== Origional ==========-------------- ##
cp -r /home/HOME/Documents/thesis_changes_old/* \
/home/HOME/Documents/thesis_changes/
sort_latex
mv thesis.tex thesis.old
## --------------------=========== Changed ==========-------------- ##
cp -r /home/HOME/Documents/thesis_changes_new/* \
/home/HOME/Documents/thesis_changes/
sort_latex
mv thesis.tex thesis.new
## --------------------=========== Comparison ==========-------------- ##
cp /home/HOME/Documents/thesis/refs.bib /home/HOME/Documents/thesis_changes/
latexdiff thesis.old thesis.new > changes.tex
cd $current_dir
}
function run {
update
create_changes
correct_latex
thesify
}
# Taken from https://stackoverflow.com/questions/8818119/
# how-can-i-run-a-function-from-a-script-in-command-line
# Check if the function exists (bash specific)
if declare -f "$1" > /dev/null
then
# call arguments verbatim
"$@"
else
# Show a helpful error
echo "'$1' is not a known function name" >&2
exit 1
fi