Expand description
The toc feature: the document’s table of contents, as a table of entries
a program can read and as a piece a backend places before the content.
§What it lists
A heading is any node whose element carries the sectioning aspect
(Sectioning): the standard headings
(\section to \subparagraph) and any heading kind an extension declares
alike. The feature lists, in the run’s document order, every heading that
the aspect says is listed (in_toc:
not of a kind declared skip_toc, not written toc=false) and whose level
(level) is at most the
setting depth (3 by default: sections, subsections
and subsubsections). A starred heading is listed like any other. A heading
inside a file brought in as a heading input comes where that file is placed.
Each entry shows what the aspect returns for the heading
(toc_title): for a
standard heading, the alternative title written with the heading key
alt=, and the heading’s title otherwise. A footnote inside the title
shows its mark in the entry, and its note is listed once, where the heading
stands.
§The table and the piece
The stage BUILD (flm.toc.build, BuildToc) writes two tables:
ENTRIES(flm.toc.entries,TocEntries): oneTocEntryper listed heading, in document order: the heading’s address, its level, its first reference point and the content its entry shows. The table holds no number and no anchor: a reader takes both from the counters and anchors tables at the point of use, as the heading’s own lowering rule does, so that every output and the table agree. A program demands the table by its name and reads it without rendering anything.PIECE(flm.toc, aPiece): the table of contents as content, one synthesized value of nested lists. A piece is a document-level synthesized value that a backend places beside the document’s content (see pieces).
The piece is declared before the content and off by default
(PieceDecl::default_on): a render places it only when its pieces
option includes it (pieces.include: [flm.toc]), or when the compose
template of the output requires it. Among the pieces placed before the
content, it comes after the metadata’s.
§The shape of the piece
The value holds three synthesized elements, which no document can write:
PIECE (flm.toc), the root, holding one LIST (flm.toc.list);
a list holds ENTRY (flm.toc.entry) nodes, each carrying a
TocEntryPayload and holding the entry’s title, then, where the entry
has sub-entries, one list of them. The entries are nested by relative
level: an entry whose level is greater than the level of the entry before
it at the same depth goes into a new list inside that entry; a level gap (a
subsubsection directly under a section) nests one list deeper, not two;
the first entry, at any level, is a top-level entry. A heading left out
(too deep, or not listed) is skipped: its listed sub-headings are nested
among the headings kept.
The lowering rules (rules) stage, on every backend:
flm.pres.block { role: flm.toc, kinds: [toc], doc_role: Toc }
└ flm.pres.list { kinds: [unnumbered, toc], entry_levels: [<each entry's level>] }
per entry: label ⇒ nothing
item ⇒ flm.pres.link { href: "#<anchor>", kind: toc }
├ flm.pres.span { role: flm.toc.entry.number } the number
├ " "
└ the title
the sub-list, where there is oneEach entry’s level is its heading’s level, from its TocEntryPayload.
The number is the heading’s number alone, without the word and the
delimiters a reference writes. An entry without a number has no number
span and no space; an entry whose heading has no anchor has no link.
On the HTML page (html), the block is a <nav> with the role
doc-toc, and the page carries the feature’s stylesheet STYLE
(flm.toc.style). The plain-text backend prints the nested lists as it
prints every list whose labels are all empty: one entry per paragraph, at
the left margin, so the nesting shows only through the numbers. In the
rendered LaTeX the block is written through the backend’s contract and the
requirement brings in the feature’s definition piece
(latex_rendered): the title, the entries linked to the headings, and
each entry’s page number as LaTeX gives it. In the
recomposed LaTeX the three elements write nothing (latex): LaTeX builds
its own table of contents, and the piece is not placed on that output
unless a render names it for that backend.
§Settings
The option type TocOptions (depth), bound on the document or on the
render request (Bind::Either): flm: {features: {toc: {depth: 2}}} in
a front matter, -O toc.depth=2 on the command line.
§Interactions with other features
indexandrefpoints: the stage reads the element index, and the table of reference points where therefpointsfeature is registered; without it, no entry has a point, and so no number and no link.numberingandrefs: the rules read the counters and anchors tables where they are computed, under peer declarations (PeerName), so the feature builds in a registry without either.pieces: the piece declaration is a peer contribution to the slotpieces::SLOT; without thepiecesfeature no backend places it.
§Items
- The feature:
Toc,feature,FEATURE,TocOptions. - The table:
ENTRIES,TocEntries,TocEntry. - The stage:
BUILD,BuildToc,TocFailed. - The piece and its elements:
PIECE,LIST,ENTRY,TocEntryPayload,KIND_TOC,NUMBER_ROLE. - The rules:
rules,latex. The style identifier, the stylesheet and the rendered LaTeX’s definition piece:STYLE,html,latex_rendered.
Re-exports§
Modules§
- html
- The stylesheet of the
tocfeature on thehtmlbackend,flm.toc.style(stylesheet), and the markup it selects on. - latex
- The rules of the three elements of the table of contents on the
latex-recomposedbackend: each writes nothing. - latex_
rendered - The definition piece of the
tocfeature on thelatex-renderedbackend,flm.latex.def.flmx.toc(piece). - rules
- The synthesized elements of the table of contents and their general lowering rules, the default on every backend.
- stage
- This module defines the stage
BuildToc, which builds the table of contents of thetocfeature, along with the errorTocFailedthat the stage reports.
Structs§
- Toc
- The
tocfeature: the option typeTocOptions, the tableENTRIES, the stageBUILD, the piecePIECEwith its elements, lowering rules and stylesheet (see the module documentation). - TocEntries
- The table of entries,
flm.toc.entries(ENTRIES): oneTocEntryper listed heading, in the run’s document order. See the module documentation. - TocEntry
- One entry of the table of contents: a listed heading.
- TocEntry
Payload - The payload of an
ENTRYnode: the heading’s first reference point, where it has one, and its level. The entry’s rule reads the number and the anchor of the point from the counters and anchors tables. - TocOptions
- The options of the
tocfeature, bound on the document or on the render request (Bind::Either); in data, the settings of the featuretoc.
Constants§
- BUILD
- The name of the stage that writes the table of entries and the piece,
flm.toc.build(BuildToc). - DEFAULT_
DEPTH - The default of
TocOptions::depth, 3. - ENTRIES
- The typed name of the table of entries,
flm.toc.entries(TocEntries); like every table name, it is also the capability a caller demands to have it computed. - ENTRY
- The name of the synthesized element of one entry,
flm.toc.entry, which carries aTocEntryPayload. - FEATURE
- The feature’s registered name,
toc; also its settings key. - KIND_
TOC - The kind token of the block and of the lists the rules stage,
toc: a stylesheet or a program’s lowering rule can select on it. - LIST
- The name of the synthesized element of a list of entries,
flm.toc.list. - NUMBER_
ROLE - The role of the span holding an entry’s number,
flm.toc.entry.number. - PIECE
- The name of the piece
flm.toc: the name of its table (of typePiece), of its declaration, and of the synthesized element at the root of its content. - STYLE
- The feature’s style identifier,
flm.toc.style, which the general rule of the root (RootRule) requires: the stylesheet on the HTML page (html::stylesheet).