-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctuth-core.tex
405 lines (310 loc) · 12.9 KB
/
ctuth-core.tex
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
%!TEX ROOT = ctutest.tex
\ProvidesExplFile{ctuth-core.tex}%
{2016/06/15}{0.1 t1606152353}%MY TIMESTAMP HERE {0.1}
{"Core"\space part\space of\space the\space class\space ctuthesis}
%%% GENERAL LaTeX3 THINGIES
\cs_generate_variant:Nn \keys_set:nn { nx }
\cs_generate_variant:Nn \tl_if_eq:nnTF { xn }
\cs_generate_variant:Nn \seq_gconcat:NNN { cc }
\cs_generate_variant:Nn \str_if_eq:nnTF { xn }
\skip_new:N \g_ctuthesis_tempa_skip
%%% CLASS SETUP, FIELDS, TEMPLATES, THEMES
% Set allowed languages: No other languages can ever be main, title or second
\tl_gset:Nn \g_ctuthesis_alllanguages_tl {{czech}{english}{slovak}}
% Error message for using \ctuprocess twice
\msg_new:nnn { ctuthesis } { ctuprocess-twice } { The~macro~ \token_to_str:N \ctuprocess\ should~
be~used~only~once~in~preamble. }
% Error message for not using \ctuprocess at all
\msg_new:nnn { ctuthesis } { ctuprocess-none } { It~is~necessary~to~use~the~
macro~ \token_to_str:N \ctuprocess\ once~in~the~preamble. }
%%% KEY-VALUE SETUP
% Two seqs: one for keys that need disabling after \documentclass,
% another one for keys that need disabling after \ctuprocess
\seq_new:N \g_ctuthesis_keys_nop_seq
\seq_new:N \g_ctuthesis_keys_nopost_seq
% Add the clist #2 into seq #1
\cs_new_protected:Nn \ctuthesis_keys_add_no:nn {
\group_begin:
\seq_set_from_clist:Nn \l_temp_ctuthesis_a_seq { #2 }
\seq_gconcat:ccN { g_ctuthesis_keys_#1_seq } { g_ctuthesis_keys_#1_seq } \l_temp_ctuthesis_a_seq
\group_end:
}
% Error messages for the keyvalue interface
\msg_new:nnn { ctuthesis } { keys-unknown } { The~key~'#1'~is~not~known~to~the~
class~'ctuthesis'~and~will~be~ignored. }
\msg_new:nnn { ctuthesis } { keys-nopost } { The~key~'#1'~is~forbidden~after~
\token_to_str:N \ctuprocess \space and~will~be~ignored.~You~may~wish~to~
set~it~up~before. }
\msg_new:nnn { ctuthesis } { keys-nop } { The~key~'#1'~is~forbidden~in~
\token_to_str:N \ctusetup \space and~will~be~ignored.~Use~the~optional~argument~
of~ \token_to_str:N \documentclass \space to~set~it~up. }
% Very standard unknown key treatment
\keys_define:nn { ctuthesis } {
unknown .code:n = \msg_error:nnx { ctuthesis } { keys-unknown } { \l_keys_key_tl },
}
% Disables keys marked '#1' (either 'nop' or 'nopost')
\cs_new_protected:Nn \ctuthesis_disable_keys:n {
\seq_map_inline:cn { g_ctuthesis_keys_#1_seq } {
\keys_define:nn { ctuthesis } {
##1 .code:n = \msg_error:nnx { ctuthesis } { keys-#1 } { ##1 },
}
}
}
% General keys
\tl_gset:Nn \g_ctuthesis_fontsize_tl {11pt}
\seq_new:N \g_ctuthesis_languages_seq
\keys_define:nn { ctuthesis } {
% Only 11pt fontsize is allowed
fontsize .choices:nn = { 11pt } { \tl_gset_eq:NN \g_ctuthesis_fontsize_tl \l_keys_choice_tl },
% Oneside option
oneside .bool_gset:c = { g_ctuthesis_switch_oneside_bool },
oneside .initial:n = { false },
twoside .meta:n = { oneside = false },
% Draft option
draft .bool_gset:c = { g_ctuthesis_switch_draft_bool },
draft .initial:n = { false },
% We use three languages:
% main for the work itself, ToC and LoFT
mainlanguage .choice:,
% title for the titlepage, thanks, declaration and abstract
titlelanguage .choice:,
% second is the language of second abstract. First abstract is in title language,
% second abstract is either in main language, or in English for Czech/Slovak theses
% or Czech for English theses. It will be set automatically.
secondlanguage .choice:,
% otherlanguages will be simply passed on to babel
otherlanguages .code:n =
\seq_set_from_clist:Nn \l_temp_ctuthesis_a_seq { #1 }
\seq_gconcat:NNN \g_ctuthesis_languages_seq \g_ctuthesis_languages_seq \l_temp_ctuthesis_a_seq
,
}
\ctuthesis_keys_add_no:nn { nop } { draft, fontsize, oneside, twoside }
\ctuthesis_keys_add_no:nn { nopost } { mainlanguage, titlelanguage, secondlanguage }
% Switches defaulting to false
\tl_map_inline:nn { {front-specification}{monochrome}{savetoner}{pkg-listings}{layout-short} } {
\keys_define:nn { ctuthesis } {
#1 .bool_gset:c = { g_ctuthesis_switch_#1_bool },
#1 .initial:n = { false },
}
}
\ctuthesis_keys_add_no:nn { nopost } { monochrome, savetoner, pkg-listings }
% Switches defaulting to true
\tl_map_inline:nn { {front-list-of-tables}{front-list-of-figures}{pkg-hyperref}{pkg-makeidx}{pkg-amsthm} } {
\keys_define:nn { ctuthesis } {
#1 .bool_gset:c = { g_ctuthesis_switch_#1_bool },
#1 .initial:n = { true },
}
}
\ctuthesis_keys_add_no:nn { nopost } { pkg-hyperref, pkg-makeidx }
% We allow the key 11pt along with the key fontsize
\tl_map_inline:nn { {11pt} } {
\keys_define:nn { ctuthesis } {
#1 .meta:n = { fontsize = #1 },
}
\ctuthesis_keys_add_no:nn { nop } { #1 }
}
% Basic fields that are not language-dependent
\tl_map_inline:nn { {author}{supervisor}{supervisor-specialist}{supervisor-address}{day}{month}{year}
{facultynum}{specification-file}{preprint} } {
\keys_define:nn { ctuthesis } {
#1 .tl_gset:c = { g_ctuthesis_field_#1_tl },
}
}
% Language-dependent keys and environments
\tl_map_inline:Nn \g_ctuthesis_alllanguages_tl {
% Various fields in various languages
\tl_map_inline:nn { {title}{subtitle}{university}{university-endl}{faculty}{department}
{doctype}{fieldofstudy}{subfieldofstudy}{keywords} } {
\keys_define:nn { ctuthesis } {
##1-#1 .tl_gset:c = g_ctuthesis_field_##1_#1_tl,
}
}
% Sets up the choice for each of the languages
\tl_map_inline:nn { {mainlanguage}{titlelanguage}{secondlanguage} } {
\keys_define:nn { ctuthesis } {
##1 / #1 .code:n =
\tl_gset:cn { g_ctuthesis_field_##1_tl } { #1 }
\seq_gput_right:Nn \g_ctuthesis_languages_seq { #1 },
}
}
% The abstract is now language-dependent
\NewEnviron { abstract-#1 } { \tl_gset:cV { g_ctuthesis_field_abstract_#1_tl } \BODY }
\tl_new:c { g_ctuthesis_field_abstract_#1_tl }
}
% "abstract" itself is not used, the language of the abstract has to be specified
\msg_new:nnn { ctuthesis } { abstract-forbidden } { The~environment~'abstract'~should~be~replaced~
by~'abstract-lang'~with~the~proper~language~specified. }
\DeclareDocumentEnvironment{ abstract }{ }{ \msg_error:nn { ctuthesis } { abstract-forbidden } }{ }
% "thanks" and "declaration" are fields, but set up as environments rather then KVs
\cs_undefine:c { thanks }
\NewEnviron { thanks } { \tl_gset:cV { g_ctuthesis_field_thanks_tl } \BODY }
\tl_new:c { g_ctuthesis_field_thanks_tl }
\NewEnviron { declaration } { \tl_gset:cV { g_ctuthesis_field_declaration_tl } \BODY }
\tl_new:c { g_ctuthesis_field_declaration_tl }
\tl_gset:Nn \g_ctuthesis_ctulstbg_tl { ctulstbg }
\keys_define:nn { ctuthesis } {
ctulstbg .tl_gset:N = \g_ctuthesis_ctulstbg_tl
}
% A macro called after every \keys_set{ctuthesis}{...}
\cs_new_protected:Nn \ctuthesis_ctusetup_trigger: {
% Remove duplicates from the language list
\seq_gremove_duplicates:N \g_ctuthesis_languages_seq
% Set up titlelanguage as mainlanguage if the latter is defined and the former is not
\bool_if:nT { \tl_if_exist_p:c { g_ctuthesis_field_mainlanguage_tl }
&& ! \tl_if_empty_p:c { g_ctuthesis_field_mainlanguage_tl }
&& ( ! \tl_if_exist_p:c { g_ctuthesis_field_titlelanguage_tl }
|| \tl_if_empty_p:c { g_ctuthesis_field_titlelanguage_tl } )
} {
\keys_set:nx { ctuthesis } { titlelanguage = \tl_use:c { g_ctuthesis_field_mainlanguage_tl } }
}
% Set up secondlanguage if it has not been set up before
\bool_if:nT { \tl_if_exist_p:c { g_ctuthesis_field_mainlanguage_tl }
&& \tl_if_exist_p:c { g_ctuthesis_field_titlelanguage_tl }
&& ( ! \tl_if_exist_p:c { g_ctuthesis_field_secondlanguage_tl }
|| \tl_if_empty_p:c { g_ctuthesis_field_secondlanguage_tl } )
} {
\tl_if_eq:ccTF { g_ctuthesis_field_mainlanguage_tl } { g_ctuthesis_field_titlelanguage_tl } {
\tl_if_eq:xnTF { \tl_use:c { g_ctuthesis_field_mainlanguage_tl } } { english } {
\keys_set:nn { ctuthesis } { secondlanguage = czech }
} {
\keys_set:nn { ctuthesis } { secondlanguage = english }
}
} {
\keys_set:nx { ctuthesis } { secondlanguage = \tl_use:c { g_ctuthesis_field_mainlanguage_tl } }
}
}
}
% Key setup to be used in the preamble
\NewDocumentCommand \ctusetup { m } {
\keys_set:nn { ctuthesis } { #1 }
\ctuthesis_ctusetup_trigger:
}
%%% THEMES, TEMPLATES AND FIELDS
% Theme, template and field hadling - "unknown" error messages
\msg_new:nnn { ctuthesis } { unknown-theme } { Theme~'#1'~has~not~been~defined~
for~use~with~ \token_to_str:N \ctutheme . }
\msg_new:nnn { ctuthesis } { unknown-template } { Template~'#1'~has~not~been~defined~
for~use~with~ \token_to_str:N \ctutemplate . }
\msg_new:nnn { ctuthesis } { unknown-field } { Field~'#1'~has~not~been~defined~
for~use~with~ \token_to_str:N \ctufield . }
% Theme and template hadling - setters
\NewDocumentCommand \ctuthemeset { >{\TrimSpaces}m +m } {
\cs_set:cn { ctuthesis_theme_#1_var: } { #2 }
}
\NewDocumentCommand \ctutemplateset { >{\TrimSpaces}m +m } {
\cs_set:cn { ctuthesis_template_#1_var: } { #2 }
}
% Theme, template and field hadling - getters
\NewDocumentCommand \ctutheme { >{\TrimSpaces}m } {
\cs_if_exist_use:cF { ctuthesis_theme_#1_var: } { \msg_error:nnx { ctuthesis } { unknown-theme } { #1 } }
}
\NewDocumentCommand \ctutemplate { >{\TrimSpaces}m } {
\cs_if_exist_use:cF { ctuthesis_template_#1_var: } { \msg_error:nnx { ctuthesis } { unknown-template } { #1 } }
}
% `\ctufield` supports the context language specifier as an optional argument
\NewDocumentCommand \ctufield { s >{\TrimSpaces}o >{\TrimSpaces}m } {
\IfBooleanTF { #1 } {
\IfValueTF { #2 } {
\ctuthesis_field_use_default:nnn { #2 } { #3 } { }
} {
\ctuthesis_field_use_default:nn { #3 } { }
}
} {
\IfValueTF { #2 } {
\ctuthesis_field_use:nn { #2 } { #3 }
} {
\ctuthesis_field_use:n { #3 }
}
}
}
% Four variants of the "field use": expandable (with default value)/non-expandable (with error message) and language-independent/dependent
% #1->field, #2->default value
\cs_new:Nn \ctuthesis_field_use_default:nn {
\cs_if_exist_use:cF { g_ctuthesis_field_#1_tl } { #2 }
}
% #1->language, #2->field, #3->default value
\cs_new:Nn \ctuthesis_field_use_default:nnn {
\ctuthesis_field_use_default:nn
{ #2_\ctuthesis_field_use_default:nn { #1 language } { nolanguage } }
{ #3 }
}
% #1->field
\cs_new_protected:Nn \ctuthesis_field_use:n {
\cs_if_exist_use:cF { g_ctuthesis_field_#1_tl } { \msg_error:nnx { ctuthesis } { unknown-field } { #1 } }
}
% #1->language, #2->field
\cs_new_protected:Nn \ctuthesis_field_use:nn {
\cs_if_exist:cTF { g_ctuthesis_field_#1language_tl }
{ \ctuthesis_field_use:n { #2_\ctuthesis_field_use_default:nn { #1 language } { } } }
{ \msg_error:nnx { ctuthesis } { unknown-field } { #1 language } }
}
% Theme, template and field hadling - existance conditionals
\prg_new_conditional:Nnn \ctuthesis_theme_exists:n { p, T, F, TF } {
\cs_if_exist:cTF { ctuthesis_theme_#1_var } { \prg_return_true: } { \prg_return_false: }
}
\prg_new_conditional:Nnn \ctuthesis_template_exists:n { p, T, F, TF } {
\cs_if_exist:cTF { ctuthesis_template_#1_var } { \prg_return_true: } { \prg_return_false: }
}
\prg_new_conditional:Nnn \ctuthesis_field_exists:n { p, T, F, TF } {
\cs_if_exist:cTF { g_ctuthesis_field_#1_tl } { \prg_return_true: } { \prg_return_false: }
}
% Theme, template and field hadling - publicly available conditionals with "true" and "false" branches
\DeclareDocumentCommand \ctuiftheme { s >{\TrimSpaces}m +m +m } {
\ctuthesis_theme_exists:nTF { #2 } {
\IfBooleanTF { #1 } {
\tl_if_empty:cTF { g_ctuthesis_theme_#1_tl } { #4 } { #3 }
} {
#3
}
} {
#4
}
}
\DeclareDocumentCommand \ctuiftemplate { s >{\TrimSpaces}m +m +m } {
\ctuthesis_template_exists:nTF { #2 } {
\IfBooleanTF { #1 } {
\tl_if_empty:cTF { g_ctuthesis_template_#1_tl } { #4 } { #3 }
} {
#3
}
} {
#4
}
}
% The starred variant checks for emptiness rather than for existance
\DeclareDocumentCommand \ctuiffield { s >{\TrimSpaces}o >{\TrimSpaces}m +m +m } {
\IfValueTF { #2 } {
\ctuthesis_field_exists:nF { #2 language } { \msg_error:nnx { ctuthesis } { unknown-field } { #1 } }
\IfBooleanTF { #1 } {
\ctuiffield * { #3_\ctuthesis_field_use:n { #2 language } } { #4 } { #5 }
} {
\ctuiffield { #3_\ctuthesis_field_use:n { #2 language } } { #4 } { #5 }
}
} {
\ctuthesis_field_exists:nTF { #3 } {
\IfBooleanTF { #1 } {
\tl_if_empty:cTF { g_ctuthesis_field_#3_tl } { #5 } { #4 }
} {
#4
}
} {
\ctuthesis_field_exists:nTF { #3 } { #5 } { #4 }
}
}
}
% We don't do any check for existance of a switch, so better be careful.
\prg_new_conditional:Nnn \ctuthesis_if_switch:n { p, T, F, TF } {
\bool_if:cTF { g_ctuthesis_switch_#1_bool } { \prg_return_true: } { \prg_return_false: }
}
\DeclareDocumentCommand \ctuifswitch { >{\TrimSpaces}m +m +m } {
\bool_if:cTF { g_ctuthesis_switch_#1_bool } { #2 } { #3 }
}
%%% LOGGING
% Create \ctuverlog which contains the automatically updated timestamp of the file.
% It can be used for instance in \ctusetup{preprint = \ctuverlog} in order to show
% the timestamp on every page.
\cs_new_protected:Npx \ctuverlog {
ctuthesis ~ \use_ii:nn
{2016/06/15}{ t1606152353}%MY TIMESTAMP HERE {}
}
\endinput