-
Notifications
You must be signed in to change notification settings - Fork 6
/
formatLatex.sh
executable file
·41 lines (33 loc) · 1.35 KB
/
formatLatex.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
# NB: Backslash in sed is represented by THREE backslashes
cd fdm-devito-notebooks
# Array containing custom DocOnce commands
DOCONCE=("\\\tp" "\\\half" "\\\Real" "\\\normalvec")
# Array containing pure LaTeX commands, where
# PURE_LATEX[i] is the pure LaTeX version of DOCONCE[i]
PURE_LATEX=("\\\thinspace ." "\\\frac{1}{2}" "\\\mathbb{R}" "\\\boldsymbol{n}")
# Auxilliary errors as a result of the above formatting and their fixes
AUX_ERRORS=("outhinspace .ut" "athinspace .lot" "htthinspace .")
AUX_FIXES=("output" "atplot" "http")
# Chapter directory names
CHAPTERS=("01_vib" "02_wave" "03_diffu" "04_advec" "05_nonlin" "A_formulas" "B_trunc" "C_softeng2")
# If arrays are different lengths, script is not executed and throws error
if [ ${#DOCONCE[@]} -ne ${#PURE_LATEX[@]} ]; then
echo "ERROR: DocOnce and pure LaTeX arrays are different lengths"
exit 1
fi
for chapter in "${CHAPTERS[@]}"; do
cd $chapter
# Only replace text in Jupyter notebooks (.ipynb files)
for notebook in *.ipynb; do
for index in ${!DOCONCE[@]}; do
sed -i -e "s/${DOCONCE[index]}/${PURE_LATEX[index]}/g" $notebook
done
for index in ${!AUX_ERRORS[@]}; do
sed -i -e "s/${AUX_ERRORS[index]}/${AUX_FIXES[index]}/g" $notebook
done
done
# Remove extra files generated
rm -rf *.ipynb-e
cd ..
done
echo "Successfully formatted .ipynb files in ${CHAPTERS[@]}"