-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkbook.sh
executable file
·147 lines (147 loc) · 4.61 KB
/
mkbook.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
#!/bin/bash
#This application creates a folder optimized for writing books with subfiles with my template. For now you'd need to set up manually the directory where the app takes the templates, maybe in the future I'll make an automatic setup of that but for now it is what it is
bookcreate() {
if [ ! -d "$name" ]; then
mkdir -p "$(pwd)/$name/chapters"
mkdir "$(pwd)/$name/images"
mkdir "$(pwd)/$name/resources"
cp "$HOME"/templates/latex/base/base.tex "$(pwd)"/"$name"/"$name".tex
cp "$HOME"/templates/latex/base/newchapter.tex "$(pwd)"/"$name"/chapters/newchapter.tex
sed -i 's/..\/<++>/..\/'"$name"'/g' "$(pwd)"/"$name"/chapters/newchapter.tex
else
echo "there exists already a book with that name"
exit
fi
}
maketitle () {
mkdir $(pwd)/$name/title
if [ -n "$lang" ]; then
if [ "$lang" = "en" ]; then
cp "$HOME"/templates/latex/title/en/title.tex "$(pwd)"/"$name"/title/title.tex
cp "$HOME"/templates/latex/title/en/frontispice.tex "$(pwd)"/"$name"/title/frontispice.tex
sed -i 's/..\/<++>\/../'"$name"'.tex/g' "$(pwd)"/"$name"/title/title.tex
sed -i 's/..\/<++>\/../'"$name"'.tex/g' "$(pwd)"/"$name"/title/frontispice.tex
elif [ "$lang" = "it" ]; then
cp "$HOME"/templates/latex/title/it/title.tex "$(pwd)"/"$name"/title/title.tex
cp "$HOME"/templates/latex/title/it/frontispice.tex "$(pwd)"/"$name"/title/frontispice.tex
sed -i 's/..\/<++>/..\/'"$name"'.tex/g' "$(pwd)"/"$name"/title/title.tex
sed -i 's/..\/<++>/..\/'"$name"'.tex/g' "$(pwd)"/"$name"/title/frontispice.tex
else
echo "the language inserted is not supported, using the english version"
cp "$HOME"/templates/latex/title/en/title.tex "$(pwd)"/"$name"/title/title.tex
cp "$HOME"/templates/latex/title/en/frontispice.tex "$(pwd)"/"$name"/title/frontispice.tex
sed -i 's/..\/<++>/..\/'"$name"'.tex/g' "$(pwd)"/"$name"/title/title.tex
sed -i 's/..\/<++>/..\/'"$name"'.tex/g' "$(pwd)"/"$name"/title/frontispice.tex
fi
else
echo "language not selected, using the english version"
cp "$HOME"/templates/latex/title/en/title.tex "$(pwd)"/"$2"/title/title.tex
cp "$HOME"/templates/latex/title/en/frontispice.tex "$(pwd)"/"$name"/title/frontispice.tex
sed -i 's/..\/<++>/..\/'"$name"'.tex/g' "$(pwd)"/"$name"/title/title.tex
sed -i 's/..\/<++>/..\/'"$name"'.tex/g' "$(pwd)"/"$name"/title/frontispice.tex
fi
}
titlecomplete () {
sed -i "s/\\Huge\ /\\Huge\ $name/g" "$(pwd)"/"$name"/title/title.tex
sed -i "s/\\Huge\ /\\Huge\ $name/g" "$(pwd)"/"$name"/title/frontispice.tex
if [ "$lang" = "it" ]; then
sed -i "s/Appunti\ di/Appunti di\ $name/g" "$(pwd)"/"$name"/title/title.tex
sed -i "s/Versione\ /Versione\ $ver/g" "$(pwd)"/"$name"/title/title.tex
sed -i "s/Appunti\ di/Appunti di\ $name/g" "$(pwd)"/"$name"/title/frontispice.tex
sed -i "s/Versione\ /Versione\ $ver/g" "$(pwd)"/"$name"/title/frontispice.tex
else
sed -i "s/Notes\ on/Notes on\ $name/g" "$(pwd)"/"$name"/title/title.tex
sed -i "s/Version\ /Version\ $ver/g" "$(pwd)"/"$name"/title/title.tex
sed -i "s/Notes\ on/Notes on\ $name/g" "$(pwd)"/"$name"/title/frontispice.tex
sed -i "s/Version\ /Version\ $ver/g" "$(pwd)"/"$name"/title/frontispice.tex
fi
}
titlecolor() {
if [ "$opt" = 1 ]; then
sed -i 's/\%\\usepackage{sapienza}/\\usepackage{sapienza}/g' "$(pwd)"/"$name"/"$name".tex
#rm "$(pwd)"/"$name"/"$name".tex
#cp "$HOME"/templates/latex/base/sapienza.tex "$(pwd)"/"$name"/"$name".tex
fi
}
helpf() {
echo "mkbook, LaTeX book folder creator from template"
echo "USAGE AND ARGUMENTS: "
echo " mkbook -n NAME Create folder and .tex file with NAME"
echo " -l lang Use specified language (it/en) supported. Uses en if not specified or not supported"
echo " -v vers Add a version value of the book"
echo " -h Prints this help section"
echo " --sapienza Optional argument for changing the color of equations and the titlepage to the official color of Sapienza Università"
}
if [[ -n $1 ]]; then
case $1 in
-n)
name=$2
bookcreate "$2";;
-h)
helpf;;
*)
echo "you must first insert a" name" (-n NAME)"
helpf;;
esac
case $3 in
-l)
lang=$4;;
--sapienza)
opt=1;;
-v)
ver=$4;;
-h)
helpf;;
esac
case $4 in
--sapienza)
opt=1;;
-v)
ver=$5;;
-h)
helpf;;
esac
case $5 in
--sapienza)
opt=1;;
-v)
ver=$6;;
-h)
helpf;;
esac
case $6 in
--sapienza)
opt=1;;
-v)
ver=$7;;
-h)
helpf;;
esac
case $7 in
--sapienza)
opt=1;;
-v)
ver=$8;;
-h)
helpf;;
esac
case $8 in
--sapienza)
opt=1;;
-v)
ver=$9;;
-h)
helpf;;
esac
maketitle "$@"
titlecomplete
titlecolor
exit
#else
# echo "insert a" name" [-n NAME]"
# exit
fi
maketitle "$@"
titlecomplete
titlecolor
exit