# Glossary

<StatusBadge status="available" /> `format: glossary` turns a :term[story]{id=story} into a
**glossary**: each `## heading` is a term, the paragraph under it its short definition, the rest its
long one. The same file is shown as an A–Z list with its alphabet rail (« É » under « E », sorted by
`Intl.Collator` in the language shown) or by section, gives each term an anchor (`#lorem`) and,
with `pages: true`, a page; the build lists under each term the pages that use it ("Used in").

The same terms are linked from any story with `:term[…]`, see [Terms](/documentation/writing/terms).
The glossary of Récit itself is written in this format:
[Glossary](/documentation/reference/glossary). The example is `glossary-lorem` (English and French).
Both formats of `@recit/directory` share one model of named entries: the
[directory](/formats/directory/overview) is the other.

## A minimal glossary

```md title="glossary.md"
---
title: Lorem Glossary
format: glossary
lang: en
view: az # az | sections
pages: false # one page per term
---

--- id=basics

# Basics

## Lorem {aliases=lorems tags=core see=ipsum}

A placeholder text. One paragraph: the short definition, shown in the card of a :term.

The long definition follows, as many paragraphs as needed.

## Ipsum {source=https://example.com/ipsum license=CC-BY-4.0}

The second word of the placeholder.
```

| Written                    | What it is                                                                                  |
| -------------------------- | ------------------------------------------------------------------------------------------- |
| `--- id=…` and `# heading` | a **section**: the `sections` view groups the terms under it                                |
| `## heading`               | a **term**; its id is the slug of its name, or `{id=…}`                                     |
| first paragraph            | the short definition, one paragraph of Markdown: the card of a `:term`, the slide of a deck |
| the paragraphs after it    | the long definition: the term's page, the speaker notes of its slide                        |
| `{aliases=a,b}`            | other forms the term is recognised by (plurals included, no stemming)                       |
| `{tags=a,b}`               | tags                                                                                        |
| `{see=id,id}`              | see-also links; an id that is not a term of the glossary is an error, with its line         |
| `{source=… license=…}`     | where the definition was taken from; `license` without `source` is an error                 |

## Settings

In the front matter, or for every glossary of a folder in the `glossary:` section of
`recit.config.ts` (the front matter wins).

