Skip to content

Commit

Permalink
Add option use-key-as-short for register-glossary
Browse files Browse the repository at this point in the history
  • Loading branch information
quachpas committed Dec 20, 2024
1 parent 8f42432 commit 7ea2f6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
7 changes: 7 additions & 0 deletions tests/debug/debug.typ
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,11 @@ false: #context there-are-refs(groups: (" ",))

#default-print-reference.with(show-all: true)(entry-list-2.last())

== Test use-key-as-short

#let entry-list-6 = ((key: "potato-use-key-as-short"),)
#register-glossary(entry-list-6)
#print-glossary(entry-list-6)
@potato-use-key-as-short

]
16 changes: 9 additions & 7 deletions themes/default.typ
Original file line number Diff line number Diff line change
Expand Up @@ -508,18 +508,19 @@
//
// # Arguments
// entry-list (array<dictionary>): the list of entries
// use-key-as-short (bool): flag to use the key as the short form
//
// # Returns
// The normalized entry list
#let __normalize_entry_list(entry-list) = {
#let __normalize_entry_list(entry-list, use-key-as-short: true) = {
let new-list = ()
for entry in entry-list {
if not has-short(entry) and not has-long(entry) {
if not use-key-as-short and not has-short(entry) and not has-long(entry) {
panic(__error_message(entry.key, __entry_has_neither_short_nor_long))
}
new-list.push((
key: entry.key,
short: entry.at("short", default: ""),
short: entry.at("short", default: if use-key-as-short { entry.key } else { "" }),
artshort: entry.at("artshort", default: "a"),
plural: entry.at("plural", default: ""),
long: entry.at("long", default: ""),
Expand Down Expand Up @@ -914,17 +915,18 @@
})
}

// register-glossary(entry-list) -> none
// register-glossary(entry-list, use-key-as-short: true) -> none
// Register the glossary entries
//
// # Arguments
// entries (array<dictionary>): the list of entries
#let register-glossary(entry-list) = {
// entries (array<dictionary>): the list of entries
// use-key-as-short (bool): flag to use the key as the short form
#let register-glossary(entry-list, use-key-as-short: true) = {
if sys.version <= version(0, 11, 1) {
return
}
// Normalize entry-list
let entries = __normalize_entry_list(entry-list)
let entries = __normalize_entry_list(entry-list, use-key-as-short: use-key-as-short)

__update_glossary(entries)
}
Expand Down

0 comments on commit 7ea2f6f

Please sign in to comment.