-
Notifications
You must be signed in to change notification settings - Fork 13
/
glossary-lib.typ
42 lines (33 loc) · 1.07 KB
/
glossary-lib.typ
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
#import "locale.typ": GLOSSARY
#import "shared-lib.typ": display, display-link
#let prefix = "glossary-state-"
#let glossary-state = state("glossary", none)
#let init-glossary(glossary) = {
glossary-state.update(glossary)
}
// Display acronym. Expands it if used for the first time
#let gls(element, link: true) = {
display("glossary", glossary-state, element, element, link: link)
}
// Print an index of all the acronyms and their definitions.
#let print-glossary(language, glossary-spacing) = {
heading(level: 1, outlined: false, numbering: none)[#GLOSSARY.at(language)]
glossary-state.display(glossary => {
let glossary-keys = glossary.keys()
let max-width = 0pt
for key in glossary-keys {
let result = measure(key).width
if (result > max-width) {
max-width = result
}
}
let glossary-list = glossary-keys.sorted()
for element in glossary-list {
grid(
columns: (max-width + 1em, auto),
gutter: glossary-spacing,
[*#element#label("glossary-" + element)*], [#glossary.at(element)],
)
}
})
}