| Setting  | Default     | What it does                                                                                                              |
| -------- | ----------- | ------------------------------------------------------------------------------------------------------------------------- |
| `view`   | `az`        | the view shown first: `az`, every term under its initial with the alphabet rail, or `sections`, the order of the sections |
| `usedIn` | `true`      | lists under each term the pages that use it ("Used in"), computed at build time                                           |
| `pages`  | `false`     | one page per term, `<slug>/<id>`, prerendered and in the sitemap                                                          |
| `strict` | `false`     | every term writes its `{id=…}`; a term without one is an error                                                            |
| `pdf`    | A4 portrait | `recit export --to pdf`: `view` (`az` or `sections`, the story's own view by default), the page box                       |

With `strict: true` (front matter, or `glossary: { strict: true }` in `recit.config`), every term
writes its id. Each term without one is an error of `recit validate` and of the build, at its line:
in the glossary above, under `glossary: { strict: true }`, both `## Lorem {aliases=… see=ipsum}`
(`✖ glossary.md:13 — entry "Lorem" has no id (strict)`) and `## Ipsum {source=…}`
(`✖ glossary.md:19 — entry "Ipsum" has no id (strict)`). `## Lorem {id=lorem aliases=… see=ipsum}`
and `## Ipsum {id=ipsum source=…}` pass: the term keeps its anchor when its name changes. This is
not `--strict` of `recit validate --links`.

One glossary per language: `glossary.md` and `glossary.fr.md` side by side, the same ids. A term
links to the glossary of the page's language first.

```ts title="recit.config.ts"
import { defineConfig } from "recit/config";

export default defineConfig({
  glossary: { view: "sections", usedIn: true, pages: true, strict: true },
});
```

In an MDX page of a Récit site: `<StoryEmbed slug="glossary" format="glossary" />`.

## Structured data

The page that `recit build` writes carries the glossary's schema.org data in its head: a
`DefinedTermSet` in the language shown, with one `DefinedTerm` per term (its name, its abbreviation
and aliases as `alternateName`, its short definition as `description`). A site or another tool gets
the same document from `entriesJsonLd({ format: "glossary", glossary })` of `@recit/directory`; with
`pageUrl`, an absolute address, each term gets its anchor as `url`.

## Commands

| Command                                             | What it does                                                            |
| --------------------------------------------------- | ----------------------------------------------------------------------- |
| `recit validate glossary.md`                        | checks the terms, the `see=` ids, `source` and `license`, and `strict`  |
| `recit convert glossary.md`                         | the JSON twin, and back from `glossary.json`                            |
| `recit convert glossary.md --to webstory`           | a title card, then one card per term, or `--per section`                |
| `recit dev glossary.md`, `recit build glossary.md`  | the glossary as a page, served while you write or built to static files |
| `recit export glossary.md --to pdf -o glossary.pdf` | every term, A–Z or by section, A4 portrait with its page numbers        |

The PDF lands next to the story (`glossary.pdf`) unless `-o` or `pdf.output` names it, and is listed
in `exports.json`. The `pdf` key takes the
[PDF options](/documentation/configuration/recit-config#pdf-options) of every paginated format
(`page`, `header`, `footer`, `colorMode`, `output`…), plus `view`:
`glossary: { pdf: { view: "sections" } }` prints the terms under their sections. Each `see`
reference is a link inside the PDF.

## Bridges

| Command or directive                       | What it gives                                                         |
| ------------------------------------------ | --------------------------------------------------------------------- |
| `::glossary{terms=lorem,ipsum}` on a slide | the short definitions of the terms named, each a link to the glossary |
| MCP `lookup_term`                          | a term by id or by text, in a language: its short and long definition |
| `back: [glossary]` in a book               | a page of the terms the book uses, with the pages where it uses them  |
| `print: { glossary: true }` in a report    | the same at the end of the printed report                             |

## The JSON twin

A `kind: "story"` file (`https://recit.dev/schema/v1/glossary.json`, `format: "glossary"`,
`version: 1`) next to the `.md` holds the same glossary under the story envelope (`syntax`,
`preamble`, `meta`, `data`, `settings` — see
[Scenes › In the JSON twin](/documentation/writing/scenes#in-the-json-twin)) and `scenes`, while a
`kind: "sidecar"` companion (`glossary.json`) completes sections and terms by `id`.

| Key              | Type / values                                 | Effect                                                                                                                                   |
| ---------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `scenes`         | `object[]`                                    | Required in `kind: "story"`. Sections of the glossary, in order (`---` separators in Markdown; a file without `---` is one section).     |
| `scenes.id`      | `string` (non-empty)                          | Required. Stable section identifier across languages (`--- id=…` in Markdown; [Scenes](/documentation/writing/scenes#in-the-json-twin)). |
| `scenes.title`   | `string` or `Record<string, string>`          | Optional section heading (`# Heading` at the start of the section, shown in the `sections` view).                                        |
| `scenes.body`    | `string` or `Record<string, string>`          | Optional Markdown or MDX prose of the section before its first `##` term ([Scenes](/documentation/writing/scenes#in-the-json-twin)).     |
| `scenes.notes`   | `string` or `Record<string, string>`          | Optional author notes in Markdown (`:::notes`; [Scenes](/documentation/writing/scenes#in-the-json-twin)).                                |
| `scenes.attrs`   | `Record<string, string \| number \| boolean>` | Optional separator attributes (`--- key=value`) other than `id` ([Scenes](/documentation/writing/scenes#in-the-json-twin)).              |
| `scenes.entries` | `object[]`                                    | Optional list of terms defined in this section.                                                                                          |

Each object in `scenes.entries` describes one term (`entries.id` and `entries.name` are required in
`kind: "story"`):

| Key                | Type / values                                        | Effect                                                                                                                                                        |
| ------------------ | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `entries.id`       | `string` (`^[a-z0-9][\w-]*$`)                        | Required. Stable term id across languages (anchor `#id` and `:term{id=…}` target); derived from `entries.name` in Markdown unless `{id=…}` is set (`strict`). |
| `entries.name`     | `string` or `Record<string, string>`                 | Required. Term heading (`## Heading` in Markdown).                                                                                                            |
| `entries.aliases`  | `string[]` (non-empty) or `Record<string, string[]>` | Other forms the term is recognised by (`{aliases=a,b}` in Markdown, plurals included, no stemming; duplicate names or aliases across terms are an error).     |
| `entries.abbr`     | `string` (non-empty)                                 | Abbreviation rendered as `<abbr>` next to the term name (`{abbr=…}` in Markdown).                                                                             |
| `entries.termCode` | `string` (non-empty)                                 | Code of the term in a controlled vocabulary, `DefinedTerm.termCode` (`{termCode=…}` in Markdown).                                                             |
| `entries.summary`  | `string` or `Record<string, string>`                 | Short definition in Markdown (first paragraph under `## Heading`), shown in `:term` hover cards, glossary lists and deck slides.                              |
| `entries.body`     | `string` or `Record<string, string>`                 | Long definition in Markdown (paragraphs after the first blank line under `## Heading`), shown on the term's page and in deck speaker notes.                   |
| `entries.tags`     | `string[]` (non-empty)                               | Tags on the term (`{tags=a,b}` in Markdown).                                                                                                                  |
| `entries.see`      | `string[]` (non-empty)                               | Ids of related terms in the same glossary (`{see=id,id}` in Markdown; an unknown id is an error).                                                             |
| `entries.source`   | `{ url, license? }`                                  | Provenance of a definition taken from elsewhere (`{source=… license=…}` in Markdown; `license` without `source` is an error).                                 |
| `source.url`       | `string` (`http:` or `https:` URI)                   | Required when `entries.source` is set. URL of the source (`{source=…}` in Markdown).                                                                          |
| `source.license`   | `string` (non-empty)                                 | Optional license identifier or name (`{license=…}` in Markdown).                                                                                              |
