-
Notifications
You must be signed in to change notification settings - Fork 5
/
chemmacros.build
executable file
·347 lines (330 loc) · 9.68 KB
/
chemmacros.build
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# --------------------------------------------------------------------------
# the CHEMMACROS package
#
# comprehensive support for typesetting chemistry documents
#
# --------------------------------------------------------------------------
# Web: https://github.com/cgnieder/chemmacros/
# E-Mail: [email protected]
# --------------------------------------------------------------------------
# Copyright 2011--2021 Clemens Niederberger
# 2022-- Clemens Niederberger & Sonja K.
# --------------------------------------------------------------------------
# this is a personal bash script to build the chemmacros package
# and very likely not of use for anybody else
#
# !! USE WITH CAUTION !!
#
# --------------------------------------------------------------------------
#!/bin/bash
pkgname="chemmacros"
moduleext="code.tex"
modulename="${pkgname}"
styname="${pkgname}.sty"
program="arara"
manualfile="$pkgname.manual"
manualname="$pkgname-manual"
zipname="$pkgname"
build=true
cleancode=false
cleandoc=false
cleanup=false
createzip=false
manual=false
runmktexlsr=false
update=false
silent=false
usage="script for buiding the $pkgname package
./$(basename "$0") [option(s) [value]]
where valid options are:
-b build sty file from modules (default: $build)
-d deletes auxiliary files from a latex compilation
allowed values: 'none', 'all', 'code', 'doc' (default: 'none')
-f name of manual file (without .tex) (default: '$manualname')
-h show this help
-l run latex to (re-) create manual (default: $manual)
-m run mktexlsr, only when used together with -u (default: $runmktexlsr)
-n do nothing and exit
-o output file for creating the style file (default: '$styname')
-p program for building the manual (default: '$program')
-s silent, avoid messages (default: $silent)
-u update local tex repository (default: $update)
-z create zip file for CTAN upload (default: $createzip)"
# options:
while [ -n "$1" ]; do
case "$1" in
-b|--build)
case "$2" in
true)
shift ;;
false)
build=false
shift ;;
*) ;;
esac ;;
-d|--delete)
case "$2" in
none)
cleanup=false ;;
all)
cleanup=true
cleancode=true
cleandoc=true ;;
code)
cleanup=true
cleancode=true ;;
doc)
cleanup=true
cleandoc=true ;;
*)
echo "invalid value '$2'"
exit 1 ;;
esac
shift ;;
-f|--file)
manualname="$2"
shift ;;
-h|--help)
echo "$usage"
exit 0 ;;
-l|--latex)
case "$2" in
true)
manual=true
shift ;;
false)
manual=false
shift ;;
*)
manual=true ;;
esac ;;
-m|--mktexlsr)
case "$2" in
true)
runmktexlsr=true
shift ;;
false)
runmktexlsr=false
shift ;;
*)
runmktexlsr=true ;;
esac ;;
-n|--nothing)
exit 0 ;;
-o|--output)
styname="$2"
shift ;;
-p|--program)
program="$2"
shift ;;
-s|--silent)
case "$2" in
true)
slient=true
shift ;;
false)
silent=false
shift ;;
*)
silent=true ;;
esac ;;
-u|--update)
case "$2" in
true)
update=true
shift ;;
false)
update=false
shift ;;
*)
update=true ;;
esac ;;
-v|--version)
zipname="${zipname}_v$2"
shift ;;
-z|--zip)
case "$2" in
true)
createzip=true
shift ;;
false)
createzip=false
shift ;;
*)
createzip=true ;;
esac ;;
*) echo "unknown option '$1'"
exit 1 ;;
esac
shift
done
if [ "$silent" == true ] ; then
verbose=false
else
verbose=true
fi
START_DIR="${PWD}"
DEV_DIR=~/LaTeX/dev
SNAPSHOT_DIR=~/LaTeX/snapshots
CHEMMACROS_DEV_DIR=${DEV_DIR}/$pkgname
CODE_DIR=${CHEMMACROS_DEV_DIR}/code
DOC_DIR=${CHEMMACROS_DEV_DIR}/doc
TEXMFLOCAL_DIR=/usr/local/texlive/texmf-local
LATEXLOCAL_DIR=${TEXMFLOCAL_DIR}/tex/latex/local
BIBLOCAL_DIR=${TEXMFLOCAL_DIR}/bibtex/bib/local
# files to be "cleaned":
AUX_FILES=""
if [ "$cleanup" == true ] ; then
if [ "$cleancode" == true ] ; then
AUX_FILES="${AUX_FILES}
${CODE_DIR}/*~"
fi
if [ "$cleandoc" == true ] ; then
AUX_FILES="${AUX_FILES}
${DOC_DIR}/*~
${DOC_DIR}/*synctex*
${DOC_DIR}/*.run.xml
${DOC_DIR}/*.aux
${DOC_DIR}/*.acr
${DOC_DIR}/*.xsim
${DOC_DIR}/*.log
${DOC_DIR}/*.out
${DOC_DIR}/*.bbl
${DOC_DIR}/*.bcf
${DOC_DIR}/*.bib
${DOC_DIR}/*.blg
${DOC_DIR}/*.idx
${DOC_DIR}/*.ilg
${DOC_DIR}/*.ind
${DOC_DIR}/*.tmp
${DOC_DIR}/*.toc
${DOC_DIR}/*.lof
${DOC_DIR}/*.lot"
fi
fi
if [ "$build" == true ] ; then
if [ "$verbose" == true ] ; then
echo "writing style file $styname ..."
fi
# change to the code directory
cd ${CODE_DIR}
# build sty file from modules:
cat \
../$pkgname.intro.statement \
$modulename.start.$moduleext \
$modulename.base.$moduleext \
$modulename.errorcheck.$moduleext \
$modulename.lang.$moduleext \
$modulename.greek.$moduleext \
$modulename.formula.$moduleext \
$modulename.charges.$moduleext \
$modulename.acid-base.$moduleext \
$modulename.symbols.$moduleext \
$modulename.particles.$moduleext \
$modulename.phases.$moduleext \
$modulename.nomenclature.$moduleext \
$modulename.tikz.$moduleext \
$modulename.isotopes.$moduleext \
$modulename.mechanisms.$moduleext \
$modulename.newman.$moduleext \
$modulename.orbital.$moduleext \
$modulename.polymers.$moduleext \
$modulename.reactions.$moduleext \
$modulename.redox.$moduleext \
$modulename.xfrac.$moduleext \
$modulename.scheme.$moduleext \
$modulename.spectroscopy.$moduleext \
$modulename.thermodynamics.$moduleext \
$modulename.units.$moduleext \
$modulename.reactants.$moduleext \
$modulename.translations.$moduleext \
> $styname
if [ "$verbose" == true ] ; then
echo "writing manual files ..."
fi
cd ${DOC_DIR}
# build manual files:
cat \
../$pkgname.intro.statement \
$manualfile.tex \
> $manualname.tex
cat \
../$pkgname.intro.statement \
$manualfile.cls \
> $manualname.cls
fi
# build manual
if [ "$manual" == true ] ; then
cd ${DOC_DIR}
if [ "$verbose" == true ] ; then
echo "running '$program' on '$manualname'..."
fi
$program $manualname
fi
# remove temporary and auxiliary files
if [ "$cleanup" == true ] ; then
if [ "$verbose" == true ] ; then
echo "deleting auxiliary files..."
fi
for file in ${AUX_FILES}
do
if [ ! -e "${file}" ]; then continue
else
if [ "$verbose" == true ] ; then
echo "deleting file '${file}' ..."
fi
rm "${file}"
fi
done
fi
# move new sty file to local repo
if [ "$update" == true ] ; then
if [ "$verbose" == true ] ; then
echo "updating texmf-local..."
fi
if [ ! -d "${LATEXLOCAL_DIR}/$pkgname" ]; then
if [ "$verbose" == true ] ; then
echo "creating directory '${LATEXLOCAL_DIR}/$pkgname' ..."
fi
mkdir ${LATEXLOCAL_DIR}/$pkgname
fi
cd ${CODE_DIR}
cp $styname ${LATEXLOCAL_DIR}/$pkgname
if [ "$runmktexlsr" == true ] ; then
if [ "$verbose" == true ] ; then
echo "running mktexlsr ..."
fi
mktexlsr
fi
fi
if [ "$createzip" == true ] ; then
cd ${START_DIR}
if [ -f "${SNAPSHOT_DIR}/$pkgname/$zipname.zip" ] ; then
rm ${SNAPSHOT_DIR}/$pkgname/$zipname.zip
fi
if [ "$verbose" == true ] ; then
echo "creating zip archive $zipname.zip ..."
fi
if [ ! -d "${SNAPSHOT_DIR}/$pkgname" ]; then
if [ "$verbose" == true ] ; then
echo "creating directory '${SNAPSHOT_DIR}/$pkgname' ..."
fi
mkdir ${SNAPSHOT_DIR}/$pkgname
fi
mkdir $pkgname/
cp ${CODE_DIR}/$styname $pkgname/
cp ${CODE_DIR}/$pkgname-2015-02-08.sty $pkgname/
cp ${CODE_DIR}/$pkgname-2020-03-07.sty $pkgname/
cp ${DOC_DIR}/$manualname.tex $pkgname/
cp ${DOC_DIR}/$manualname.pdf $pkgname/
cp README $pkgname/
cp HISTORY $pkgname/
zip -r $zipname.zip $pkgname/
rm -r $pkgname/
if [ "$verbose" == true ] ; then
echo "moving zip archive $zipname.zip ..."
fi
mv $zipname.zip ${SNAPSHOT_DIR}/$pkgname/$zipname.zip
fi
cd ${START_DIR}
exit 0