Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to "automatically" chose between a and an #34

Merged
merged 5 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions examples/full-example/main.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "../../glossarium.typ": make-glossary, print-glossary, gls, glspl
#import "../../glossarium.typ": make-glossary, print-glossary, gls, glspl, agls
// 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/.

Expand All @@ -9,23 +9,34 @@
//I recommend setting a show rule for the links to that your reader understand that they can click on the references to go to the term in the glossary.
#show link: set text(fill: blue.darken(60%))

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").

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").

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")


#pagebreak()

Numbering is, of course, correct when referencing the glossary: @kuleuven, @ulb, @ughent, @vub, @ulb, @umons, @uliege, @unamur. They are also sorted based on where the page is in the document and not the textual representation.
Numbering is, of course, correct when referencing the glossary: @kuleuven, @ulb,
@ughent, @vub, @ulb, @umons, @uliege, @unamur. They are also sorted based on
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.

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.

#pagebreak()

= Glossary
#print-glossary(
(
Expand All @@ -51,7 +62,9 @@ At the moment, customization is not built-in to the function and instead follows
key: "vub",
short: "VUB",
long: "Vrije Universiteit Brussel",
desc: [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)],
desc: [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)],
),
(
key: "ulb",
Expand All @@ -71,15 +84,19 @@ At the moment, customization is not built-in to the function and instead follows
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.",
),
(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",
desc: lorem(10),
),
(
key: "notused",
short: "Not used",
desc: [This key is not cited anywhere, it won't be in the glossary unless the `show-all` argument is set to true],
desc: [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
Expand Down
44 changes: 37 additions & 7 deletions glossarium.typ
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SOFTWARE.*/

// key not found error
#let __not-found-panic-error-msg(key) = {
__glossarium_error_prefix+"key '"+key+"' not found"
__glossarium_error_prefix + "key '" + key + "' not found"
}

// Reference a term
Expand Down Expand Up @@ -57,6 +57,35 @@ SOFTWARE.*/
}
}

#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))
}
}
}

// Reference to term with pluralisation
#let glspl(key, long: none) = {
let suffix = "s"
Expand Down Expand Up @@ -120,8 +149,10 @@ SOFTWARE.*/
new-list.push((
key: entry.key,
short: entry.short,
artshort: entry.at("artshort", default: "a"),
plural: entry.at("plural", default: ""),
long: entry.at("long", default: ""),
artlong: entry.at("artlong", default: "a"),
longplural: entry.at("longplural", default: ""),
desc: entry.at("desc", default: ""),
group: entry.at("group", default: ""),
Expand Down Expand Up @@ -192,13 +223,12 @@ SOFTWARE.*/
(values: values, pages: pages)
},
).values.map(x => {
let page-numbering = x.page-numbering();
if page-numbering == none {
page-numbering = "1"
}
link(x)[#numbering(page-numbering, ..counter(page).at(x))]
let page-numbering = x.page-numbering();
if page-numbering == none {
page-numbering = "1"
}
).join(", ")
link(x)[#numbering(page-numbering, ..counter(page).at(x))]
}).join(", ")
}
}
}
Expand Down
Loading