|
115 | 115 | // key (str): the key of the term
|
116 | 116 | //
|
117 | 117 | // # Returns
|
118 |
| -// The entry of the term |
119 |
| -// |
120 |
| -// # Panics |
121 |
| -// If the key is not found, it will raise a `key_not_found` error |
| 118 | +// The entry of the term or `none` |
122 | 119 | #let __get_entry_with_key(loc, key) = {
|
123 | 120 | let entries = if sys.version <= version(0, 11, 1) {
|
124 | 121 | __glossary_entries.final()
|
|
128 | 125 | if key in entries {
|
129 | 126 | return entries.at(key)
|
130 | 127 | } else {
|
131 |
| - panic(__error_message(key, __key_not_found)) |
| 128 | + return none |
132 | 129 | }
|
133 | 130 | }
|
134 | 131 |
|
|
264 | 261 | // The link and the entry label
|
265 | 262 | #let gls(key, suffix: none, long: none, display: none, update: true, capitalize: false) = context {
|
266 | 263 | let entry = __get_entry_with_key(here(), key)
|
| 264 | + if entry == none { |
| 265 | + panic(__error_message(key, __key_not_found)) |
| 266 | + } |
267 | 267 |
|
268 | 268 | // Attributes
|
269 | 269 | let ent-long = entry.at("long", default: "")
|
|
335 | 335 | // The link and the entry label
|
336 | 336 | #let agls(key, suffix: none, long: none, update: true) = context {
|
337 | 337 | let entry = __get_entry_with_key(here(), key)
|
| 338 | + if entry == none { |
| 339 | + panic(__error_message(key, __key_not_found)) |
| 340 | + } |
338 | 341 |
|
339 | 342 | // Attributes
|
340 | 343 | let ent-long = entry.at("long", default: "")
|
|
384 | 387 | #let glspl(key, long: none, update: true, capitalize: false) = context {
|
385 | 388 | let default-plural-suffix = "s"
|
386 | 389 | let entry = __get_entry_with_key(here(), key)
|
| 390 | + if entry == none { |
| 391 | + panic(__error_message(key, __key_not_found)) |
| 392 | + } |
387 | 393 |
|
388 | 394 | // Attributes
|
389 | 395 | let ent-short = entry.at("short", default: "")
|
|
456 | 462 | // The attribute of the term
|
457 | 463 | #let __gls_attribute(key, attr, link: false, update: false) = context {
|
458 | 464 | let entry = __get_entry_with_key(here(), key)
|
| 465 | + if entry == none { |
| 466 | + panic(__error_message(key, __key_not_found)) |
| 467 | + } |
| 468 | + |
459 | 469 | if link {
|
460 | 470 | return __link_and_label(entry.key, entry.at(attr), update: update)
|
461 | 471 | } else if attr in entry and entry.at(attr) != none {
|
|
584 | 594 | if (
|
585 | 595 | r.element != none and r.element.func() == figure and r.element.kind == __glossarium_figure
|
586 | 596 | ) {
|
| 597 | + let position = r.element.location() |
587 | 598 | // call to the general citing function
|
588 | 599 | let key = str(r.target)
|
589 | 600 | if key.ends-with(":pl") {
|
590 | 601 | // Plural ref
|
591 |
| - glspl(str(key).slice(0, -3), update: update) |
| 602 | + let singular_key = str(key).slice(0, -3) |
| 603 | + if __get_entry_with_key(position, singular_key) != none { |
| 604 | + return glspl(singular_key, update: update) |
| 605 | + } |
| 606 | + let lower_case_key = lower(singular_key.first()) + singular_key.slice(1) |
| 607 | + if __get_entry_with_key(position, lower_case_key) != none { |
| 608 | + return glspl(lower_case_key, update: update, capitalize: true) |
| 609 | + } |
592 | 610 | } else {
|
593 | 611 | // Default ref
|
594 |
| - gls(str(key), suffix: r.citation.supplement, update: update) |
| 612 | + let _key = str(key) |
| 613 | + if __get_entry_with_key(position, _key) != none { |
| 614 | + return gls(_key, suffix: r.citation.supplement, update: update) |
| 615 | + } |
| 616 | + let lower_case_key = lower(_key.first()) + _key.slice(1) |
| 617 | + if __get_entry_with_key(position, lower_case_key) != none { |
| 618 | + return gls(lower_case_key, suffix: r.citation.supplement, update: update, capitalize: true) |
| 619 | + } |
595 | 620 | }
|
| 621 | + |
| 622 | + panic(__error_message(key, __key_not_found)) |
596 | 623 | } else {
|
597 |
| - r |
| 624 | + return r |
598 | 625 | }
|
599 | 626 | }
|
600 | 627 |
|
|
852 | 879 | kind: __glossarium_figure,
|
853 | 880 | supplement: "",
|
854 | 881 | )[]#label(entry.key + ":pl")
|
| 882 | + // Same as above, but for capitalized form, e.g., "@Term" |
| 883 | + #if upper(entry.key.first()) != entry.key.first() { |
| 884 | + [ |
| 885 | + #figure( |
| 886 | + kind: __glossarium_figure, |
| 887 | + supplement: "", |
| 888 | + )[]#label(__capitalize(entry.key)) |
| 889 | + #figure( |
| 890 | + kind: __glossarium_figure, |
| 891 | + supplement: "", |
| 892 | + )[]#label(__capitalize(entry.key) + ":pl") |
| 893 | + ] |
| 894 | + } |
855 | 895 | ]
|
856 | 896 |
|
857 | 897 | // default-group-break() -> content
|
|
0 commit comments