diff --git a/README.md b/README.md index ccc76fb..e3739fc 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,6 @@ After importing the package and before making any calls to `gls`,` print-glossar > >Therefore I recommend that you always put the `#show: ...` statement on the line just below the `#import` statement. - ### Printing the glossary First we have to define the terms. @@ -42,7 +41,7 @@ A term is a [dictionary](https://typst.app/docs/reference/types/dictionary/) com - `key` (string) *required, case-sensitive, unique*: used to reference the term. - `short` (string) *required*: the short form of the term replacing the term citation. - `long` (string or content) *optional*: The long form of the term, displayed in the glossary and on the first citation of the term. -- `desc` (string or content) *optional*: The description of the term. +- `description` (string or content) *optional*: The description of the term. - `plural` (string or content) *optional*: The pluralized short form of the term. - `longplural` (string or content) *optional*: The pluralized long form of the term. - `group` (string) *optional, case-sensitive*: The group the term belongs to. The terms are displayed by groups in the glossary. @@ -63,9 +62,9 @@ Then the terms are passed as a list to `print-glossary` key: "oidc", short: "OIDC", long: "OpenID Connect", - desc: [OpenID is an open standard and decentralized authentication protocol promoted by the non-profit + description: [OpenID is an open standard and decentralized authentication protocol promoted by the non-profit #link("https://en.wikipedia.org/wiki/OpenID#OpenID_Foundation")[OpenID Foundation].], - group: "Accronyms", + group: "Acronyms", ), // a term with a short plural @@ -74,7 +73,7 @@ Then the terms are passed as a list to `print-glossary` short: "potato", // "plural" will be used when "short" should be pluralized plural: "potatoes", - desc: [#lorem(10)], + description: [#lorem(10)], ), // a term with a long plural @@ -84,7 +83,7 @@ Then the terms are passed as a list to `print-glossary` long: "diagonal matrix", // "longplural" will be used when "long" should be pluralized longplural: "diagonal matrices", - desc: "Probably some math stuff idk", + description: "Probably some math stuff idk", ), ) ) @@ -94,10 +93,9 @@ By default, the terms that are not referenced in the document are not shown in t You can also disable the back-references by setting the parameter `disable-back-references` to `true`. -Group page breaks can be enable by setting the parameter `enable-group-pagebreak` to `true`. - -You can call this function from anywhere in you document. +By default, group breaks use `linebreaks`. This behaviour can be changed by setting the `user-group-break` parameter to `pagebreak()`, or `colbreak()`, or any other function that returns the `content` you want. +You can call this function from anywhere in your document. ### Referencing terms. diff --git a/docs/main.pdf b/docs/main.pdf new file mode 100644 index 0000000..02d60df Binary files /dev/null and b/docs/main.pdf differ diff --git a/docs/main.typ b/docs/main.typ new file mode 100644 index 0000000..8889baa --- /dev/null +++ b/docs/main.typ @@ -0,0 +1,449 @@ +#import "../glossarium.typ": * + +#show: make-glossary +#set page(paper: "a4") +#set heading(numbering: "1.") +#show link: set text(fill: red) +#let typc(body) = raw(body, lang: "typc") +#let typc-block(body) = rect(width: 100%, fill: gray.lighten(80%))[#set text(size: 9pt);#body] +#let entry-list = ( + ( + key: "WHO", + short: "WHO", + long: "World Health Organization", + description: lorem(5), + group: "Organizations", + ), + ( + key: "WTO", + short: "WTO", + long: "World Trade Organization", + description: lorem(5), + group: "Organizations", + ), + ( + key: "IMF", + short: "IMF", + long: "International Monetary Fund", + description: lorem(5), + ), + ( + key: "UN", + short: "UN", + long: "United Nations", + description: lorem(5), + ), + ( + key: "EU", + short: "EU", + long: "European Union", + description: lorem(5), + ), + ( + key: "USA", + short: "USA", + long: "United States of America", + description: lorem(5), + group: "Countries", + ), + ( + key: "UK", + short: "UK", + long: "United Kingdom", + description: lorem(5), + group: "Countries", + ), + ( + key: "UAE", + short: "UAE", + long: "United Arab Emirates", + description: lorem(5), + group: "Countries", + ), +) +#let entries = __normalize_entry_list(entry-list) +#let groups = entries.map(x => x.at("group")).dedup() + +#align(center)[`glossarium@`#glossarium_version] + +#outline(indent: 1em) + += Customization + +This section shows how to change the default behaviour of `glossarium` by +implementing user functions. It is recommended to keep to the user available +interface and not to change the default behaviour of the package. If you have +any suggestions or need help, please open an issue on the +#link("https://github.com/ENIB-Community/glossarium")[GitHub repository]. + +There are effectively two requirements for a user to use `glossarium`: ++ Write a #typc("show: make-glossary") rule to transform all + #typc("@key") and #typc("@key:pl") into #typc("#gls(key)") or + #typc("#glspl(key)") ++ Call #typc("print-glossary(entry-list)") somewhere in order to write all + labels + +The `glossarium` package provides a default behaviour to +#typc("print-glossary"). In ascending order, all implemented behaviours are: + ++ #typc("default-print-back-references(entry) -> contextual content") ++ #typc("default-print-description(entry) -> content") ++ #typc("default-print-title(entry) -> content") ++ #typc("default-print-gloss(entry, ...) -> contextual content") ++ #typc("default-print-reference(entry, ...) -> contextual content") ++ #typc("default-print-glossary(entries, groups, ...) -> contextual content") + +/ gloss: A *gloss* is a single entry in the glossary. It is composed of a + *title*, a *description*, and a list of *back references*. + +/ reference: A *reference* is the construct `glossarium` uses to manage the + glossary. Internally, it is constructed using #typc("figure()") and #typc("label()"). + +/ glossary: A *glossary* is the list of all glosses. It is composed of a list of + *entries* and a list of *groups*. The default *group* is #typc("\"\""). + +Each of these functions can be replaced by a user-defined function with the same +signature. Then, the user can pass them directly to #typc("print-glossary()"), +e.g., +#typc-block[ +```typc +let my-print-description(entry) = { + let ent-description = entry.at("description", default: "") + return text.with(size: 9pt)[#ent-description] +} +print-glossary(entry-list, user-print-description: my-print-description) +``` +] + +Keep in mind that some options are available from the start: +- `show-all (bool)` : show all entries, even if they are not referenced in the document +- `disable-back-references (bool)`: do not show back references +- `user-group-break (function: () => content)`: a function to call between groups + +== Default functions + +The functions are listed in order of reverse call hierarchy: ++ #typc("print-glossary(entry-list)") + + #typc("default-print-glossary(entries, groups)") + + #typc("default-print-reference(entry)") + + #typc("default-print-gloss(entry)") + + #typc("default-print-title(entry)") + + #typc("default-print-description(entry)") + + #typc("default-print-back-references(entry)") + + #typc("default-group-break()") + +#text.with(fill: red.darken(10%))([ + #emoji.warning Although #typc("default-print-reference") is available to the + user, it is not recommended to modify this function. +]) + +The full signatures for #typc("default-print-gloss()"), +#typc("default-print-reference()"), and +#typc("default-print-glossary()") in the next sections. + +=== Arguments + +The functions take the following arguments: ++ #typc("entries"): the normalized entry list ++ #typc("groups"): the list of groups ++ #typc("entry"): an entry + +This is one #typc("entry"): +#typc-block[ + #entries.first() +] + +#typc("groups") +#typc-block[ + #groups +] + +#typc("entries") +#typc-block[ + #entries.slice(0, 2) +] + +=== #typc("default-print-back-references(entry)") + +The default implementation is: + +#typc-block[ +```typc +#let default-print-back-references(entry) = { + return get-entry-back-references(entry).join(", ") +} +``` +] + +Without going into details, assume that +#typc("get-entry-back-references(entry)") returns a list of back references. The +function simply joins them with a comma. + +For example, for @WHO, the back references are: +#typc-block[#context get-entry-back-references(entries.first()).join(", ")] + +The value of #typc("get-entry-back-references(entry)") is: +#typc-block[#context get-entry-back-references(entries.first())] +where #typc("dest") contains a #typc("location"). + +=== #typc("default-print-description(entry)") + +The default implementation is: + +#typc-block[ +```typc +#let default-print-description(entry) = { + return entry.at("description") +} +``` +] + +=== #typc("default-print-title(entry)") + +The default implementation is: + +#typc-block[ +```typc +#let default-print-title(entry) = { + let caption = [] + let txt = text.with(weight: 600) + + if has-long(entry) { + caption += txt(emph(entry.short) + [ -- ] + entry.long) + } else { + caption += txt(emph(entry.short)) + } + return caption +} +``` +] + +The function is fairly simple to understand: +- If the entry has a long description, it returns #typc("text.with(weight: 600)[emph(entry.short) -- entry.long]") +- If the entry does not have a long description, it returns #typc("text.with(weight: 600)[emph(entry.short)]") + +=== #typc("default-print-gloss(entry)") + +The default implementation is +#typc-block[ +```typc +#let default-print-gloss( + entry, + show-all: false, + disable-back-references: false, + user-print-title: default-print-title, + user-print-description: default-print-description, + user-print-back-references: default-print-back-references, +) = context { + let caption = [] + + if show-all == true or count-refs(entry) != 0 { + // Title + caption += user-print-title(entry) + + // Description + if has-description(entry) { + // Title - Description separator + caption += ": " + + caption += user-print-description(entry) + } + + // Back references + if disable-back-references != true { + caption += " " + + caption += user-print-back-references(entry) + } + } + + return caption +} +``` +] + +- #typc("default-print-gloss") is responsible for printing separators between + the title, description, and back references. +- It also checks if the entry should be printed or not. If the entry is not + referenced in the document, it will not be printed unless #typc("show-all: + true"). +- If back references are disabled (#typc("disable-back-references: true")), they + will not be printed. + +The default behaviour will be displayed as such: +#typc-block[ + #default-print-gloss(entries.first()) +] + +Without back references: +#typc-block[ + #default-print-gloss(entries.first(), disable-back-references: true) +] + +For a non-referenced entry: +#typc-block[ + show-all: false => #default-print-gloss(entries.at(1)) + + show-all: true => #default-print-gloss(entries.at(2), show-all: true) +] + +One important utility function is #typc("count-refs"). For @WHO, +#typc("#context count-refs(entry)") is +#typc-block[ + #context count-refs(entries.first()) +] + +=== #typc("default-print-reference(entry)") + +#text.with(fill: red.darken(10%))([ + #emoji.warning There are few reasons to modify this function. It is recommended + to keep the default behaviour, but an override option is provided for advanced + users. +]) + +The default implementation is: +#typc-block[ +```typc +#let default-print-reference( + entry, + show-all: false, + disable-back-references: false, + user-print-gloss: default-print-gloss, + user-print-title: default-print-title, + user-print-description: default-print-description, + user-print-back-references: default-print-back-references, +) = { + return [ + #show figure.where(kind: __glossarium_figure): it => it.caption + #par( + hanging-indent: 1em, + first-line-indent: 0em, + )[ + #figure( + supplement: "", + kind: __glossarium_figure, + numbering: none, + caption: user-print-gloss( + entry, + show-all: show-all, + disable-back-references: disable-back-references, + user-print-title: user-print-title, + user-print-description: user-print-description, + user-print-back-references: user-print-back-references, + ), + )[] #label(entry.key) + // Line below can be removed safely + #figure(kind: __glossarium_figure, supplement: "")[] #label(entry.key + ":pl") + ] + #parbreak() + ] +} +``` +] + +The function is responsible for creating the referenceable element and the label +for the gloss. +- it uses #typc("figure()") and #typc("label()") to create the element and make + it referenceable. #typc("glossarium") uses #typc("kind: __glossarium_figure") + to uniquely identify glossary figures +- the figure's caption is the result of #typc("user-print-gloss()") (see + previous section @ssec:print-gloss) +- By default, an additional empty figure with label #typc("key:pl") + is created. This is useful for referencing plural forms of the glossary entry, + e.g., #typc("@WHO:pl")=@WHO:pl. It can be safely removed. + +#text.with(fill: red.darken(10%))([ + #emoji.warning Notice that #typc("entry.key") is used as the label. This usage + implies that glosses with duplicate keys will not work, as labels must be + unique. +]) + +The code below panics: +#typc-block[ + ```typc + #figure(caption: "test")[]#label("a") + #figure(caption: "test")[]#label("a") + @a + ``` +] +with error +#typc-block[ + ```shell + error: label `` occurs multiple times in the document + ``` +] + +=== #typc("default-print-glossary(entries, groups)") + +#typc-block[ +```typc +#let default-print-glossary( + entries, + groups, + show-all: false, + disable-back-references: false, + user-print-reference: default-print-reference, + user-group-break: default-group-break, + user-print-gloss: default-print-gloss, + user-print-title: default-print-title, + user-print-description: default-print-description, + user-print-back-references: default-print-back-references, +) = { + let body = [] + let previous-heading = query(selector(heading).before(here())).last() + + for group in groups.sorted() { + let group-entries = entries.filter(x => x.at("group") == group) + let group-ref-counts = group-entries.map(count-refs) + let print-group = ( + group != "" + and ( + show-all == true + or group-ref-counts.any(x => x > 0) + ) + ) + + // Only print group name if any entries are referenced + if print-group { + body += [#heading(group, level: previous-heading.level + 1)] + } + for entry in group-entries.sorted(key: x => x.key) { + body += user-print-reference( + entry, + show-all: show-all, + disable-back-references: disable-back-references, + user-print-gloss: user-print-gloss, + user-print-title: user-print-title, + user-print-description: user-print-description, + user-print-back-references: user-print-back-references, + ) + } + + body += user-group-break() + } + + return body +} +``` +] + +The function is responsible for printing the glossary. It iterates over all +groups and prints the entries. It also checks if the group should be printed or +not. If the group is empty, it will not be printed unless #typc("show-all: +true"). + +See the default style in @sssec:default-style. + +== Styles + +=== Default glossary + +// let parent-heading = query(heading(1)).first() + +#typc-block[ += Glossary +#print-glossary( + entry-list, + show-all: true, +) +] \ No newline at end of file diff --git a/examples/full-example/main.pdf b/examples/full-example/main.pdf index d3e94da..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 74184b7..49f8a3e 100644 --- a/examples/full-example/main.typ +++ b/examples/full-example/main.typ @@ -1,7 +1,6 @@ -#import "../../glossarium.typ": make-glossary, print-glossary, gls, glspl, agls +#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 #set page(paper: "a5") @@ -12,14 +11,28 @@ There are many Belgian universities, like @kuleuven and @ulb. When repeating their names, they won't show as a long version: @kuleuven, @ulb. But we can still force them to be long using the `gls` function: #gls("kuleuven", long: true). + We can also force them to be short: #gls("kuleuven", long: false). Finally, we -can make them plural using the `suffix` parameter: #gls("kuleuven", suffix: "s") or -using the additional `supplement` onto the `ref`: @kuleuven[s]. We can also use -the plural function function `#glspl(key: "kuleuven")` #glspl("kuleuven"). +can make them plural: ++ using the `suffix` parameter: #gls("kuleuven", suffix: "s"), or ++ using the additional `supplement` onto the `ref`: @kuleuven[s], or ++ the plural function `#glspl(key: "kuleuven")` #glspl("kuleuven"), or ++ call `@kuleuven:pl` @kuleuven:pl It is also possible to use the proper article with `#agls("lod")`: "#agls("lod") system", "#agls("lod") system". -You can also override the text shown by setting the `display` argument: #gls("kuleuven", display: "whatever you want") +You can also override the text shown by setting the `display` argument: #gls("kuleuven", display: "whatever you want") + +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") #pagebreak() @@ -29,40 +42,39 @@ 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() = Glossary + #print-glossary( ( ( key: "kuleuven", short: "KU Leuven", long: "Katholieke Universiteit Leuven", - desc: [Fugiat do fugiat est minim ullamco est eu duis minim nisi tempor adipisicing do _sunt_. #gls("vub")], + description: [Fugiat do fugiat est minim ullamco est eu duis minim nisi tempor adipisicing do _sunt_. #gls("vub")], + plural: "KU Leuvens", ), ( key: "uclouvain", short: "UCLouvain", long: "Université catholique de Louvain", - desc: "Sunt pariatur deserunt irure dolore veniam voluptate cillum in. Officia nulla laborum nostrud mollit officia aliqua. Laborum tempor aute proident fugiat adipisicing qui laborum tempor ad officia. Nulla ipsum voluptate in proident laborum labore nulla culpa sunt deserunt sit ad aliqua culpa.", + description: "Sunt pariatur deserunt irure dolore veniam voluptate cillum in. Officia nulla laborum nostrud mollit officia aliqua. Laborum tempor aute proident fugiat adipisicing qui laborum tempor ad officia. Nulla ipsum voluptate in proident laborum labore nulla culpa sunt deserunt sit ad aliqua culpa.", ), ( key: "ughent", short: "UGent", long: "Universiteit Gent", - desc: "Labore officia commodo dolor sunt eu sunt excepteur enim nisi ex ad officia magna. Nostrud elit ullamco quis amet id eu. Cupidatat elit cupidatat ad nulla laboris irure elit.", + description: "Labore officia commodo dolor sunt eu sunt excepteur enim nisi ex ad officia magna. Nostrud elit ullamco quis amet id eu. Cupidatat elit cupidatat ad nulla laboris irure elit.", ), ( key: "vub", short: "VUB", long: "Vrije Universiteit Brussel", - desc: [Proident veniam non aliquip commodo sunt cupidatat. Enim est cupidatat occaecat + description: [Proident veniam non aliquip commodo sunt cupidatat. Enim est cupidatat occaecat elit et. Adipisicing irure id consequat ullamco non. Labore sunt tempor et mollit. #gls("kuleuven", long: true)], ), @@ -70,32 +82,36 @@ parameter to the `glossary.with` function to load data from an external format. key: "ulb", short: "ULB", long: "", - desc: "Magna do officia sit reprehenderit anim esse. Eu Lorem ullamco incididunt minim quis sit sunt id mollit sit amet cupidatat. Labore incididunt enim culpa ex magna veniam proident non sint dolor. Incididunt proident esse culpa nostrud tempor cupidatat culpa consectetur excepteur ipsum deserunt duis exercitation. Non consectetur dolore culpa laboris in quis. Cupidatat aliquip exercitation id elit ipsum amet enim nostrud elit reprehenderit velit. Irure labore pariatur non dolore non officia laborum quis deserunt adipisicing cillum incididunt.", + description: "Magna do officia sit reprehenderit anim esse. Eu Lorem ullamco incididunt minim quis sit sunt id mollit sit amet cupidatat. Labore incididunt enim culpa ex magna veniam proident non sint dolor. Incididunt proident esse culpa nostrud tempor cupidatat culpa consectetur excepteur ipsum deserunt duis exercitation. Non consectetur dolore culpa laboris in quis. Cupidatat aliquip exercitation id elit ipsum amet enim nostrud elit reprehenderit velit. Irure labore pariatur non dolore non officia laborum quis deserunt adipisicing cillum incididunt.", ), ( key: "umons", short: "UMons", long: "Université de Mons", - desc: "Aliquip incididunt elit aliquip eu fugiat sit consectetur officia veniam sunt labore consequat sint eu. Minim occaecat irure consequat sint non enim. Ea consectetur do occaecat aliqua exercitation exercitation consectetur Lorem pariatur officia nostrud. Consequat duis minim veniam laboris nulla anim esse fugiat. Ullamco aliquip irure adipisicing quis est laboris.", + description: "Aliquip incididunt elit aliquip eu fugiat sit consectetur officia veniam sunt labore consequat sint eu. Minim occaecat irure consequat sint non enim. Ea consectetur do occaecat aliqua exercitation exercitation consectetur Lorem pariatur officia nostrud. Consequat duis minim veniam laboris nulla anim esse fugiat. Ullamco aliquip irure adipisicing quis est laboris.", ), ( key: "uliege", short: "ULiège", long: "Université de Liège", - desc: "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.", + 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", + key: "lod", + short: "LOD", artshort: "an", long: "level of details", - desc: lorem(10), + description: lorem(10), ), ( key: "notused", short: "Not used", - desc: [This key is not cited anywhere, it won't be in the glossary unless the + description: [This key is not cited anywhere, it won't be in the glossary unless the `show-all` argument is set to true], ), ), diff --git a/examples/groups/groups.pdf b/examples/groups/groups.pdf index 45de7be..b30bbac 100644 Binary files a/examples/groups/groups.pdf and b/examples/groups/groups.pdf differ diff --git a/examples/groups/groups.typ b/examples/groups/groups.typ index c135c9c..d3ddf81 100644 --- a/examples/groups/groups.typ +++ b/examples/groups/groups.typ @@ -15,38 +15,38 @@ Reference to @ntc \ Reference to @bor #pagebreak() + = Glossary with group enabled + #print-glossary( ( ( key: "ntc", short: "NTC", long: "Linear Transform Coding", - desc: [This is the opposite of @ltc.], + description: [This is the opposite of @ltc.], group: "Nonlinear", ), ( key: "ltc", short: "LTC", long: "This is the opposite of @ltc.", - desc: [ Transform Coding constraint to linear transforms.], + description: [Transform Coding constraint to linear transforms.], group: "Linear", ), ( key: "bor", short: "DEF", long: "Default", - desc: lorem(25), + description: lorem(25), ), ( key: "bor2", short: "DEF2", long: "Default2", - desc: lorem(25), + description: lorem(25), group: "", // Please note that an empty group has the same effect as no group ), - ), show-all: true, - enable-group-pagebreak: true, // break page for each group ) diff --git a/examples/import-terms-from-yaml-file/main.pdf b/examples/import-terms-from-yaml-file/main.pdf index 1df244f..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/import-terms-from-yaml-file/main.typ b/examples/import-terms-from-yaml-file/main.typ index 7f7348c..250010c 100644 --- a/examples/import-terms-from-yaml-file/main.typ +++ b/examples/import-terms-from-yaml-file/main.typ @@ -61,7 +61,7 @@ key: key, short: eval(entry.short, mode: "markup"), long: eval(entry.at("long", default: ""), mode: "markup"), - desc: eval(entry.at("description", default: ""), mode: "markup"), + description: eval(entry.at("description", default: ""), mode: "markup"), group: entry.at("group", default: ""), file: file, )) diff --git a/examples/plural-example/main.pdf b/examples/plural-example/main.pdf index 71cf253..3acb782 100644 Binary files a/examples/plural-example/main.pdf and b/examples/plural-example/main.pdf differ diff --git a/examples/plural-example/main.typ b/examples/plural-example/main.typ index 0d9ee15..a22a19f 100644 --- a/examples/plural-example/main.typ +++ b/examples/plural-example/main.typ @@ -21,27 +21,35 @@ I love #glspl("cpu"). I ate a #gls("cpu") once. Would you eat a #gls("buffer") ? I heard #glspl("buffer") are tasty. = Glossary + #print-glossary( - (( - key: "potato", - short: "potato", - // "plural" will be used when "short" should be pluralized - plural: "potatoes", - desc: [#lorem(10)], - ), ( - key: "dm", - short: "DM", - long: "diagonal matrix", - // "longplural" will be used when "long" should be pluralized - longplural: "diagonal matrices", - desc: "Probably some math stuff idk", - ), ( - key: "cpu", - short: "CPU", - long: "Central Processing Unit", - desc: [#lorem(10)], - ), (key: "buffer", short: "buffer", desc: "A place to store stuff"),), - // show all term even if they are not referenced, default to true + ( + ( + key: "potato", + short: "potato", + // "plural" will be used when "short" should be pluralized + plural: "potatoes", + description: [#lorem(10)], + ), ( + key: "dm", + short: "DM", + long: "diagonal matrix", + // "longplural" will be used when "long" should be pluralized + longplural: "diagonal matrices", + description: "Probably some math stuff idk", + ), ( + key: "cpu", + short: "CPU", + long: "Central Processing Unit", + description: [#lorem(10)], + ), + ( + key: "buffer", + short: "buffer", + description: "A place to store stuff" + ), + ), + // show all term even if they are not referenced, default to false show-all: true, // disable the back ref at the end of the descriptions disable-back-references: true, diff --git a/glossarium.typ b/glossarium.typ index 998553a..059cadb 100644 --- a/glossarium.typ +++ b/glossarium.typ @@ -1,141 +1,437 @@ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE.*/ +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. // glossarium figure kind #let __glossarium_figure = "glossarium_entry" + // prefix of label for references query -#let __glossary_label_prefix = "glossary:" +#let __glossary_label_prefix = "gls:" + // global state containing the glossary entry and their location +// A glossary entry is a `dictionary`. +// See `__normalize_entry_list`. #let __glossary_entries = state("__glossary_entries", (:)) -#let __glossarium_error_prefix = "glossarium error : " +// glossarium version +#let glossarium_version = "0.4.0" + +// error prefix +#let __glossarium_error_prefix = "glossarium@" + glossarium_version + " error : " + +// Errors types +#let __key_not_found = "key_not_found" +#let __attribute_is_empty = "attribute_is_empty" +#let __unknown_error = "unknown_error" + +// __error_message(key, kind, ..kwargs) -> str +// Generate an error message +// +// # Arguments +// key (str): the key of the term +// kind (str): the kind of the error +// kwargs (arguments): additional arguments +// +// # Returns +// The error message +#let __error_message(key, kind, ..kwargs) = { + let msg = none + let kwargs = kwargs.named() // convert arguments sink to dictionary + + // Generate the error message + if kind == __key_not_found { + msg = "key '" + key + "' not found" + } else if kind == __attribute_is_empty { + attr = kwargs.get("attr") + " " + msg = "requested attribute " + attr + "is empty for key '" + key + "'" + } else { + msg = "unknown error" + } + + // return the error message + return __glossarium_error_prefix + msg +} +// __query_labels_with_key(loc, key, before: false) -> array