# Report

<StatusBadge status="available" /> `format: report` turns a story into a **data report**: one
continuous page, one **section** per scene, a table of contents beside it, and a PDF. Every number it
shows comes from its data, never from the text: `:value`, `::chart`, `::table` and `:::kpi` read the
sources of `data:` at build time, so changing the CSV and rebuilding updates the prose, the charts
and the tables together.

The examples are `report-quarterly` (Markdown, two languages) and `report-study` (MDX). The four
data directives are on [Data directives](/formats/report/data).

## A minimal report

```md title="report.md"
---
title: Lorem Ipsum Report
format: report
lang: en
data:
  sales: ./data/sample.csv
toc: true
---

--- id=summary

## Summary

Revenue reached :value{data=sales field=revenue agg=sum format=currency currency=EUR} over the year.

::chart{data=sales type=line x=month y=revenue title="Monthly revenue"}
```

`recit init --format report` writes this starter and its `data/sample.csv`.

### Data sources

`data:` names each source. A path is a CSV, JSON or YAML file relative to the story; its column
types are inferred from the first 100 rows (`number`, `boolean`, `date`, `string`) or declared under
`columns:`; a later cell that does not fit is an error that names its line. In a CSV every cell is
text, so `2025` reads as a number; in JSON, YAML or inline rows a value keeps the type it is written
with, so a quoted `"2025"` stays text and is never grouped by thousands. A number is written with a
decimal point and no thousands separator, and fits a double: `1e400` is not a number, never `∞`.
Rows can also be written inline under `rows:`.

```yaml
data:
  sales: ./data/sales.csv
  regions:
    src: ./data/regions.json
    columns: { name: string, revenue: number }
  targets:
    rows: [{ quarter: 2026-Q4, revenue: 50000 }]
    meta:
      title: Dolor sit amet
      publisher: Lorem Ipsum Institute
      license: CC-BY-4.0
      modified: 2026-11-01
      url: https://example.org/lorem
```

An inline source (or a plugin source) may carry optional `meta` provenance with DCAT field names
(`title`, `url`, `publisher`, `license`, `modified`). When `::chart` omits `source=`, it composes
its `Source:` line from `publisher`, `title` and `(license)` automatically (`source=""` suppresses
it).

The files are read in Node, at build time. The rows never reach the browser: only the numbers shown
do. A missing file, an empty source or a cell that does not fit its type is an error with the line.
The four directives are described in [Data directives](/formats/report/data).

### MDX

A report can be written in MDX (`study.story.mdx`): a section then adds JSX and expressions to the
Markdown, next to the same data directives. Its sections are rendered to HTML once, at build time,
like the Markdown ones, so the page still receives no rows. A report cannot `import` a module: its
page is built from JSON, and an import is an error. `examples/report-study` ends with such a
section.

## Settings

In the front matter; the `report:` section of `recit.config.ts` gives the defaults of every report
of a folder, and the front matter wins.

| Setting       | Default | What it does                                                                                  |
| ------------- | ------- | --------------------------------------------------------------------------------------------- |
| `toc`         | `true`  | the side table of contents, a drawer on a phone                                               |
| `numbering`   | `false` | numbered section headings                                                                     |
| `interactive` | `true`  | keyboard navigation, arrow keys and a tooltip on charts in the browser                        |
| `print`       |         | printed layout (`print.layout`: `"document"`, `"poster"` or `"banner"`), and `print.glossary` |
| `theme`       |         | a named theme; `report` is the reading theme of the format                                    |
| `pdf`         | A4      | the PDF options, below                                                                        |

`theme.customCss` in `recit.config.ts` applies to a report last, as it does to a deck.

