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

Deprecate state.final() and query(..., loc) + add missing panic for empty attribute + formatting #52

Merged
merged 11 commits into from
Oct 6, 2024
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
glossarium.pdf
glossarium.pdf
/.gtm/
8 changes: 8 additions & 0 deletions .vscode/glossarium.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {},
}
158 changes: 100 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ Glossarium is a simple, easily customizable typst glossary inspired by [LaTeX gl

![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 +33,80 @@ 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.
A term is a [dictionary](https://typst.app/docs/reference/types/dictionary/) composed of 2 required and 2 optional elements:
### Registering the glossary

- `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.
- `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.
First we have to define the terms.
A term is a [dictionary](https://typst.app/docs/reference/types/dictionary/) as follows:

Then the terms are passed as a list to `print-glossary`
| Key | Type | Required/Optional | Description |
| ------------- | ----------------- | ----------------- | -------------------------------------------------------------------------------------------- |
| `key` | string | required | Case-sensitive, unique identifier used to reference the term. |
| `short` | string | semi-optional | The short form of the term replacing the term citation. |
| `long` | string or content | semi-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. |
| `group` | string | optional | Case-sensitive group the term belongs to. The terms are displayed by groups in the 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 +145,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,21 +154,45 @@ 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

### Unreleased

### 0.4.2

> [!TIP] For Typst v0.12.0 and later
> A new function is introduced `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
> )
> ```

> [!NOTE] Deprecate `location` argument in queries

> [!TIP] `short` is no longer **required**, but **semi-optional**.
> Accept `short` or `long` for an entry, but not neither.

### 0.4.1

- Resolved an issue causing Glossarium to crash when all entries had a defined, non-empty group.

### 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 +214,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.
Loading
Loading