-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlib.typ
More file actions
662 lines (627 loc) · 20 KB
/
lib.typ
File metadata and controls
662 lines (627 loc) · 20 KB
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
#import "pages.typ": *
#import "_pkgs.typ": hydra.hydra
#import "localization.typ": localization
#let _lang = state("lang")
#let _style = state("style")
#let _appendix-numbering = "A.1"
#let fiit-thesis(
// title of your thesis
title: "Záverečná práca",
// type of the thesis: "bp1", "bp2", "dp1", "dp2", "dp3"
thesis: "bp2",
// a dictionary of type: <language_code>: <abstract>. Both "en" and "sk" are
// mandatory
abstract: (
sk: lorem(150),
en: lorem(150),
), // abstract
// your full name
author: "Jožko Mrkvička",
// ID that you copied from AIS
id: "FIIT-12345-123456",
// department of your work
department: "upai",
// full name of your thesis supervisor
supervisor: "prof. Jozef Mrkva, PhD.",
// supported values: "en", "sk"
lang: "en",
// month of the hand-in
month: 5,
// current date for declaration and year of handing-in
current-date: datetime.today(),
// acknowledgment text
acknowledgment: none,
// assignment from AIS file path.
assignment: none,
// enable list of tables
tables-outline: false,
// enable list of images (figures)
figures-outline: false,
// if this array is empty, the list of abbreviations does not appear
abbreviations-outline: (),
// set to "true" to disable the first (cover) sheet
disable-cover: false,
// style of the thesis
// options: "regular", "compact", "legacy", "legacy-noncompliant",
// "pagecount"
style: "regular",
body,
) = {
////////////////////////////////
// style handling
let is-legacy = style == "legacy" or style == "legacy-noncompliant"
// regular style
let text-size = 1.1em
let page-margins = 3cm
let bibliography-style = "iso-690-numeric"
let use-binding = true
let regular-headings = true
let first-line-indent = 1em
let leading = 1.3em
let spacing = 1.5em
let footer-descent = 30% + 0pt
let header-ascent = 30% + 0pt
let header-margin = if is-legacy { -1.6em } else { -1em }
let header = context {
let hdr = hydra(1)
if hdr != none and style != "pagecount" {
if is-legacy {
hydra(
display: (_, current-heading) => if current-heading.numbering
!= none {
current-heading.supplement
[ ]
numbering(
current-heading.numbering,
counter(heading).at(current-heading.location()).at(0),
)
[. ]
current-heading.body
} else {
current-heading.body
},
skip-starting: false,
)
} else {
emph(hdr)
}
v(header-margin)
line(length: 100%)
}
}
let footer-with-bound-numbering = context {
let (n,) = counter(page).get()
set align(if calc.even(n) { left } else { right })
if page.numbering != none { counter(page).display(page.numbering) }
}
if style == "compact" {
page-margins = 2.5cm
regular-headings = false
leading = 0.8em
spacing = 1.5em
text-size = 1.2em
} else if is-legacy {
// general legacy styles
page-margins = (
inside: 1.5in,
outside: 1in,
top: 1.5in,
bottom: 2in,
)
use-binding = true
first-line-indent = 0em
leading = 1.1em
spacing = 2em
footer-descent = 2em
header-ascent = 2em
} else if style == "pagecount" {
leading = 1.2em
spacing = leading
first-line-indent = 0em
}
if style == "legacy-noncompliant" {
bibliography-style = "ieee"
}
////////////////////////////////
// locale
let locale = localization(lang: lang)
let slovak = localization(lang: "sk")
let english = localization(lang: "en")
_lang.update(lang)
_style.update(style)
assert(
type(month) == int and month >= 1 and month <= 12,
message: "Month should be an integer between 1 and 12",
)
month = month - 1 // convert to array index
////////////////////////////////
// pagecount handling
show pagebreak: it => if style == "pagecount" { none } else { it }
show bibliography: it => if style == "pagecount" { none } else { it }
show outline: it => if style == "pagecount" { none } else { it }
show figure: it => if style == "pagecount" { none } else { it }
show colbreak: it => if style == "pagecount" { none } else { it }
show list.item: it => if style == "pagecount" { it.body } else { it }
show list: it => if style == "pagecount" { it.body } else { it }
show columns: it => if style == "pagecount" { it.body } else { it }
show align: it => if style == "pagecount" { it.body } else { it }
////////////////////////////////
// page setup
set document(author: author, title: title)
set text(font: "New Computer Modern", lang: lang)
show math.equation: set text(weight: 400)
set bibliography(style: bibliography-style, title: locale.bibliography)
////////////////////////////////
// setup headings
set heading(numbering: "1.1", supplement: locale.chapter.title)
show heading: it => block({
if style != "pagecount" {
if style != "compact" {
set text(1.1em, weight: "semibold")
numbering(it.numbering, ..counter(heading).at(it.location()))
h(0.3cm)
it.body
v(0.2cm)
} else {
it
}
}
})
show heading.where(level: 1): it => {
if style == "pagecount" {
return
}
if regular-headings {
// regular, legacy and legacy-noncompliant
set text(1.6em, weight: if is-legacy { "medium" } else { "bold" })
set par(first-line-indent: 0em)
{
set page(header: none, numbering: none)
pagebreak(to: if use-binding { "odd" } else { none }, weak: true)
}
if counter(heading).get().at(0) == 1 {
counter(page).update(1)
}
if it.numbering == _appendix-numbering {
counter(page).update(1)
}
pagebreak(weak: true)
block(height: 2.8cm)
if it.numbering != none {
[#it.supplement #numbering(it.numbering, counter(heading).get().at(0))]
v(0cm)
}
it.body
v(.4cm)
} else {
// compact
pagebreak(to: "odd", weak: true)
if it.numbering == _appendix-numbering {
counter(page).update(1)
}
pagebreak(weak: true)
if it.numbering != none {
it.supplement
[ ]
numbering(it.numbering, counter(heading).get().at(0))
}
linebreak()
it.body
linebreak()
v(.5cm)
}
}
////////////////////////////////
// figures
let figure-supplement(the-figure) = {
if the-figure.func() == raw {
locale.figures.raw
} else if the-figure.func() == table {
locale.figures.table
} else {
locale.figures.figure
}
}
set figure(supplement: figure-supplement)
////////////////////////////////
// title page localization
let fields = locale.title-page.fields
let values = locale.title-page.values
////////////////////////////////
// process potential multiple supervisors
let supervisors-sk = ()
let supervisors-en = ()
if type(supervisor) == str {
supervisors-sk = (
(
left: if thesis.starts-with("bp") {
slovak.title-page.fields.supervisor-bachelors
} else { slovak.title-page.fields.supervisor-masters },
right: supervisor,
),
)
supervisors-en = (
(
left: if thesis.starts-with("bp") {
english.title-page.fields.supervisor-bachelors
} else { english.title-page.fields.supervisor-masters },
right: supervisor,
),
)
} else if type(supervisor) == dictionary {
for pair in supervisor.sk {
supervisors-sk.push((left: pair.at(0), right: pair.at(1)))
}
for pair in supervisor.en {
supervisors-en.push((left: pair.at(0), right: pair.at(1)))
}
}
// localized supervisors
let supervisor-footer = if lang == "en" { supervisors-en } else {
supervisors-sk
}
////////////////////////////////
// cover sheet
if not disable-cover and style != "pagecount" {
title-page(
id: id,
author: author,
title: title,
type: values.thesis.at(thesis),
header: [
#locale.university \
#locale.faculty
],
footer: supervisor-footer,
date: [#values.month.at(month) #current-date.display("[year]")],
)
pagebreak(to: if use-binding { "odd" } else { none }, weak: true)
}
counter(page).update(1)
////////////////////////////////
// title page
assert(
type(department) == str and (department == "upai" or department == "iise"),
message: "Please provide one of the following departments: 'upai' or 'iise'",
)
if style != "pagecount" {
title-page(
id: id,
author: author,
title: title,
type: values.thesis.at(thesis),
header: [
#locale.university \
#locale.faculty
],
footer: (
(left: fields.program, right: values.program.informatics),
(left: fields.field, right: values.field.informatics),
(left: fields.department, right: values.department.at(department)),
..supervisor-footer,
),
date: [#values.month.at(month) #current-date.display("[year]")],
)
}
// intentional blank page
pagebreak(to: if use-binding { "odd" } else { none })
////////////////////////////////
// AIS assignment
assert(
assignment == none or type(assignment) == content,
message: "For final stage of your thesis, please provide an assignment PDF file as `image(\"my.pdf\")`.",
)
if style != "pagecount" and assignment == none {
page(
fill: tiling(size: (40pt, 40pt))[
#place(line(start: (0%, 0%), end: (100%, 100%), stroke: 2pt + red))
],
)[
#set text(30pt)
#set par(justify: true)
Don't forget to replace this page with your AIS assignment PDF by
specifying `image("assignment.pdf")` into `assignment` argument of the
template! Be careful, the assignment should be in PDF format, not just
an image.
Typst 0.14 supports inserting PDFs with embedded text!
]
} else if style != "pagecount" {
set page(margin: 0em)
assignment
}
pagebreak()
pagebreak() // intentional blank page
////////////////////////////////
// cestne vyhlasenie
if style != "pagecount" {
v(1fr)
text(1.1em)[
Čestne vyhlasujem, že som túto prácu vypracoval(a) samostatne, na základe
konzultácií a s použitím uvedenej literatúry.
#v(1.5em)
// TODO: replace this with an appropriate Slovak date
#grid(
columns: (4fr, 3fr),
rows: 2,
gutter: 3pt,
align: (left, center),
row-gutter: .8em,
grid.cell(
rowspan: 2,
align: start,
current-date.display("V Bratislave, [day].[month].[year]"),
),
repeat("."),
author,
)
]
}
pagebreak()
pagebreak() // intentional blank page
////////////////////////////////
// acknowledgment
if style != "pagecount" and acknowledgment != none {
v(1fr)
par(text(1.5em)[ *#locale.acknowledgment* ])
text(1.1em)[
#acknowledgment
#v(1.5em)
]
pagebreak()
pagebreak() // intentional blank page
}
////////////////////////////////
// even if the language is Slovak, the university requires students to provide
// both versions of the abstract
////////////////////////////////
// slovak abstract
if style != "pagecount" {
abstract-page(
title: slovak.annotation.title,
university: slovak.university,
faculty: slovak.faculty,
program: (
left: slovak.title-page.fields.program,
right: slovak.title-page.values.program.informatics,
),
author: (left: slovak.annotation.author, right: author),
thesis: (left: slovak.title-page.values.thesis.at(thesis), right: title),
supervisor: supervisors-sk,
date: [#slovak.title-page.values.month.at(month) #(
current-date.display("[year]")
)],
abstract.sk,
)
}
pagebreak() // intentional blank page
////////////////////////////////
// english abstract
if style != "pagecount" {
abstract-page(
title: english.annotation.title,
university: english.university,
faculty: english.faculty,
program: (
left: english.title-page.fields.program,
right: english.title-page.values.program.informatics,
),
author: (left: english.annotation.author, right: author),
thesis: (left: english.title-page.values.thesis.at(thesis), right: title),
supervisor: supervisors-en,
date: [#english.title-page.values.month.at(month) #(
current-date.display("[year]")
)],
abstract.en,
)
}
pagebreak() // intentional blank page
////////////////////////////////
// table of contents
set par(
first-line-indent: first-line-indent,
justify: true,
leading: leading,
spacing: spacing,
)
set page(
numbering: "i",
number-align: center,
margin: page-margins,
header: header,
footer-descent: footer-descent,
header-ascent: header-ascent,
footer: footer-with-bound-numbering,
) // Roman numbering until the end of the contents
set text(
size: text-size,
)
show outline.entry.where(
level: 1,
): it => {
if it.element.func() == heading {
// outline entry for the contents
set block(above: 1.8em)
show text: it => strong(it)
link(
it.element.location(),
it.indented(it.prefix(), [#it.body()#h(1fr)#it.page()]),
)
} else {
// outline entry for lists of figures
link(
it.element.location(),
it.indented(strong(it.prefix()), it.inner()),
)
}
}
show outline.entry: set block(above: 1.2em)
outline(title: locale.contents.title, depth: 3, indent: auto)
if figures-outline {
outline(title: locale.contents.figures, target: figure.where(kind: image))
}
if tables-outline {
outline(title: locale.contents.tables, target: figure.where(kind: table))
}
if abbreviations-outline.len() > 0 and style != "pagecount" {
list-of-abbreviations(
title: locale.contents.abbreviations,
abbreviations: abbreviations-outline,
use-binding: use-binding,
)
}
set page(numbering: none, margin: page-margins)
v(1fr) // if the page is full, this will be a pagebreak
pagebreak(weak: true) // if the page is not full, this will be a pagebreak
counter(page).update(1) // start of the main section
////////////////////////////////
// main body
set par(
first-line-indent: first-line-indent,
justify: true,
leading: leading,
spacing: spacing,
)
set page(
numbering: "1",
number-align: center,
margin: page-margins,
header: header,
footer-descent: footer-descent,
header-ascent: header-ascent,
footer: footer-with-bound-numbering,
)
////////////////////////////////
// assertions
context if thesis == "bp2" or thesis == "dp3" {
// resume and plan of work are mandatory for the final theses
let resume = query(
heading.where(level: 1).and(<resume>),
)
let plan-of-work = query(
heading.where(level: 1).and(<plan-of-work>),
)
assert(
resume.len() == 1 and resume.at(0).numbering == none or lang == "sk",
message: "Could not find <resume> label in your work. Please create a resume chapter in Slovak and mark it with the <resume> label.",
)
assert(
lang != "sk" or resume.len() == 0,
message: "Theses in Slovak should not have a resume. If for some reason you need to have it, remove the <resume> label from its heading.",
)
assert(
plan-of-work.len() == 1,
message: "Could not find <plan-of-work> label in your work. Please create a plan of work appendix and mark it with the <plan-of-work> label.",
)
assert(
plan-of-work.at(0).numbering == _appendix-numbering,
message: "The plan of work (<plan-of-work> label) should be an appendix. Check if its numbering is right, did you forget to use `#show: section-appendices.with()`?",
)
}
assert(
abstract.keys().contains("sk") and abstract.keys().contains("en"),
message: "Please provide an abstract in both Slovak and English language",
)
assert(
locale.title-page.values.thesis.keys().contains(thesis),
message: "The thesis type you provided is not supported. Please contact the authors or choose one of the supported types",
)
if type(supervisor) != str {
assert(
type(supervisor) == dictionary,
message: "Please provide correct supervisor argument: either a string, or localized array of pairs (\"position\", \"name\").",
)
assert(
supervisor.keys().len() == 2
and supervisor.keys().contains("sk")
and supervisor.keys().contains("en")
and type(supervisor.sk) == array
and type(supervisor.en) == array,
message: "Please provide correct localization dictionary. Example: `(sk: <array>, en: <array>)`",
)
assert(
supervisor.sk.len() == supervisor.en.len(),
message: "Supervisor localizations don't match! Number of supervisors differs in localizations.",
)
for pair in supervisor.sk + supervisor.en {
assert(
type(pair) == array,
message: "Please provide correct supervisor argument: one or more pairs are not arrays.
Tip: if you have only one pair in the array, add a comma (,) after that element. Example: `supervisor: ((\"a\", \"b\"),)`",
)
assert(
pair.len() == 2,
message: "Please provide correct supervisor argument: one or more pairs do not have exactly 2 elements.",
)
assert(
type(pair.at(0)) == str and type(pair.at(1)) == str,
message: "Please provide correct supervisor argument: one or more pairs contain elements that are not strings.",
)
}
}
assert(
type(abbreviations-outline) == array,
message: "Please provide correct abbreviations-outline argument: either a string, or an array of pairs (\"abbreviation\", \"explanation\").",
)
for pair in abbreviations-outline {
assert(
type(pair) == array,
message: "Please provide correct abbreviations-outline argument: one or more pairs are not arrays.
Tip: if you have only one pair in the array, try to add a comma (,) after that element. Example: `abbreviations-outline: ((\"a\", \"b\"),)`",
)
assert(
pair.len() == 2,
message: "Please provide correct abbreviations-outline argument: one or more pairs do not have exactly 2 elements.",
)
assert(
(type(pair.at(0)) == str or type(pair.at(0)) == content)
and (type(pair.at(1)) == str or type(pair.at(1)) == content),
message: "Please provide correct abbreviations-outline argument: one or more pairs contain elements that are not strings or content.",
)
}
assert(
type(style) == str
and (
style == "regular"
or style == "compact"
or style == "legacy"
or style == "legacy-noncompliant"
or style == "pagecount"
),
message: "Please provide correct style of your thesis, possible options are: \"regular\", \"compact\", \"legacy\", \"legacy-noncompliant\" and \"pagecount\".",
)
body
}
// functions that are used in the thesis
#let section-appendices(body) = {
let appendix-page-numbering(first, ..) = [
// here, we don't need the `context` block. If we introduce it, it's going
// to make outline entries dirty: it will assume that we need to use
// current context, instead of the chapter's context
#numbering(_appendix-numbering, counter(heading).get().at(0))-#first
]
set page(numbering: appendix-page-numbering)
// get the supplement from state
// since getting a state value requires context, wrap the supplement into a
// function
set heading(numbering: _appendix-numbering, supplement: context {
let locale = localization(lang: _lang.get())
if _style.get() == "legacy" or _style.get() == "legacy-noncompliant" {
locale.legacy-appendix
} else { locale.appendix }
})
counter(heading).update(0)
// appendices don't add up to page count
show text: it => context if _style.get() == "pagecount" { none } else { it }
body
}
#let resume(body) = {
pagebreak()
context {
let locale = localization(lang: _lang.get())
set heading(numbering: none)
[
= Resumé <resume>
]
}
body
}