Skip to content

Commit

Permalink
Deprecate state.final() and query(..., loc) + add missing panic f…
Browse files Browse the repository at this point in the history
…or empty attribute + formatting using typstyle
  • Loading branch information
quachpas committed Aug 12, 2024
1 parent f55d66d commit d50c95a
Show file tree
Hide file tree
Showing 17 changed files with 363 additions and 257 deletions.
144 changes: 89 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
# Typst glossary

> [!WARNING] For Typst v0.11.0 and later
> Due to changes in the `typst` compiler (`context`), a new function is needed, i.e., `register-glossary`.
> Recommended usage is the following:
> ```diff
> #import "@preview/glossarium:0.4.0": make-glossary, register-glossary, print-glossary, gls, glspl
> #show: make-glossary
> + #let entry-list = (...)
> + #register-glossary(entry-list)
> ... // Your document body
> #print-glossary(
> - (
> - ...
> - )
> + entry-list
> )
> ```
> Glossarium is based in great part of the work of [Sébastien d'Herbais de Thun](https://github.com/Dherse) from his master thesis available at: <https://github.com/Dherse/masterproef>. His glossary is available under the MIT license [here](https://github.com/Dherse/masterproef/blob/main/elems/acronyms.typ).
Glossarium is a simple, easily customizable typst glossary inspired by [LaTeX glossaries package](https://www.ctan.org/pkg/glossaries) . You can see various examples showcasing the different features in the `examples` folder.
![Screenshot](.github/example.png)
## Manual
## Manual
### Import and setup
This manual assume you have a good enough understanding of typst markup and scripting.
This manual assume you have a good enough understanding of typst markup and scripting.
For Typst 0.6.0 or later import the package from the typst preview repository:
```typ
#import "@preview/glossarium:0.4.0": make-glossary, print-glossary, gls, glspl
#import "@preview/glossarium:0.4.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`:

```typ
#import "glossarium.typ": make-glossary, print-glossary, gls, glspl
#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
Expand All @@ -33,62 +51,78 @@ 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
### Registering the glossary

First we have to define the terms.
A term is a [dictionary](https://typst.app/docs/reference/types/dictionary/) composed of 2 required and 2 optional elements:
First we have to define the terms.
A term is a [dictionary](https://typst.app/docs/reference/types/dictionary/) composed of 2 required and 2 optional elements:

- `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.
- `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.
- `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.
- `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`

```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",
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: "Acronyms",
),
// a term with a short plural
(
key: "potato",
short: "potato",
// "plural" will be used when "short" should be pluralized
plural: "potatoes",
description: [#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",
description: "Probably some math stuff idk",
),
)
#let entry-list = (
// 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",
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: "Acronyms",
),
// a term with a short plural
(
key: "potato",
short: "potato",
// "plural" will be used when "short" should be pluralized
plural: "potatoes",
description: [#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",
description: "Probably some math stuff idk",
),
)
```

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

```typ
#register-glossary(entry-list)
```

### Printing the glossary

Now, you can display the glossary using the `print-glossary` function.

```typ
#print-glossary(entry-list)
```

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.

You can also disable the back-references by setting the parameter `disable-back-references` to `true`.
Expand Down Expand Up @@ -127,7 +161,7 @@ Please look at the examples regarding plurals.
You can also override the text displayed by setting the `display` argument.

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

## Final tips
Expand All @@ -136,7 +170,7 @@ I recommend setting a show rule for the links to that your readers understand th

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

## Changelog
Expand All @@ -149,8 +183,8 @@ I recommend setting a show rule for the links to that your readers understand th

### 0.4.0

- Support for plurals has been implemented, showcased in [examples/plural-example/main.typ](examples/plural-example). Contributed by [@St0wy](https://github.com/St0wy).
- The behavior of the gls and glspl functions has been altered regarding calls on undefined glossary keys. They now cause panics. Contributed by [@St0wy](https://github.com/St0wy).
- Support for plurals has been implemented, showcased in [examples/plural-example/main.typ](examples/plural-example). Contributed by [@St0wy](https://github.com/St0wy).
- The behavior of the gls and glspl functions has been altered regarding calls on undefined glossary keys. They now cause panics. Contributed by [@St0wy](https://github.com/St0wy).

### 0.3.0

Expand All @@ -172,7 +206,7 @@ I recommend setting a show rule for the links to that your readers understand th

#### Fixed

- Fixed a bug where the reference would a long ref even when "long" was set to false. Contributed by [@dscso](https://github.com/dscso)
- Fixed a bug where the reference would a long ref even when "long" was set to false. Contributed by [@dscso](https://github.com/dscso)

#### Changed

Expand Down
Binary file modified advanced-docs/main.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion advanced-docs/main.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "../glossarium.typ": *
#import "../themes/default.typ": *

#show: make-glossary
#set page(paper: "a4")
Expand Down Expand Up @@ -64,6 +64,7 @@
group: "Countries",
),
)
#register-glossary(entry-list)
#let entries = __normalize_entry_list(entry-list)
#let groups = entries.map(x => x.at("group")).dedup()

Expand Down
Binary file modified examples/full-example/main.pdf
Binary file not shown.
134 changes: 68 additions & 66 deletions examples/full-example/main.typ
Original file line number Diff line number Diff line change
@@ -1,7 +1,73 @@
#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
#import "../../glossarium.typ": make-glossary, register-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
#let entry-list = (
(
key: "kuleuven",
short: "KU Leuven",
long: "Katholieke Universiteit Leuven",
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",
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",
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",
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)],
),
(
key: "ulb",
short: "ULB",
long: "",
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",
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",
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: "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],
),
)
#register-glossary(entry-list)

#set page(paper: "a5")

Expand Down Expand Up @@ -50,71 +116,7 @@ Additionally, you can load data externally and pass it as a parameter to the
= Glossary

#print-glossary(
(
(
key: "kuleuven",
short: "KU Leuven",
long: "Katholieke Universiteit Leuven",
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",
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",
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",
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)],
),
(
key: "ulb",
short: "ULB",
long: "",
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",
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",
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: "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],
),
),
entry-list,
// show all term even if they are not referenced, default to true
show-all: true,
// disable the back ref at the end of the descriptions
Expand Down
Binary file modified examples/groups/groups.pdf
Binary file not shown.
Loading

0 comments on commit d50c95a

Please sign in to comment.