Skip to main content

Headings and numbers

A heading is a text block with a level and, optionally, an id:

<h1 id="method">{label()} Method</h1>

{label()} asks for the number of the heading it is written inside. That is the whole rule: a heading is numbered exactly when something prints its number. Leave {label()} out and the heading is unnumbered — a References heading needs no attribute to stay unnumbered.

Sections​

<section> groups content and may name its heading:

<section labelled-by="method">
<h2 id="method">{label()} System model</h2>
<p>…</p>
</section>

The section is structure only: it groups content and has no visual effect of its own. The number belongs to the heading, not the section. labelled-by is accepted as the name of the grouping, but it has no effect on layout or numbering yet.

Configuring numbers​

Numbering is configured per kind in the project file:

{
"numbering": {
"h1": { "scope": "document" },
"h2": { "scope": "section" },
"figures": { "scope": "document" },
"tables": { "scope": "document" },
"equations": { "scope": "section" },
"h3": { "scope": "document", "style": "lower-roman" }
}
}
  • Scope is document (1, 2, 3) or section (3.1). A kind absent from numbering is unnumbered.
  • Style is arabic (default), lower-roman, upper-roman, lower-alpha or upper-alpha.
  • h1 opens a section either way and resets section counters, so section scope on h1 is an error (scope-h1-section).
  • A section-scoped heading needs a numbered h1 above it; otherwise scope-no-section is reported.

Numbering happens in document order after expansion. An edit that changes the order of instances changes the numbers; an edit that changes what asks for a number also does, because numbering is demand-driven.

Printing a number elsewhere​

label() belongs to the heading it is written inside. Everywhere else, read the generated store:

from "./gen/head.g.mtx" import type { Heading };
from "./gen/head.g.mtx" import const { headings };

export component CiteSec {
prop to: Heading;
return <a to={to}>Section {headings[to].label}</a>;
}
See <CiteSec to="method" /> for the model.

The field is called label, not number: it is the printed representation — "3", "iv", "AA" — whatever the configured style produces.

note

For figures, tables and equations, reading .label is what demands the number. A heading is demanded by label() inside it, not by a store read. A store entry for an unnumbered heading exists, but it has no label field, so asking for one is an error (unnumbered).

Targets and ids​

An id makes an element pointable. Headings, paragraphs, images, tables, divs and pages accept one. Duplicate ids are an error (duplicate-id), because a pointer would be ambiguous.

<a to="id"> draws a link whose destination is wherever that id was rendered. Forward references are fine: destinations are resolved after drawing, not during layout.

A pointer that reaches nothing is an error (dangling-link).

Captions​

A caption is a text block that sits outside the thing it describes:

<col keep gap={2}>
<caption labelled-by="tab-time">Table {tables["tab-time"].label}. Update time per sweep.</caption>
<table id="tab-time" columns={4}>…</table>
</col>

There is no built-in caption numbering. A project writes a caption component that reads the store, which is why changing the caption style for a whole project means changing one component:

export component TableCaption {
prop to: Table;
prop children: markup;
return <caption labelled-by={to}>Table {tables[to].label}. {children}</caption>;
}

Generated stores​

collect writes one module per citable kind:

StoreContents
headingsHeading ids and labels
figuresImage ids used as figures
tablesTable ids
equations\label names inside <math>
refsBibliography records

Each module holds a literal union of ids and a const object:

// gen/fig.g.mtx
export type Figure = "fig-bw" | "fig-2";
export const figures = {
"fig-bw": { label: "1" },
"fig-2": { label: "2" },
};

The union is what makes a citation component type-safe: <CiteFig to="fig-2" /> checks against the ids that exist, and an id that was never collected is a type error before layout begins.

Styles at a glance​

Style12345
arabic12345
lower-romaniiiiiiivv
upper-romanIIIIIIIVV
lower-alphaabcde
upper-alphaABCDE