diff --git a/docs/main.pdf b/docs/main.pdf index 3e9bb0e..02d60df 100644 Binary files a/docs/main.pdf and b/docs/main.pdf differ diff --git a/examples/full-example/main.pdf b/examples/full-example/main.pdf index 15f9499..f6c626d 100644 Binary files a/examples/full-example/main.pdf and b/examples/full-example/main.pdf differ diff --git a/examples/full-example/main.typ b/examples/full-example/main.typ index b0a17bc..49f8a3e 100644 --- a/examples/full-example/main.typ +++ b/examples/full-example/main.typ @@ -1,4 +1,4 @@ -#import "../../glossarium.typ": make-glossary, print-glossary, gls, glspl, agls, gls-key, gls-short, gls-plural, gls-long, gls-longplural, gls-description, gls-group +#import "../../glossarium.typ": make-glossary, print-glossary, gls, glspl, agls, gls-key, gls-short, gls-artshort, gls-plural, gls-long, gls-artlong, gls-longplural, gls-description, gls-group // Replace the local import with a import to the preview namespace. // If you don't know what that mean, please go read typst documentation on how to import packages at https://typst.app/docs/packages/. #show: make-glossary @@ -26,8 +26,10 @@ You can also override the text shown by setting the `display` argument: #gls("ku Attributes of an entry can be retrieved using the available functions: - `gls-key("kuleuven")`: #gls-key("kuleuven") - `gls-short("kuleuven")`: #gls-short("kuleuven") +- `gls-artshort("kuleuven")`: #gls-artshort("kuleuven") - `gls-plural("kuleuven")`: #gls-plural("kuleuven") - `gls-long("kuleuven")`: #gls-long("kuleuven") +- `gls-artlong("kuleuven")`: #gls-artlong("kuleuven") - `gls-longplural("kuleuven")`: #gls-longplural("kuleuven") - `gls-description("kuleuven")`: #gls-description("kuleuven") - `gls-group("kuleuven")`: #gls-group("kuleuven") @@ -40,11 +42,8 @@ where the page is in the document and not the textual representation. #pagebreak() -At the moment, customization is not built-in to the function and instead follows -a modified version of @ughent's template. But you can easily customize it by -modifying `glossary.typ`. It is short enough and well documented enough to be -easily understood. Additionally, you can load data externally and pass it as a -parameter to the `glossary.with` function to load data from an external format. +Additionally, you can load data externally and pass it as a parameter to the +`glossary.with` function to load data from an external format. #pagebreak() @@ -97,12 +96,23 @@ parameter to the `glossary.with` function to load data from an external format. long: "Université de Liège", description: "Tempor deserunt commodo reprehenderit eiusmod enim. Ut ullamco deserunt in elit commodo ipsum nisi voluptate proident culpa. Sunt do mollit velit et et amet consectetur tempor proident Lorem. Eu officia amet do ea occaecat velit fugiat qui tempor sunt aute. Magna Lorem veniam duis ea eiusmod labore non anim labore irure culpa Lorem dolor officia. Laboris reprehenderit eiusmod nostrud duis excepteur nisi officia.", ), - (key: "unamur", short: "UNamur", long: "Université de Namur"), + ( + key: "unamur", + short: "UNamur", + long: "Université de Namur" + ), + ( + key: "lod", + short: "LOD", + artshort: "an", + long: "level of details", + description: lorem(10), + ), ( key: "notused", short: "Not used", - description: [This key is not cited anywhere, it won't be in the glossary unless the - `show-all` argument is set to true], + description: [This key is not cited anywhere, it won't be in the glossary unless the + `show-all` argument is set to true], ), ), // show all term even if they are not referenced, default to true diff --git a/examples/groups/groups.pdf b/examples/groups/groups.pdf index 1bf894f..b30bbac 100644 Binary files a/examples/groups/groups.pdf and b/examples/groups/groups.pdf differ diff --git a/examples/import-terms-from-yaml-file/main.pdf b/examples/import-terms-from-yaml-file/main.pdf index f592107..08c7617 100644 Binary files a/examples/import-terms-from-yaml-file/main.pdf and b/examples/import-terms-from-yaml-file/main.pdf differ diff --git a/examples/plural-example/main.pdf b/examples/plural-example/main.pdf index 3e270d0..3acb782 100644 Binary files a/examples/plural-example/main.pdf and b/examples/plural-example/main.pdf differ diff --git a/glossarium.typ b/glossarium.typ index 749d65d..059cadb 100644 --- a/glossarium.typ +++ b/glossarium.typ @@ -118,22 +118,28 @@ return attr != "" and attr != [] } #let has-long(entry) = __has_attribute(entry, "long") +#let has-artshort(entry) = __has_attribute(entry, "artshort") #let has-plural(entry) = __has_attribute(entry, "plural") +#let has-long(entry) = __has_attribute(entry, "long") +#let has-artlong(entry) = __has_attribute(entry, "artlong") #let has-longplural(entry) = __has_attribute(entry, "longplural") #let has-description(entry) = __has_attribute(entry, "description") #let has-group(entry) = __has_attribute(entry, "group") + -// __link_and_label(key, text) -> contextual content +// __link_and_label(key, text, prefix: none, suffix: none) -> contextual content // Build a link and a label // // # Arguments // key (str): the key of the term -// text (str): the text to be displayed +// text (content): the text to be displayed +// prefix (str|content): the prefix to be added to the label +// suffix (str|content): the suffix to be added to the label // // # Returns // The link and the entry label -#let __link_and_label(key, text) = context { - return [#link(label(key), text)#label(__glossary_label_prefix + key)] +#let __link_and_label(key, text, prefix: none, suffix: none) = context { + return [#prefix#link(label(key), text)#suffix#label(__glossary_label_prefix + key)] } // gls(key, suffix: none, long: none, display: none) -> contextual content @@ -187,32 +193,43 @@ } } +// agls(key, suffix: none, long: none) -> contextual content +// Reference to term with article +// +// # Arguments +// key (str): the key of the term +// suffix (str|content): the suffix to be added to the short form +// long (bool): enable/disable the long form +// +// # Returns +// The link and the entry label #let agls(key, suffix: none, long: none) = { context { - let __glossary_entries = __glossary_entries.final(here()) - if key in __glossary_entries { - let entry = __glossary_entries.at(key) - - let gloss = __query_labels_with_key(here(), key, before: true) - - let is_first = gloss == () - let entlong = entry.at("long", default: "") - let textLink = if (is_first or long == true) and entlong != [] and entlong != "" and long != false { - [#entlong (#entry.short#suffix)] - } else { - [#entry.short#suffix] - } - - let article = if (is_first or long == true) and entlong != [] and entlong != "" and long != false { - entry.at("artlong", default: "a") - } else { - entry.at("artshort", default: "a") - } - - [#article #link(label(entry.key), textLink)#label(__glossary_label_prefix + entry.key)] - } else { - panic(__not-found-panic-error-msg(key)) + let entry = __get_entry_with_key(here(), key) + + // Attributes + let ent-long = entry.at("long", default: "") + let ent-short = entry.at("short", default: "") + let ent-artlong = entry.at("artlong", default: "a") + let ent-artshort = entry.at("artshort", default: "a") + + // Conditions + let is-first-or-long = __is_first_or_long(here(), key, long: long) + let has-long = has-long(entry) + + // Link text + let link-text = none + let article = none + if is-first-or-long and has-long and long != false { + link-text = [#ent-long (#ent-short#suffix)] + article = ent-artlong + } else { // Default to short + link-text = [#entry.short#suffix] + article = ent-artshort } + + // Return + return __link_and_label(entry.key, link-text, prefix: [#article ]) } } @@ -289,7 +306,7 @@ } } -// gls-key(key) -> str +// gls-key(key, link: false) -> str // Get the key of the term // // # Arguments @@ -300,7 +317,7 @@ // The key of the term #let gls-key(key, link: false) = __gls_attribute(key, "key", link: link) -// gls-short(key) -> str +// gls-short(key, link: false) -> str // Get the short form of the term // // # Arguments @@ -311,7 +328,18 @@ // The short form of the term #let gls-short(key, link: false) = __gls_attribute(key, "short", link: link) -// gls-plural(key) -> str|content +// gls-artshort(key, link: false) -> str|content +// Get the article of the short form +// +// # Arguments +// key (str): the key of the term +// link (bool): enable link to glossary +// +// # Returns +// The article of the short form +#let gls-artshort(key, link: false) = __gls_attribute(key, "artshort", link: link) + +// gls-plural(key, link: false) -> str|content // Get the plural form of the term // // # Arguments @@ -322,7 +350,7 @@ // The plural form of the term #let gls-plural(key, link: false) = __gls_attribute(key, "plural", link: link) -// gls-long(key) -> str|content +// gls-long(key, link: false) -> str|content // Get the long form of the term // // # Arguments @@ -333,7 +361,18 @@ // The long form of the term #let gls-long(key, link: false) = __gls_attribute(key, "long", link: link) -// gls-longplural(key) -> str|content +// gls-artlong(key, link: false) -> str|content +// Get the article of the long form +// +// # Arguments +// key (str): the key of the term +// link (bool): enable link to glossary +// +// # Returns +// The article of the long form +#let gls-artlong(key, link: false) = __gls_attribute(key, "artlong", link: link) + +// gls-longplural(key, link: false) -> str|content // Get the long plural form of the term // // # Arguments @@ -344,7 +383,7 @@ // The long plural form of the term #let gls-longplural(key, link: false) = __gls_attribute(key, "longplural", link: link) -// gls-description(key) -> str|content +// gls-description(key, link: false) -> str|content // Get the description of the term // // # Arguments