A `numbering` or `interactive` that is not `true` or `false`, or a `toc` that is an object (the
deck's `toc: { depth: 1 }`), is a warning (`report-invalid-setting`) in `recit dev`, `recit build`,
`recit validate` and a site: the `report:` section of `recit.config.ts` applies, or else the
default. A `toc` no schema accepts (`toc: "no"`) is an error of the front matter
(`frontmatter-invalid`), and the JSON twin's schema refuses any value but `true` or `false`.

In the browser, every chart gets one Tab stop, arrow keys across its values, a polite live region
and a tooltip read from its "Data" table (loaded in its own chunk in a site when a story holds an
interactive chart); the server HTML, the PDF and image exports are unchanged, and
`interactive: false` keeps the charts static.

| Key                  | What it does                                                                                                                                                                |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `report.toc`         | the side table of contents, as `toc` above                                                                                                                                  |
| `report.numbering`   | numbered section headings, as `numbering` above                                                                                                                             |
| `report.interactive` | interactive charts in the browser, as `interactive` above                                                                                                                   |
| `report.print`       | printed layout (`print.layout`: `"document"` by default, `"poster"` for a one-page poster grid, or `"banner"` for a single-page banner strip), and `print.glossary` (below) |
| `report.rules`       | the deck's [density rules](/formats/deck/density-rules), plus `hardcodedNumbers` (default on): a warning on a number written by hand in prose                               |
| `report.pdf`         | the PDF options of every report, the same keys as `pdf:` in the front matter                                                                                                |

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

export default defineConfig({
  metadata: { author: "Lorem Ipsum Studio" },
  report: {
    toc: true,
    numbering: false,
    print: { layout: "document" },
    interactive: true,
    rules: { hardcodedNumbers: true },
    pdf: { page: { size: "A4" } },
  },
});
```

### Numbers written by hand

A number written in the prose of a report (paragraphs, list items, blockquotes, headings and
Markdown table cells) instead of computed with `:value{…}` raises a `report-hand-number` warning at
its file and line, one per prose block, quoting the first number and counting any others in the same
block. `recit validate --strict` turns `report-hand-number` into an error (exit code `1`);
`recit build` and the rendered page keep it as a warning, and `rules.hardcodedNumbers: false` turns
it off.

Excluded from the check:

- standalone 4-digit years from `1000` to `2199` and year spans (`2025–2026`, `2025-2026`), and ISO
  dates (`2026-03-01`);
- section numbers at the start of a heading (`2.`, `3.1`, `IV.`), ordinals (`1er`, `1re`, `2e`,
  `2ème`, `3rd`, `21st`, `2nd`, `4th`, `XIXe`) and footnote calls (`[^1]`);
- digits attached to letters of a name or code (`A4`, `COVID-19`, `H2O`, `G7`, `mp4`), as well as
  code spans and blocks, link URLs and targets, image `alt` text, directive attributes, values
  rendered by the data directives, `:::notes` and the front matter.

### The PDF

`recit export --to pdf report.md` prints the printable view of the report: a title page, the table
of contents in links, the sections in order, figures and key figures never cut, the header row of a
long table repeated, bookmarks from the section titles. A4 with 20 mm margins unless `pdf:` says
otherwise; a custom page size (such as an 850×2000 mm roll-up banner) is laid out at its true size
(`recit export story.md --to pdf --page-size 850mmx2000mm`). The title of the report runs in the
header and `{page} / {pages}` in the footer; `header: {}` and `footer: {}` remove them.

`pdf:` takes the [PDF options](/documentation/configuration/recit-config#pdf-options) of every
paginated format (`outline`, `tagged`, `colorMode`, `output`, `page`, `toc`, `header`, `footer`),
plus `engine` (`chromium` by default, or `pagedjs`) and `tables.repeatHeader` (default `true`).

The table of contents of the PDF is numbered by default, with both engines: Chromium prints two or
three times to read the page of each target, and Paged.js (`engine: pagedjs`) reads CSS
`target-counter`. `toc: { pageNumbers: false }` removes the page numbers:

```yaml
pdf:
  toc:
    pageNumbers: false
```

An external link prints its address in parentheses after its text, unless the text is already the
address.

`print: { glossary: true }` (default `false`) ends the printed document with a glossary: the terms
of the project's [glossaries](/formats/glossary/overview) its sections use (`:term`), sorted by name
in the language of the report, each with its short definition and the page of every use. In print, a
term is a link to its entry instead of a hover card. The contents list the glossary, and both
engines number its pages, like the contents. A poster or a banner has no glossary.

```yaml
print:
  glossary: true
```

### Poster

With `print: { layout: "poster" }`, the printable view lays the report out on a single-page poster
grid; `recit export --to pdf` refuses a poster that takes more than one page because a poster is
meant to be read at a glance on one sheet rather than split across pages.

#### Bleed and crop marks

For a printed poster (`A3`, `A2`, or a custom `{ width, height }`),
`pdf: { engine: pagedjs, page: { bleed: 3mm, marks: crop } }` adds bleed around the trim and crop
marks (`crop` by default when `bleed` is set, `cross`, or `crop cross`; `pagedjs` only). The PDF
stays in RGB: **CMYK is out of scope, and the printer converts**.

### Banner

With `print: { layout: "banner" }`, the printable view renders a single-page banner strip
(`728px × 90px` by default, zero margins, no running header or footer) holding the report title, the
first `:value`, the first link as a call to action and the `brand` signature. `recit validate`
estimates without a browser whether the title, value and call to action stay within character
budgets scaled to `pdf.page.size` width (and wrapped full-width budgets at or below `24em` /
`384px`, such as `300px × 250px`), raising `report-banner-fit` warnings with the source line or JSON
pointer (`recit validate --strict` turns `report-banner-fit` into an error, exit code `1`).
`recit export --to pdf` measures the rendered boxes and the `brand` signature against their boxes
and the banner's inner box in Chromium before printing, warning in the console and under `warnings`
(`code: "overflow"`) in `exports.json` when a part is cut (`--strict` fails the export instead), and
refuses a banner that overflows onto more than one page.

`recit export --to images` captures a `poster` or `banner` report (`print.layout: "poster"` or
`"banner"`) as PNG: `<output>/<story>.png` at the layout's natural size by default,
`<output>/<preset>/<story>.png` into one folder per preset of `--preset` (`og-image`, `mpu`,
`leaderboard`), or `<output>/<W>x<H>/<story>.png` for `--size <W>x<H>`, all listed in
`exports.json`. When a banner part is cut or a poster or banner overflows its page box, the capture
warns in the console and records `warnings` (`code: "overflow"`) on the file entry in
`exports.json`; `--strict` fails the export without writing any PNG or `exports.json`. As for a
[deck](/formats/deck/exporting), each requested preset or `--size` must stay within **25%** of the
`print.layout` page aspect ratio (`max(rTarget / rLayout, rLayout / rTarget) ≤ 1.25`), contained and
centred inside the frame; any target further apart (for example `mpu` on a default `728×90` banner
without a closer `pdf.page.size`) is refused before writing any file. A report without
`print.layout: "poster"` or `"banner"` has no page images and is refused; pass `--charts` to export
its `::chart` figures instead.

```bash
recit export banner.md --to images --preset leaderboard
recit export banner.md --to images --size 1456x180
```

`leaderboard` (728×90) and `mpu` (300×250) are too far apart to come from one layout: a banner sized
for an `mpu` sets `pdf.page.size` to a close size (`{ width: "300px", height: "250px" }`), then
exports with `--preset mpu`.

## QR code

`::qr` draws a vector QR code at build time so a printed report, a poster, a web story card or a
slide can link back to its online page without a bitmap:

```md
::qr{url="https://example.com/report" label="example.com/report" size="30mm" level="M"}
```

| Attribute | Default | Values                                                                                                   |
| --------- | ------- | -------------------------------------------------------------------------------------------------------- |
| `url`     | —       | required `http://` or `https://` address (`javascript:` and `data:` are refused)                         |
| `label`   | `url`   | text printed in clear underneath (`<figcaption>`); defaults to the full address                          |
| `size`    | `30mm`  | side length in `mm` or `px` (`30mm`, `240px`)                                                            |
| `level`   | `M`     | error correction level: `L` (7 %), `M` (15 %), `Q` (25 %) or `H` (30 %)                                  |
| `utm`     | —       | `source:…,medium:…,campaign:…` (overrides `recit.config`'s `utm` field by field), or `none` to strip all |

The directive renders a `<figure class="recit-qr">` with a crisp vector `<svg role="img">`
(`shape-rendering="crispEdges"`, `#000` modules on a `#fff` quiet zone) carrying an accessible name
in the story's language (`QR code to https://…` in English, `Code QR vers https://…` in French), and
the address or `label` in clear underneath (`<figcaption>`) so a reader can also type it. In the
JSON twin as in the `.md` source, `::qr` stays in the Markdown of the scene's `body`.

When `utm` is set in [`recit.config`](/documentation/configuration/recit-config#utm) or on the
directive, `utm_source`, `utm_medium` (`qr` when omitted) and `utm_campaign` are added to the
address encoded in the QR matrix without overwriting any `utm_*` parameter already present in `url`,
while the printed `<figcaption>` and `aria-label` keep the short original address (`utm="none"`
skips tracking on a single code):

```md
::qr{url="https://example.com/report" utm="source:poster,campaign:lorem"}
```

## The JSON twin

Every report has a typed JSON twin (`kind: "story"`, `format: "report"`), with its `data` and its
`settings`, checked by `https://recit.dev/schema/v1/report.json` and converted both ways by
`recit convert`. The examples `report-quarterly` and `report-study` keep theirs on disk
(`quarterly.story.json`, `study.story.json`).

```bash
npx recit convert report.md --to json -o report.json
```

A report section has no format-specific typed field: `scenes` uses the shared scene keys (see
[Scenes › In the JSON twin](/documentation/writing/scenes#in-the-json-twin)), while a
`kind: "sidecar"` companion completes sections by `id`.

| Key            | Type / values                                 | Effect                                                                                                                                   |
| -------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `scenes`       | `object[]`                                    | Required in `kind: "story"`. Sections of the report, in order (`---` separators in Markdown).                                            |
| `scenes.id`    | `string` (non-empty)                          | Required. Stable section identifier across languages (`--- id=…` in Markdown; [Scenes](/documentation/writing/scenes#in-the-json-twin)). |
| `scenes.body`  | `string` or `Record<string, string>`          | Optional Markdown or MDX prose and data directives of the section ([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)).              |

## Commands

| Command                              | What it does                                                                                  |
| ------------------------------------ | --------------------------------------------------------------------------------------------- |
| `recit dev report.md`                | the report with live reload, its data read again when a source changes                        |
| `recit build report.md -o dist`      | the report as static files (`-o, --output`, `./dist`)                                         |
| `recit validate report.md`           | the story against its schema, its data loaded and each data directive evaluated               |
| `recit convert report.md --to json`  | the JSON twin; `--to md` goes back to Markdown                                                |
| `recit export --html report.md`      | one self-contained HTML file                                                                  |
| `recit export --to pdf report.md`    | the PDF of the printable view, listed in `exports.json` (`--locale fr` for one language)      |
| `recit export --to images banner.md` | PNG images of a `poster` or `banner` (`--preset`, `--size`; `--charts` for `::chart` figures) |

Every command and its flags are in [the CLI reference](/documentation/reference/cli).

## Bridges

| From → to         | How                                     |
| ----------------- | --------------------------------------- |
| report → deck     | `recit convert report.md --to deck`     |
| report → webstory | `recit convert report.md --to webstory` |

`recit convert report.md --to deck` writes a deck, one slide per section with the same `id`, the
data directives kept (`reportToDeck` of `@recit/report/bridge`). A `::table` longer than eight rows
gets `limit=8`; a `::chart` beside a `:::kpi` or a `::table` moves to a slide of its own
(`<id>-chart`, under the section's title), so it keeps the slide's width; prose a slide cannot hold
is an error with its line, never an invented summary. `-o deck.json` writes the deck's twin instead.

`recit convert report.md --to webstory` tells each key figure and each chart of the report as a card
(`reportToWebstory` of `@recit/webstory`, owned by its target so the report does not depend on the
webstory format). A key figure's card shows its `:value`, its label under it, then its note.

## Packages

```ts
import fs from "node:fs";
import {
  compileStory,
  DataSourcesSchema,
  extractDeckFrontmatter,
} from "@recit/core";
import { dataDirectives } from "@recit/data/directives";
import { loadDataSources } from "@recit/data/node";
import { storyToReport } from "@recit/report";

const markdown = fs.readFileSync("report.md", "utf-8");
// The `data:` sources of the front matter, read relative to the report
const { metadata } = extractDeckFrontmatter(markdown);
const data = await loadDataSources(
  DataSourcesSchema.parse(metadata.data ?? {}),
  { baseDir: "." },
);
const story = await compileStory(markdown, {
  file: "report.md",
  // The handlers of :value, ::chart, ::table and :::kpi over those sources
  directives: dataDirectives(data.tables),
});
const { report, diagnostics } = storyToReport(story);
```

This is what `recit dev` and `recit build` do. A report without data directives needs only
`compileStory` and `storyToReport`; without `directives`, a data directive is an error
(`directive-without-handler`).

| Import                     | Contents                                                                                     |
| -------------------------- | -------------------------------------------------------------------------------------------- |
| `@recit/report`            | `storyToReport`, `toReportView` and the view types, no React                                 |
| `@recit/report/components` | the components (`Report`, `ReportToc`…)                                                      |
| `@recit/report/runtime`    | `mountReport`, the page of `recit dev` and `recit build`                                     |
| `@recit/report/print`      | `ReportPrint`, `ReportBanner` and `bannerFitIssues`, the printable view and its banner strip |
| `@recit/report/bridge`     | `reportToDeck`                                                                               |
| `@recit/report/node`       | `renderMdxReport`, the sections of a report written in MDX (Node)                            |
| `@recit/report/styles.css` | the stylesheet of the report                                                                 |
| `@recit/data`              | the sources, the aggregates and the charts the directives compute                            |
