-
Notifications
You must be signed in to change notification settings - Fork 0
/
xelatex-letter-builder.sh
executable file
·466 lines (415 loc) · 10.4 KB
/
xelatex-letter-builder.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
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
#! /bin/bash
#
#
# -----------------------------------------------------------
# | "XeLaTeX-LetterBuilder" |
# -----------------------------------------------------------
# A Bash script to create automagically letters with XeLaTeX
#
#
#
# Copyright (C) 2015 Paul Jerabek
#
# __________________________________________________________
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# __________________________________________________________
#
# This script will automatically create XeLaTeX letters in the Linux
# Libertine and Linux Biolinum font. For that, it will utilize the
# scrlttr2 class out of the KOMA-Script package.
#
# After a series of questions the nano editor will open out in which
# the content of the letter can be inserted. After that a PDF document
# will be created.
#
# It is fairly easy to modify the script to one's need by just changing
# some of the options and keywords in the XeLaTeX letter template.
#
# As a feature, this script will save the sender details (name, address etc.)
# in a directory called ~/.xelatex-letter-builder so it can be
# easily loaded for later use.
#
# Required packages: xelatex, fonts-linuxlibertine, nano
#
#
#
# 01/07/2015: Version 1.0
#
##############################################################
#
# definition of variables
#
DATE=`date +%Y-%m-%d`
MAINFONT="Linux Libertine O"
SANSFONT="Linux Biolinum O"
SAVEPATH="$HOME/.xelatex-letter-builder"
MYPWD=`pwd`
#
# definition of functions
#
function welcome {
echo ""
echo "#################################################"
echo "# Welcome to the XeLaTeX-Letter-Generator! #"
echo "#################################################"
echo ""
echo ""
echo ""
}
function sender {
SENDER=""
echo ""
while [ "$SENDER" == "" ]; do
echo "#################################################"
echo "Please enter the name of the sender! (q to quit)"
read SENDER
if [ "$SENDER" == "q" ]; then
exit 0
fi
done
echo "#################################################"
echo ""
echo ""
echo "Return address:"
echo ""
echo "Street and house number?"
read SENDERSTREET
echo ""
echo "Postal code and city?"
read SENDERCITY
echo ""
echo ""
echo "Telephone number?"
read TELEPHONE
if [ "$TELEPHONE" == "" ]; then # Empty?
INSERTPHONE=""
else
INSERTPHONE=" \\usekomavar*{fromphone} & \usekomavar{fromphone} \\\\"
fi
echo ""
echo ""
echo "Mobile phone number?"
read MOBILE
if [ "$MOBILE" == "" ]; then
INSERTMOBILE=""
else
INSERTMOBILE=" \\usekomavar*{frommobile} & \usekomavar{frommobile}\\\\"
fi
echo ""
echo ""
echo "E-mail address?"
read MAILADDRESS
if [ "$MAILADDRESS" == "" ]; then
INSERTMAIL=""
else
INSERTMAIL=" \\usekomavar*{fromemail} & \usekomavar{fromemail} \\\\"
fi
echo ""
echo "Homepage?"
read HOMEPAGE
echo ""
if [ "$HOMEPAGE" == "" ]; then
INSERTURL=""
else
INSERTURL=" \\usekomavar*{fromurl} & \usekomavar{fromurl}"
fi
echo "#################################################"
echo ""
echo ""
}
function recipient {
RECIPIENT=""
echo ""
while [ "$RECIPIENT" == "" ]; do
echo "#################################################"
echo "Please enter the name of the recipient! (q zum Beenden)"
read RECIPIENT
if [ "$RECIPIENT" == "q" ]; then
exit 0
fi
done
echo ""
echo "#################################################"
echo ""
echo "Inside address:"
echo ""
echo "Street and house number?"
read RECIPIENTSTREET
echo ""
echo "Postal code and city?"
read RECIPIENTCITY
echo ""
echo "#################################################"
echo ""
echo ""
}
function city {
echo ""
echo "#################################################"
echo "City printed beside the date?"
read CITY_TEST
if [ "$CITY_TEST" != "" ]; then
CITY="$CITY_TEST, "
fi
echo ""
echo "#################################################"
echo ""
echo ""
}
function senddate {
echo ""
echo "#################################################"
echo "Date? (Default: Today's)"
read SENDDATE
if [ "$SENDDATE" == "" ]; then # Name leer?
SENDDATE="\today"
fi
echo ""
echo "#################################################"
echo ""
echo ""
}
function subject {
echo ""
echo "#################################################"
echo "Regarding?"
read SUBJECT
echo ""
echo "#################################################"
echo ""
echo ""
}
function opening {
echo ""
echo "#################################################"
echo "Opening? (Default: Dear Sir or Madam,)"
read OPENING
if [ "$OPENING" == "" ]; then # Empty?
OPENING="Dear Sir or Madam,"
fi
echo ""
echo "#################################################"
echo ""
echo ""
}
function closing {
echo ""
echo "#################################################"
echo "Closing? (Default: Sincerely yours,)"
read CLOSING
if [ "$CLOSING" == "" ]; then # Empty?
CLOSING="Sincerely yours,"
fi
echo ""
echo "#################################################"
echo ""
echo ""
}
function attachments {
echo ""
echo "#################################################"
echo "Enclosures? (Seperate multiple enclosure through \\\\\\\\ from each other )"
read ATTACHMENTS
if [ "$ATTACHMENTS" == "" ]; then
INSERTATTACHMENT="% \\encl{$ATTACHMENTS}"
else
INSERTATTACHMENT=" \\encl{$ATTACHMENTS}"
fi
echo ""
echo "#################################################"
echo ""
echo ""
}
function makedir {
FOLDERNAME=""
echo ""
while [ "$FOLDERNAME" == "" ]; do
echo "#################################################"
echo "Save under which name? (q to quit)"
read FOLDERNAME
if [ "$FOLDERNAME" == "q" ]; then
exit 0
fi
done
mkdir "$MYPWD/$DATE-$FOLDERNAME"
echo "#################################################"
echo ""
echo ""
}
function lettercontent {
CHECK="1"
echo ""
while [ "$CHECK" == "1" ]; do
echo "#################################################"
echo "Please enter the content of the letter. Just type"
echo "in the text and press Ctrl+X, Y and 2x enter. "
echo ""
echo "Press now enter to proceed and open the nano editor."
echo ""
read CHECK
done
touch $MYPWD/$DATE-$FOLDERNAME/lettercontent.dat
nano $MYPWD/$DATE-$FOLDERNAME/lettercontent.dat
LETTERCONTENT=`cat $MYPWD/$DATE-$FOLDERNAME/lettercontent.dat`
echo "#################################################"
echo ""
echo ""
}
function makealetter {
cd "$MYPWD/$DATE-$FOLDERNAME"
cat <<-EOF > "$FOLDERNAME".tex
%!TEX TS−program = xetex
%!TEX encoding = UTF−8 Unicode
\\documentclass[UScommercial9,paper=letter]{scrlttr2}
\\usepackage[pass]{geometry}
\\KOMAoptions{parskip,locfield=wide,firsthead=false,enlargefirstpage}
\\setkomavar{fromname}{$SENDER}
\\setkomavar{fromaddress}{$SENDERSTREET\\\\$SENDERCITY}
\\setkomavar{fromphone}[Tel.: ]{$TELEPHONE}
\\setkomavar{fromemail}{$MAILADDRESS}
\\setkomavar{fromurl}[Website: ]{$HOMEPAGE}
\\newkomavar[Mobile:]{frommobile}
\\setkomavar{frommobile}{$MOBILE}
\\setkomavar{location}{%
\\textbf{\usekomavar{fromname}}\\\\
\\usekomavar{fromaddress}
\\scriptsize
\\begin{tabular}[t]{@{}l@{\ }l}
$INSERTPHONE
$INSERTMOBILE
& \\\\
$INSERTMAIL
$INSERTURL
\\end{tabular}
\\usekomavar{frombank}
}
\\usepackage[english]{babel}
\\usepackage{graphicx}
\\usepackage{fontspec}% provides font selecting commands
\\usepackage{xunicode}% provides unicode character macros
\\usepackage[no-sscript]{xltxtra} % provides some fixes/extras.
\\usepackage{fixltx2e}
\\usepackage{setspace}
\\usepackage{ellipsis}
\\usepackage{amssymb}
\\usepackage{amsmath}
\\renewcommand{\glqq}{„}
\\renewcommand{\grqq}{“}
% Packages for xelatex----------------------
% \\usepackage{unicode-math}
% \\defaultfontfeatures{Mapping=tex-text, Numbers=OldStyle}
\\defaultfontfeatures{Mapping=tex-text}
\\setmainfont{$MAINFONT}
\\setsansfont{$SANSFONT}
% \\setmathfont[Scale=MatchLowercase]{Asana Math}
\\begin{document}
% Date:
\\setkomavar{date}{$CITY$SENDDATE}
\\setkomavar{subject}{$SUBJECT}
\\begin{letter}{%
$RECIPIENT\\\\
$RECIPIENTSTREET\\\\
$RECIPIENTCITY
}
\\opening{$OPENING}
$LETTERCONTENT
\\closing{$CLOSING}
% \\ps PS:
$INSERTATTACHMENT
% \\cc{Verteiler}
\\end{letter}
\\end{document}
EOF
xelatex "$FOLDERNAME".tex
}
function savesender {
mkdir -p "$SAVEPATH"
cd "$SAVEPATH"
echo "$SENDER" > sender.dat
echo "$SENDERSTREET" > senderstreet.dat
echo "$SENDERCITY" > sendercity.dat
echo "$TELEPHONE" > telephone.dat
echo "$MOBILE" > mobile.dat
echo "$MAILADDRESS" > mailaddress.dat
echo "$HOMEPAGE" > homepage.dat
}
function checksavepath {
if [ -d "$SAVEPATH" ]; then
loadsender
else sender
fi
}
function loadsender {
echo ""
echo "#################################################"
echo "Press Y/y to load the data about the last sender"
echo "from $SAVEPATH."
echo ""
read LOADDATA
if [[ "$LOADDATA" == "Y" || "$LOADDATA" == "y" ]]; then
cd "$SAVEPATH"
if [ -f sender.dat ]; then
SENDER=`cat sender.dat`
fi
if [ -f senderstreet.dat ]; then
SENDERSTREET=`cat senderstreet.dat`
fi
if [ -f sendercity.dat ]; then
SENDERCITY=`cat sendercity.dat`
fi
if [ -f telephone.dat ]; then
TELEPHONE=`cat telephone.dat`
fi
if [ -f mobile.dat ]; then
MOBILE=`cat mobile.dat`
fi
if [ -f mailaddress.dat ]; then
MAILADDRESS=`cat mailaddress.dat`
fi
if [ -f homepage.dat ]; then
HOMEPAGE=`cat homepage.dat`
fi
echo ""
echo "#################################################"
echo ""
echo "Loaded the following data:"
echo ""
echo "- Sender: $SENDER"
echo "- Return address: $SENDERSTREET, $SENDERCITY"
echo "- Telephone number: $TELEPHONE"
echo "- Mobile phone number: $MOBILE"
echo "- E-mail address: $MAILADDRESS"
echo "- Website: $HOMEPAGE"
echo ""
echo "#################################################"
echo ""
echo ""
else
sender
fi
}
#
# Execute functions: Create letter
#
welcome
checksavepath
#loadsender
recipient
subject
city
senddate
opening
closing
attachments
makedir
lettercontent
makealetter
savesender