Now I feel more confident it what needs to be changed. The only thing I don’t like is “key” and “long”. I would use something like maybe “first”/“second” or “from”/“to”.
#let print-glossary(entry-list) = for entry in entry-list {
show: block.with(spacing: 1em)
strong(entry.key)
h(.3em)
emph(entry.long)
if entry.description != none [: #entry.description]
"."
}
/// Swaps key/long (English/Latin) values. Sorts by Latin.
#let glossary-english-to-latin(glossary-data) = {
glossary-data
.map(entry => array
.zip(entry.long, entry.description)
.map(((long, description)) => (
(
key: long,
long: entry.key,
description: if description != [] [#description],
),
)))
.flatten()
.sorted(key: entry => entry.key)
}
/// Doesn't swap key/long (English/Latin) values. Sorts by English.
#let glossary-latin-to-english(glossary-data) = {
glossary-data
.map(entry => array
.zip(entry.long, entry.description)
.map(((long, description)) => (
(
key: entry.key,
long: long,
description: if description != [] [#description],
),
)))
.flatten()
.sorted(key: entry => entry.key)
}
#let glossary-data = (
(
key: "Foo",
long: ("Lorem", "Ipsum"),
description: ([Comment A1], [Comment A2]),
),
(
key: "Bar",
long: ("Dolor",),
description: ([Comment B],),
),
)
#let english-to-latin-glossary = glossary-english-to-latin(glossary-data)
#let latin-to-english-glossary = glossary-latin-to-english(glossary-data)
=== English to Latin
#print-glossary(english-to-latin-glossary)
=== Latin to English
#print-glossary(latin-to-english-glossary)
So, basically, we have the same input data, but then it’s passed through a processing function that spits out ready-to-print data. If you don’t need to access it, then just do
=== English to Latin
#print-glossary(glossary-english-to-latin(glossary-data))
=== Latin to English
#print-glossary(glossary-latin-to-english(glossary-data))
Inside, a lot of array methods were used in chains. For each entry, we go through a pair of long + description and make a new dictionary. Then sort by key and print.
