From 418992d27fb9de50e77438cfd887b6dd870d8d9b Mon Sep 17 00:00:00 2001 From: servostar Date: Wed, 14 Aug 2024 11:57:27 +0200 Subject: [PATCH] changed glossarium format --- src/glossarium.typ | 34 ++++++++++++++++------------------ src/glossary.typ | 42 ++++++++++++++++++++++++++++-------------- src/lib.typ | 1 + template/glossary.yml | 6 +++++- template/main.typ | 2 +- 5 files changed, 51 insertions(+), 34 deletions(-) diff --git a/src/glossarium.typ b/src/glossarium.typ index 765d175..3784d18 100644 --- a/src/glossarium.typ +++ b/src/glossarium.typ @@ -171,22 +171,21 @@ SOFTWARE.*/ caption: { context { let term_references = __query_labels_with_key(here(), entry.key) - if term_references.len() != 0 or show-all { - let desc = entry.at("desc", default: "") - let long = entry.at("long", default: "") - let hasLong = long != "" and long != [] - let hasDesc = desc != "" and desc != [] - grid( - columns: 2, - column-gutter: 1em, - text(weight: "bold", entry.short), - { - if hasLong { - text(weight: "bold", entry.long) + if term_references.len() != 0 or show-all [ + #let desc = entry.at("desc", default: "") + #let long = entry.at("long", default: "") + #let hasLong = long != "" and long != [] + #let hasDesc = desc != "" and desc != [] + + #block( + par(hanging-indent: 1em)[ + #text(weight: "bold", entry.short) + #if hasLong { + text(entry.long) } - if hasLong and hasDesc [:] - if hasDesc [ #desc ] else [. ] - if disable-back-references != true { + #if hasLong and hasDesc [:] + #if hasDesc [ #desc ] + #if disable-back-references != true { term_references .map(x => x.location()) .sorted(key: x => x.page()) @@ -211,13 +210,12 @@ SOFTWARE.*/ ) .join(", ") } - }, + ], ) - } + ] } }, )[] #label(entry.key) - #parbreak() ] } } diff --git a/src/glossary.typ b/src/glossary.typ index d68e2c6..436b664 100644 --- a/src/glossary.typ +++ b/src/glossary.typ @@ -14,6 +14,8 @@ message: "The glossary is not a dictionary", ) + let processed_glossary = (:) + for (k, v) in entries.pairs() { assert( type(v) == dictionary, @@ -52,27 +54,39 @@ message: "The optional group of glossary entry `" + k + "` is not a string", ) } else { - let group = if "long" in v { - if (context text.lang) == "de" { - "Akronyme" - } else { - "Acronyms" - } + let acronym_group = if (context text.lang) == "de" { + "Akronyme" } else { - if (context text.lang) == "de" { - "Begriffe" - } else { - "Terms" - } + "Acronyms" } - entries.at(k).group = group + let glossary_group = if (context text.lang) == "de" { + "Begriffe" + } else { + "Glossary" + } + + let group = if "long" in v { + acronym_group + } else { + glossary_group + } + + // create dedicated entries for + // acronym and glossary + if "long" in v and "desc" in v { + processed_glossary.insert(k, (short: v.short, long: v.long, group: acronym_group)) + processed_glossary.insert(k + "__glossary_entry", (short: v.short, desc: v.desc, group: glossary_group)) + } else { + processed_glossary.insert(k, v) + processed_glossary.at(k).group = group + } } } - return entries.pairs().map(((key, entry)) => ( + return processed_glossary.pairs().map(((key, entry)) => ( key: key, - short: eval(entry.short, mode: "markup"), + short: entry.short, long: eval(entry.at("long", default: ""), mode: "markup"), desc: eval(entry.at("desc", default: ""), mode: "markup"), group: entry.at("group", default: ""), diff --git a/src/lib.typ b/src/lib.typ index fa32f1a..b2c0649 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -83,6 +83,7 @@ #if "glossary" in config.thesis and config.thesis.glossary != none { print-glossary( + show-all: true, disable-back-references: true, enable-group-pagebreak: true, glossary(config.thesis.glossary), diff --git a/template/glossary.yml b/template/glossary.yml index c45422f..60c8cfb 100644 --- a/template/glossary.yml +++ b/template/glossary.yml @@ -6,4 +6,8 @@ oidc: potato: short: potato - desc: "#lorem(50)" \ No newline at end of file + desc: "#lorem(50)" + +HTTP: + short: HTTP + long: Hyper Text Transfer Protocol diff --git a/template/main.typ b/template/main.typ index 2fcf44b..d5132dc 100644 --- a/template/main.typ +++ b/template/main.typ @@ -88,7 +88,7 @@ $ #pagebreak() #lorem(100) -#inline-color("#ff0000", "red") +#inline-color("#ff0000", "red") @HTTP #figure( ```rust