Skip to content

Commit

Permalink
Merge pull request #36 from ENIB-Community/feat-plurals
Browse files Browse the repository at this point in the history
feat: plurals
  • Loading branch information
slashformotion authored Apr 27, 2024
2 parents bf1597a + f56af36 commit 99584f9
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 41 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ on:
- master
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
branches: [ '**' ]

jobs:
build-example:
Expand Down
95 changes: 58 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ This manual assume you have a good enough understanding of typst markup and scri

For Typst 0.6.0 or later import the package from the typst preview repository:

```ts
```typ
#import "@preview/glossarium:0.3.0": make-glossary, print-glossary, gls, glspl
```

For Typst before 0.6.0 or to use **glossarium** as a local module, download the package files into your project folder and import `glossarium.typ`:

```js
```typ
#import "glossarium.typ": make-glossary, print-glossary, gls, glspl
```

After importing the package and before making any calls to `gls`,` print-glossary` or `glspl`, please ***MAKE SURE*** you add this line
```js
```typ
#show: make-glossary
```

Expand All @@ -43,35 +43,51 @@ A term is a [dictionary](https://typst.app/docs/reference/types/dictionary/) com
- `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.
- `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.

Then the terms are passed as a list to `print-glossary`

```ts
#print-glossary((
// minimal term
(key: "kuleuven", short: "KU Leuven"),
// a term with a long form and a group
(key: "unamur", short: "UNamur", long: "Namur University", group: "Universities"),
// another one but formated differently
(
key: "umons",
short: "UMons",
long: "Mons University",
group: "Universities"
),
// no long form here
(key: "kdecom", short: "KDE Community", desc:"An international team developing and distributing Open Source software."),
// a full term with description containing markup
(
key: "oidc",
short: "OIDC",
long: "OpenID Connect",
desc: [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",
),
))
```typ
#print-glossary(
(
// minimal term
(key: "kuleuven", short: "KU Leuven"),
// a term with a long form and a group
(key: "unamur", short: "UNamur", long: "Namur University", group: "Universities"),
// a term with a markup description
(
key: "oidc",
short: "OIDC",
long: "OpenID Connect",
desc: [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",
),
// a term with a short plural
(
key: "potato",
short: "potato",
// "plural" will be used when "short" should be pluralized
plural: "potatoes",
desc: [#lorem(10)],
),
// a term with a long plural
(
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",
),
)
)
```

By default, the terms that are not referenced in the document are not shown in the glossary, you can force their appearance by setting the `show-all` argument to true.
Expand All @@ -87,7 +103,7 @@ You can call this function from anywhere in you document.

Referencing terms is done using the key of the terms using the `gls` function or the reference syntax.

```ts
```typ
// referencing the OIDC term using gls
#gls("oidc")
// displaying the long form forcibly
Expand All @@ -99,33 +115,38 @@ Referencing terms is done using the key of the terms using the `gls` function or

#### Handling plurals

You can use the `glspl` function and the references supplements to pluralize terms:
You can use the `glspl` function and the references supplements to pluralize terms.
The `plural` key will be used when `short` should be pluralized and `longplural` will be used when `long` should be pluralized. If the `plural` key is missing then glossarium will add an 's' at the end of the short form as a fallback.

```ts
#glspl("oidc") // equivalent of `#gls("oidc", suffix: "s")`
// or
@oidc[s]
```typ
#glspl("potato")
```

Please look at the examples regarding plurals.

#### Overriding the text shown

You can also override the text displayed by setting the `display` argument.

```ts
```typ
#gls("oidc", display: "whatever you want")
```

## Final tips

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.
I recommend setting a show rule for the links to that your readers understand that they can click on the references to go to the term in the glossary.

```ts
```typ
#show link: set text(fill: blue.darken(60%))
// links are now blue !
```

## Changelog

### Unreleased

- Added support for plurals, see [examples/plural-example](examples/plural-example)

### 0.3.0

- Introducing support for grouping terms in the glossary. Use the optional and case-sensitive key `group` to assign terms to specific groups. The appearanceof the glossary can be customized with the new parameter `enable-group-pagebreak`, allowing users to insert page breaks between groups for better organization. These enhancements were contributed by [indicatelovelace](https://github.com/indicatelovelace).
Expand Down
Binary file modified examples/full-example/main.pdf
Binary file not shown.
Binary file modified examples/groups/groups.pdf
Binary file not shown.
Binary file modified examples/import-terms-from-yaml-file/main.pdf
Binary file not shown.
Binary file modified examples/plural-example/main.pdf
Binary file not shown.
5 changes: 3 additions & 2 deletions glossarium.typ
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ SOFTWARE.*/
}
}

// reference to term with pluralisation
// Reference to term with pluralisation
#let glspl(key, long: none) = {
let suffix = "s"
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 suffix = "s";
let is_first = gloss == ()
let entlongplural = entry.at("longplural", default: "");
let entlong = if entlongplural == [] or entlongplural == "" {
// if the entry long plural is not provided, then fallback to adding 's' suffix
let entlong = entry.at("long", default: "");
if entlong != [] and entlong != "" {
[#entlong#suffix]
Expand Down

0 comments on commit 99584f9

Please sign in to comment.