Hey guys, thank you very much for your answers. I actually ended up adjusting the code that @quachpas linked to to fit my needs. The code is super long, so I wrapped it into a function which I can import from a dedicted glossary.typ file. Here’s the code in its entirety for anyone interested. glossarium-default.typ is also taken from the glossarium repo.
#import "deps.typ"
#import deps.glossarium: make-glossary, print-glossary, register-glossary
#import "assets/glossarium-default.typ": *
#import "globals.typ": text-size
#let glossary(
lang-map,
latin-symbols: (),
greek-symbols: (),
abbreviations: (),
) = {
heading()[#lang-map.at("sym-abb-title")]
let symbols = latin-symbols + greek-symbols
show: make-glossary
register-glossary(symbols)
register-glossary(abbreviations)
// Definitions for the tables
let show-all = false
let left-padding = 0.7cm
let tbl-stroke = 0.5pt
let tbl-sym-top-space = -1.135em
let tbl-abb-top-space = 1.21em
let tbl-row1-inset-bottom = -0.09em
let tbl-inset-top = 0.79em
let tbl-inset-bottom = 1.272em
let left-col-width = 3.37cm
let desc-col-width = 9.84cm
// Styling of tables
show table: set text(size: text-size)
set table(
stroke: (_, y) => (
bottom: if y == 0 { tbl-stroke },
),
align: left + top,
)
// Move the whole table to the right a bit
show table: it => { pad(left: left-padding)[#it] }
show table.cell.where(y: 0): set text(weight: "bold")
show table.cell.where(y: 0): set block(inset: (bottom: tbl-row1-inset-bottom))
// Symbols
v(tbl-sym-top-space)
// Original code from https://github.com/typst-community/glossarium/blob/785e0dbebfa44b5cae844e5e11437157be888f6e/tests/glossary-table/test.typ, adjusted to fit the needs of the template
print-glossary(
show-all: show-all,
deduplicate-back-references: true,
description-separator: none,
user-print-glossary: (entries, groups, ..kwargs) => {
kwargs = kwargs.named()
let user-print-gloss = kwargs.at("user-print-gloss")
let show-all = kwargs.at("show-all")
let minimum-refs = kwargs.at("minimum-refs")
for kw in (
// remove unused kwargs for user-print-gloss
"group-heading-level",
"group-sortkey",
"entry-sortkey",
"user-print-reference",
"user-print-group-heading",
"user-group-break",
"user-print-gloss",
) {
_ = kwargs.remove(kw)
}
table(
columns: (left-col-width, 1fr, desc-col-width),
table.header(..lang-map.at("sym-tbl-header")),
..for group in groups {
let group-entries = entries.filter(x => x.at(GROUP) == group)
let group-ref-counts = group-entries.map(x => count-refs(x.at(KEY)))
let print-group = (
// ? group-heading-pagebreak Layout divergence if location is conditional on print-group
group != "" and (show-all == true or group-ref-counts.any(x => x >= minimum-refs))
)
(
// Group heading
..for entry in entries.filter(x => x.group == group) {
let display-entry = show-all == true or count-refs(entry.at(KEY)) >= minimum-refs
// If the entry is not used, make row's total height 0%+0pt
let inset = if display-entry { (top: tbl-inset-top, bottom: tbl-inset-bottom) } else { 0% + 0pt }
(
table.cell(inset: inset, {
if display-entry {
entry.short
}
}),
table.cell(inset: inset, {
[
// default-print-reference
#__glossarium_figure(
entry.at(KEY),
body: user-print-gloss(entry, ..kwargs),
)
// The line below adds a ref shorthand for plural form, e.g., "@term:pl"
#__glossarium_figure(entry.at(KEY) + ":pl")
// Same as above, but for capitalized form, e.g., "@Term"
// Skip if key is already capitalized
#if upper(entry.at(KEY).at(0)) != entry.at(KEY).at(0) {
[
#__glossarium_figure(
default-capitalize(entry.at(KEY)),
)
#__glossarium_figure(
default-capitalize(entry.at(KEY)) + ":pl",
)
]
}
]
}),
table.cell(inset: inset, {
if display-entry {
entry.long
}
}),
)
},
)
},
)
},
user-print-gloss: (entry, ..kwargs) => {
let show-all = kwargs.at("show-all")
let minimum-refs = kwargs.at("minimum-refs")
let user-print-back-references = kwargs.at("user-print-back-references")
let deduplicate-back-references = kwargs.at("deduplicate-back-references")
let display-entry = show-all == true or count-refs(entry.at(KEY)) >= minimum-refs
if display-entry {
table.cell(entry.description)
}
},
symbols,
)
v(tbl-abb-top-space)
// Abbreviations
print-glossary(
show-all: show-all,
deduplicate-back-references: true,
description-separator: none,
user-print-glossary: (entries, groups, ..kwargs) => {
kwargs = kwargs.named()
let user-print-gloss = kwargs.at("user-print-gloss")
let show-all = kwargs.at("show-all")
let minimum-refs = kwargs.at("minimum-refs")
for kw in (
// remove unused kwargs for user-print-gloss
"group-heading-level",
"group-sortkey",
"entry-sortkey",
"user-print-reference",
"user-print-group-heading",
"user-group-break",
"user-print-gloss",
) {
_ = kwargs.remove(kw)
}
table(
columns: (1fr, desc-col-width),
table.header(..lang-map.at("abb-tbl-header")),
..for group in groups {
let group-entries = entries.filter(x => x.at(GROUP) == group)
let group-ref-counts = group-entries.map(x => count-refs(x.at(KEY)))
let print-group = (
// ? group-heading-pagebreak Layout divergence if location is conditional on print-group
group != "" and (show-all == true or group-ref-counts.any(x => x >= minimum-refs))
)
(
// Group heading
..for entry in entries.filter(x => x.group == group) {
let display-entry = show-all == true or count-refs(entry.at(KEY)) >= minimum-refs
// If the entry is not used, make row's total height 0%+0pt
let inset = if display-entry { (top: tbl-inset-top, bottom: tbl-inset-bottom) } else { 0% + 0pt }
(
table.cell(inset: inset, {
if display-entry {
entry.short
}
}),
table.cell(inset: inset, {
[
// default-print-reference
#__glossarium_figure(
entry.at(KEY),
body: user-print-gloss(entry, ..kwargs),
)
// The line below adds a ref shorthand for plural form, e.g., "@term:pl"
#__glossarium_figure(entry.at(KEY) + ":pl")
// Same as above, but for capitalized form, e.g., "@Term"
// Skip if key is already capitalized
#if upper(entry.at(KEY).at(0)) != entry.at(KEY).at(0) {
[
#__glossarium_figure(
default-capitalize(entry.at(KEY)),
)
#__glossarium_figure(
default-capitalize(entry.at(KEY)) + ":pl",
)
]
}
]
}),
)
},
)
},
)
},
user-print-gloss: (entry, ..kwargs) => {
let show-all = kwargs.at("show-all")
let minimum-refs = kwargs.at("minimum-refs")
let user-print-back-references = kwargs.at("user-print-back-references")
let deduplicate-back-references = kwargs.at("deduplicate-back-references")
let display-entry = show-all == true or count-refs(entry.at(KEY)) >= minimum-refs
if display-entry {
table.cell(entry.long)
}
},
abbreviations,
)
}