diff --git a/glossy/src/gloss.typ b/glossy/src/gloss.typ index 82e23fb..055a294 100644 --- a/glossy/src/gloss.typ +++ b/glossy/src/gloss.typ @@ -210,7 +210,7 @@ // content: The fully formatted term, including optional article, capitalization, // usage tracking metadata, and the chosen form (short, long, or both). // -#let __gls(key, modifiers: array, format-term: function, show-term: function, term-links: true) = { +#let __gls(key, modifiers: array, format-term: function, show-term: function, term-links: true, display-text: none) = { // --------------------------------------------------------------------------- // Check for illegal modifier combinations // --------------------------------------------------------------------------- @@ -355,8 +355,14 @@ let long-form = pluralize_term(entry.long, entry.longplural) // `none` safe here // Apply format-term() to get the term - let formatted-term = format-term(mode, short-form, long-form) - if type(formatted-term) != str { + let formatted-term = if display-text != none and display-text != auto { + // Display text was overriden by user, just accept it (string or content) + display-text + } else { + // Normal display (ie no override from user) + format-term(mode, short-form, long-form) + } + if "cap" in modifiers and type(formatted-term) != str { // This is because we still need to capitalize the term, and we cannot do // that with content, thus requiring a string here. // TODO: consider if we want to capitalize *before* this. First intuition is @@ -526,6 +532,7 @@ // Set up reference handling for glossary terms show ref: r => { let (raw_key, ..raw_modifiers) = str(r.target).split(":") + let supplement = r.supplement // used for term display overrides // Determine if we need to swap the key and first modifier. // Conditions for swapping: @@ -545,7 +552,7 @@ // Now see if this is an actual glossary term key if __has_entry(key) { // Found in dictionary, render via __gls() - __gls(key, modifiers: modifiers.map(lower), format-term: format-term, show-term: show-term, term-links: term-links) + __gls(key, modifiers: modifiers.map(lower), format-term: format-term, show-term: show-term, term-links: term-links, display-text: supplement) } else { // Not one of ours, so just pass it through r diff --git a/glossy/tests/override-display/ref/1.png b/glossy/tests/override-display/ref/1.png new file mode 100644 index 0000000..d077037 Binary files /dev/null and b/glossy/tests/override-display/ref/1.png differ diff --git a/glossy/tests/override-display/test.typ b/glossy/tests/override-display/test.typ new file mode 100644 index 0000000..e5a01b3 --- /dev/null +++ b/glossy/tests/override-display/test.typ @@ -0,0 +1,33 @@ +#import "/lib.typ": * + +#let myGlossary = ( + html: ( + short: "HTML", + long: "Hypertext Markup Language", + description: "A standard language for creating web pages", + group: "Web"), + css: ( + short: "CSS", + long: "Cascading Style Sheets", + description: "A language used for describing the presentation of a document", + group: "Web"), + tps: ( + short: "TPS", + long: "test procedure specification", + description: "A document on how to run all the test procedures"), + unused: "Unused term, which shouldn't print in the glossary." +) + +#show: init-glossary.with(myGlossary) + +#set page(height: auto, width: 6.5in, margin: 1em, numbering: "1") + += Overriding term display + +Here is @html[HTML being overidden]. + +Here is @css[] (blank). + +Here is @tps[TPS with #emph("content")] + +#glossary()