Skip to main content

Module xnotes

Module xnotes 

Source
Expand description

The xnotes feature: footnotes, and the other kinds of note set apart from the running text, written \footnote{…} by default.

The guide to the language describes these notes for authors (xnotes).

§Xnotes and xnote kinds

An xnote is a piece of text set apart from the running text, marked where it belongs and shown elsewhere or in place (a footnote, an endnote, a side note); an xnote kind is one way of being an xnote, declared by the feature’s configuration. (The word is made up: “note” alone says too little, and “footnote” or “endnote” each describe one place where the note is shown; the x stands for foot, end, side.) The footnotes written \footnote{…} are one xnote kind; a host adds others, such as endnotes or side notes, through the configuration, and another feature may contribute an xnote kind for the notes its own elements carry. The configuration, XnotesConfig, lists the xnote kinds an author writes, each an XnoteKind; the default configuration lists one, footnote.

§What an author writes

The claim holds in every case.\footnote{Except the empty one, which we
exclude by convention.} The next sentence goes on.

A note holding paragraphs.\footnote{The first paragraph of the note.

  The second paragraph.}

A labeled note.\footnote[\label{fn:appendix}]{See the appendix.}
See \ref{fn:appendix}, or \ref[noprefix]{fn:appendix}.

An xnote is written \<command>[<labels>]{<content>}, where <command> is one of the commands of its xnote kind (XnoteKind::commands). The content is inline content when it is written as one run of text, and paragraphs when it holds a blank line or a block such as a list; the xnote kind’s layout may fix one of the two.

The optional argument holds the xnote’s labels, \label{fn:…}, as many as the author wants, and nothing else. A label is the text an author writes as \label{type:label} to refer to a place from elsewhere. Anything else written in the optional argument is reported (BadLabelArgument; labels_of reads the argument), and the labels written beside it still label the xnote. \label can be written in that argument because the argument’s declaration refers to the references feature’s scoped package flm.refs.label: a scoped package (ScopedPackageDef) is a set of element declarations that can be written only inside the environment bodies and arguments whose declarations refer to it. A \label written after the xnote, as in \footnote{…}\label{fn:x}, is therefore an unknown command, as it is in running text. The label type (the part before the colon) must be the xnote kind’s label_type, fn for footnotes; the references feature reports any other label type (flm.refs.label-type-not-accepted).

An xnote may be written wherever inline content may be written: in a paragraph, a heading’s title, a list item, a \text{…} inside a formula, the template of a user definition. Its commands are available in text mode only, so a \footnote written directly in a formula is not an xnote: it is passed to the formula renderer with the rest of the formula. An xnote may be written inside another xnote’s content, of its own xnote kind or of another. It is then an xnote like any other: numbered, labeled and listed in its xnote kind’s list in document order, its mark placed where it is written, inside the outer xnote’s content. The xnotes feature refuses no position; a feature that contributes an xnote kind and does not accept its xnotes in some positions (inside another xnote, for instance) reports them itself.

§Where an xnote is shown

The placement of an xnote kind (XnotePlacement) says where its xnotes are shown:

  • A listed xnote leaves its xnote mark where it is written: a superscript (the xnote’s number, for a numbered xnote kind) linked to the xnote. Its content is shown in the xnote kind’s list, placed after the document’s content. A listed xnote is inline content attached to the word before it: a space written before \footnote is removed.
  • An in-place xnote is shown where it is written, in brackets, with its mark at the head: as inline content where its content is inline, and as a block of its own where its content holds paragraphs. Such a block ends the paragraph it is written in, as a list does, and the text after it is a new paragraph.

The block-structure pass (crate::lang::rewrites::blocks) decides whether an in-place xnote is a block, from the xnote kind and the node (argument_holds_blocks), before the document’s trees are frozen (no longer changed; see frozen trees). The placement is therefore part of the configuration, fixed when the registry is built, and no render request can change it.

The first xnote of the example above prints, on the plain-text output:

The claim holds in every case.¹ The next sentence goes on.

Footnotes
---------

¹ Except the empty one, which we exclude by convention.

The general rules (XnoteRule, ListRule) state the shapes that the plain-text output receives and that the HTML rules build on; html and latex state what the HTML page and the recomposed LaTeX write; the rendering guide shows the printed results (Xnotes).

§What the feature registers

The xnotes feature (XnotesFeature, an FlmFeature) registers, from its configuration:

  • The elements. One element value of XNOTE (flm.xnotes.xnote) per configured xnote kind that has commands, carrying an XnoteElement; and four synthesized elements, which no document can write: the list of each xnote kind (list_element_name, flm.xnotes.<kind>.list), an entry of a list (ENTRY), the content pointer an entry holds (CONTENT_POINTER), and the node that represents an xnote in content shown again (MARK_OF).

  • The service slot of xnote kinds, KINDS_SLOT (flm.xnotes.kinds, declared with service_slot), which holds every xnote kind of the registry, in order. A service slot is the declaration, by the feature that owns an interaction, of a dotted name, the type of the values the slot takes and its arity; any feature may contribute a value to it (crate::core::services). The feature contributes its configured xnote kinds; another feature contributes an xnote kind of its own through contribute_kind, the function that makes every declaration an xnote kind needs.

  • The table of xnotes, XNOTES (flm.xnotes, an Xnotes): every xnote of the document, by xnote kind, in document order. The collect stage, COLLECT (flm.xnotes.collect), writes it from the table of reference points. It finds xnotes by the reference kind of their points, never by element, so the xnotes of a kind another feature contributes are collected like \footnote (see XnoteSource).

  • The list of each xnote kind. A piece, a document-level synthesized value that a backend places beside the document’s content (Piece), held in the table flm.xnotes.list.<kind> (piece_table) and built by the stage flm.xnotes.build-list.<kind> (ListBuilder); it is declared to the pieces feature as placed after the content and on by default. The documentation of contribute_kind lists every declaration made for a list.

  • For a numbered xnote kind, a counter and two counter styles, declared to the numbering feature (see Numbers, references and anchors below).

  • The lowering rules. A lowering rule (LoweringRule) is written for one element and stages (builds into the lowered tree; see Lowerer) its presentation for the backend being rendered; its default mark says on which backends it is chosen. The general rules are marked default on every backend; a backend with a rule of its own marked default there uses that rule instead (SelectedRules states the rule selection order). The general rules, which a backend uses for every element that has no rule of its own there:

    • XNOTE_RULE (XnoteRule): an xnote becomes its mark for a listed xnote kind, and the bracketed xnote for an in-place one;
    • flm.xnotes.<kind>.list.lower.default (ListRule, one per xnote kind): the list becomes a block holding the title as a heading and a labeled list, one entry per xnote, labeled with its mark;
    • POINTER_RULE (PointerRule): a content pointer becomes the content it refers to;
    • MARK_OF_RULE (MarkOfRule): the node representing an xnote in content shown again becomes the xnote’s mark;
    • ENTRY_RULE (EntryRule): an entry outside its list becomes nothing and is reported.

    The plain-text backend uses the general rules only. The html backend has rules of its own for the xnote and the list (html), which write the same shapes with no bracket text and with a link back from each entry to its mark. The latex-recomposed backend has rules of its own for every element but the entry (latex): an xnote becomes the command \flmXN<kind>, and the list, the content pointer and the node representing an xnote in content shown again become nothing.

  • The stylesheet STYLE (flm.xnotes.style) of the HTML page (html::stylesheet).

  • The settings: the fields of XnotesConfig written as data, one entry per xnote kind under the settings key kinds, keyed by the xnote kind’s name (crate::core::settings).

The standard features include the feature, with the configuration StdlibConfig::xnotes.

§Numbers, references and anchors

Each xnote has two reference points (RefPoint): places in the document that can be referred to, numbered, or given an anchor, the identifier a link points at (see reference points, labels and anchors). ref_points returns the two:

  • The xnote’s own point, whose reference kind is the xnote kind’s name (footnote), carrying the xnote’s labels. The xnote of a numbered xnote kind counts in the kind’s counter, flm.xnotes.<kind>, which the numbering feature counts; its anchor is built from its number (fn-1, or fn-2-1 for a kind numbered within sections), a \ref to it prints the kind’s word and the number (Footnote 1), and \ref[noprefix] prints the number alone (1). The xnote of an unnumbered xnote kind takes its first label as its anchor, or else an anchor built from its position (sn--1kzmq); a \ref to it prints its content where the content is inline, and otherwise prints the label and is reported (NothingToShow).
  • The mark’s point, of the reference kind <kind>-mark (footnote-mark), which accepts no label and always takes an anchor built from its position (fnref--1kzmq): the place in the running text that the entry of a listed xnote links back to.

The references feature’s anchors stage computes the anchors (the table ANCHORS), and the numbering feature the numbers (the counter table COUNTERS), as for every reference point; the xnotes feature computes neither and stores nothing derived from them.

A counter is a dotted name under which things are counted in document order, and a counter style says how a counter value is shown (see counters and counter styles). A numbered xnote kind declares its counter (counter_name) and two counter styles to the numbering feature, as peer contributions to that feature’s service slots (a peer contribution is dropped, with one Note, when the feature that owns the slot is not registered): the reference style flm.xnotes.style.<kind> (style_name: the xnote kind’s words and number format), and the mark style flm.xnotes.style.<kind>.mark (mark_style_name: the xnote kind’s mark template), which a host replaces like any declared counter style. In a registry without the numbering feature, the xnotes of a numbered kind have no number: a reference prints the label, and the collect stage reports NoNumbering once per xnote kind. An unnumbered xnote kind declares nothing to the numbering feature.

§Xnotes in content shown again

Content that is shown a second time, away from where it is written (a heading’s title that a reference prints, an unnumbered float’s caption, a defined term, a list item’s tag), holds no xnote. When such content is copied to be shown again, the xnote’s element replaces the xnote in the copy, through its InCopy aspect, by a node of the element MARK_OF (MarkOf, copied_as), which MarkOfRule writes as the xnote’s mark, linked to the xnote and with no anchor of its own (and as the marks of every xnote of a node that carries several). The xnote itself is shown, listed and reported only where it is written.

§Xnotes carried by another feature’s element

An element of another feature can carry xnotes (for instance an element one of whose arguments is a note). Four things make a node an xnote, and the author’s \footnote goes through the same four:

  1. its xnote kind, contributed through contribute_kind (a kind with no command, since only the xnotes feature declares commands);
  2. the element’s Referenceable aspect, returning the two points of ref_points per xnote;
  3. the element’s XnoteSource aspect, returning per xnote the region of the node that holds its content;
  4. the element’s ApartFromText aspect, including those regions (regions_apart_from_text).

The element’s lowering rules write each xnote with the public staging helpers, so that it is written as \footnote is: stage_mark for a listed xnote kind, stage_in_place for an in-place one, stage_latex on the recomposed LaTeX. Each helper reads the table of xnotes by the node’s address and writes one xnote, identified by its position among the node’s xnotes of its kind; XnoteSource states how a node’s xnotes are paired with their contents. The element’s InCopy aspect returns copied_as, so that its xnotes are shown in a copy as \footnote’s are.

§Interactions with other features

  • numbering numbers the xnotes of numbered kinds. Without it, those xnotes have no number, and NoNumbering is reported.
  • refs declares \label and computes the anchors. Without it, the optional argument accepts no \label: every \label written there is refused like any other content (the first refused item of each xnote is reported as BadLabelArgument), and the marks carry no link and the entries no link back.
  • refpoints writes the table of reference points (REFPOINTS) from which the collect stage finds the xnotes.
  • pieces declares the service slot the lists are declared to. Without it, no backend places a list. A render leaves one xnote kind’s list out through the render options PiecesRenderOptions, with the piece’s name flm.xnotes.list.<kind>.
  • lowering, html, latex and latex-recomposed own the presentation elements, the backends and the LaTeX constructs the rules use, and numbering and refs own the tables the rules read. The feature declares each name it uses with a peer declaration (PeerName), so that it builds in a registry without those features: a rule that produces a presentation element or is the default on a backend that nobody declares is set aside (excluded from rule selection; see PeerName), and a rule that reads a table optionally runs and finds the table absent.

§Diagnostics

Every condition is reported under flm.xnotes.*, and the documentation of each states what the feature does after reporting it: BadLabelArgument, NoNumbering, Empty, PointerRefused, EntryOutsideList, Unpaired, and StageFailed (a stage of the feature could not read or write a table it declared).

§Map of the items

Re-exports§

pub use latex::stage_latex;

Modules§

html
The lowering rules of the xnotes feature for the html backend, and the feature’s stylesheet.
latex
The lowering rules of the xnotes feature for the latex-recomposed backend (its recomposition rules): each xnote is written back as a LaTeX command of its xnote kind’s own, \flmXN<kind>, which the style file defines and a LaTeX author may redefine.
latex_rendered
The xnotes feature on the latex-rendered backend: its definition piece, flm.latex.def.flmx.xnotes (piece), and the one rule of the standard features written for this backend alone, the xnote’s rule RULE (XnoteRenderedRule).

Structs§

BadLabelArgument
The error that is reported when the optional argument of an xnote contains something other than \label commands (id flm.xnotes.bad-label-argument).
Empty
The warning that is reported when an xnote has no content (id flm.xnotes.empty). Content that consists only of whitespace (including ~ and \ ) and comments counts as empty.
EntryOutsideList
Error representing an entry of a list of xnotes (ENTRY) that is lowered by its own lowering rule (id flm.xnotes.entry-outside-list).
EntryRule
The lowering rule of the element ENTRY, ENTRY_RULE, marked default on every backend.
ListBuilder
The stage flm.xnotes.build-list.<kind> (builder_name) builds the list of the xnotes of one xnote kind. The stage runs once for the whole document. It reads the table of xnotes XNOTES, and writes the list as a piece to the table flm.xnotes.list.<kind> (piece_table). This piece is placed after the content of the document.
ListRule
The general lowering rule of the list element of an xnote kind, flm.xnotes.<kind>.list.lower.default (list_rule_name), registered for every xnote kind by contribute_kind and marked default on every backend. The plain-text backend uses it; the html backend uses ListHtmlRule, which adds the links back to the marks, and the latex-recomposed backend ListLatexRule, which writes nothing.
MarkOf
The payload of a node of the element MARK_OF: the xnotes that the node represents in content shown again, which are every xnote of the given xnote kinds that the original node (the node the copy was made from) carries.
MarkOfRule
The general lowering rule of the element MARK_OF, MARK_OF_RULE: the marks of the xnotes that the node represents (MarkOf).
NoNumbering
Error raised when the xnotes of a numbered xnote kind cannot be numbered (flm.xnotes.no-numbering).
PointerRefused
Error representing a content pointer (CONTENT_POINTER) that does not refer to the content of an xnote (id flm.xnotes.pointer-refused).
PointerRule
The general lowering rule of the element CONTENT_POINTER, POINTER_RULE: the content that the pointer refers to (ContentPointer), lowered where the pointer is placed, as it is lowered inside the xnote, through lower_content_pointer.
Rejected
Something written in the optional argument of an xnote that is neither a \label{…}, whitespace nor a comment (text, a group, \textbf{…}, a command that no feature defines there), as labels_of returns it: what was written, and where.
StageFailed
The error that is reported when a stage of the xnotes feature fails because of an error in the program (id flm.xnotes.stage-failed).
Unpaired
Error raised when the two aspects of an element that describe its xnotes return different numbers of xnotes of one kind (id flm.xnotes.unpaired).
XnoteElement
The per-value data of the XNOTE element: the xnote kind that a command writes.
XnoteKind
One xnote kind: one way of being an xnote, a piece of text set apart from the running text (the footnotes written \footnote{…}, the side notes a configuration adds, the notes another feature’s elements carry; see the module documentation of the feature).
XnoteOf
One xnote that a node carries, as XnoteSource returns it.
XnoteRecord
The record of one xnote of the document in the table of xnotes (Xnotes). The record identifies the two reference points of the xnote and the region of its node that contains the content of the xnote.
XnoteRule
The general lowering rule of the element XNOTE, XNOTE_RULE, marked default on every backend.
Xnotes
The table of xnotes (XNOTES, flm.xnotes), which contains a record (XnoteRecord) for each xnote of the document, grouped by xnote kind.
XnotesConfig
The configuration of the XnotesFeature: the xnote kinds an author writes, in the order in which their lists are placed after the content.
XnotesFeature
The xnotes feature, an FlmFeature: footnotes and the other xnote kinds.
XnotesListElement
The per-value data of the list element of an xnote kind (list_element_name): the xnote kind whose xnotes the list holds.

Enums§

Brackets
How the brackets around an in-place xnote are written: the only difference between an in-place xnote written by the HTML rule and one written by the general rule.
XnotePlacement
Where the xnotes of an xnote kind are shown: in a list after the document’s content, or where each one is written.

Constants§

BACKLINK_KIND
The kind token of the link from the entry of a listed xnote back to its mark, xnote-back (written on the HTML page only; see html).
COLLECT
The name of the collect stage, flm.xnotes.collect, which writes the table XNOTES (see Xnotes for what it records).
CONTENT_POINTER
The name of the element of a content pointer, flm.xnotes.content-pointer: a synthesized element, which no document can write, with one element value.
ENTRY
The name of the element of one entry of a list of xnotes, flm.xnotes.entry: a synthesized element, which no document can write, with one element value. ListBuilder creates one entry per xnote.
ENTRY_MARK_ROLE
The role of the mark beside an entry of a list of xnotes, flm.xnotes.entry.mark.
ENTRY_RULE
The name of the lowering rule of the element ENTRY, flm.xnotes.entry.lower.default (EntryRule): an entry lowered outside its list becomes nothing and is reported.
FEATURE
The feature’s registered name, xnotes.
INPLACE_ROLE
The role of the span or the block holding an in-place xnote, flm.xnotes.xnote.inplace.
KINDS_SLOT
The name of the service slot of xnote kinds, flm.xnotes.kinds: it holds every xnote kind of the registry, in order, each an XnoteKind.
KIND_XNOTES
The kind token xnotes, carried by the block holding a list of xnotes, by the presentation list inside it and by an in-place xnote; the xnote kind’s name is the kind token after it. (A kind token is a feature-owned name on a presentation payload that a stylesheet or a lowering rule selects on; see pres::payload.)
LABELS_ARG
The name of an xnote’s optional argument, labels, which holds the \label{…} commands that label the xnote (labels_of reads them).
LINK_KIND
The kind token of the link from a mark to its xnote, xnote.
MARK_OF
The name of the element of the node that represents an xnote in content shown again, flm.xnotes.mark-of: a synthesized element, which no document can write, with one element value.
MARK_OF_RULE
The name of the general lowering rule of the element MARK_OF, flm.xnotes.mark-of.lower.default (MarkOfRule): the node becomes the mark of each xnote it represents, linked to the xnote, with no anchor.
MARK_ROLE
The role of the superscript span around an xnote’s mark in the running text, flm.xnotes.xnote.mark.
POINTER_RULE
The name of the general lowering rule of the element CONTENT_POINTER, flm.xnotes.content-pointer.lower.default (PointerRule): the pointer becomes the content it refers to, lowered where the pointer is placed.
STYLE
The feature’s style identifier, flm.xnotes.style, which the lowering of an xnote and of a list of xnotes requires on every backend but the recomposed LaTeX: the stylesheet html::stylesheet on the HTML page.
TITLE_HEADING
The heading name under which every list of xnotes stages its title, xnotes: a backend’s options that map heading names (such as the HTML render option heading_tags) map it as they map the name of a heading kind (HeadingPayload::name).
XNOTE
The name of the element of an xnote an author writes, flm.xnotes.xnote: one element value per configured xnote kind that has commands, each carrying an XnoteElement.
XNOTES
The name of the table of xnotes, flm.xnotes, whose value is an Xnotes. The collect stage COLLECT writes this table. To read the table in a stage, declare the read with Needs::reads(XNOTES); in a lowering rule, declare it with LoweringDecl::reads(XNOTES).
XNOTE_ARG
The name of an xnote’s mandatory argument, xnote, which holds the xnote’s content.
XNOTE_RULE
The name of the general lowering rule of the element XNOTE, flm.xnotes.xnote.lower.default (XnoteRule): an xnote becomes its mark for a listed xnote kind, and the xnote in place for an in-place one.

Traits§

XnoteSource
The aspect an element implements when its nodes carry xnotes: for one node, which xnote kinds it carries and which region of the node holds the content of each.

Functions§

append_to_last_paragraph
Lowers content, a run of sibling nodes holding paragraphs and blocks or holding inline content, as blocks, with appended at the end of the last paragraph’s inline run, and returns the blocks.
builder_name
The name of the stage that builds the list of the xnote kind kind, flm.xnotes.build-list.<kind> (ListBuilder).
contribute_kind
Makes every declaration that the xnote kind kind needs, on behalf of the feature that b registers.
copied_as
What the element of node, a node carrying xnotes of the xnote kinds kinds, returns from its InCopy aspect, for a copy made for purpose: in content copied to be shown again (ValueContent::Shown), one node of the element MARK_OF that represents every xnote of those kinds the node carries (MarkOf), written as their marks; in a copy of content that a synthesized value holds as its own (ValueContent::Own), the node copied as written.
counter_name
The name of the counter in which the xnotes of the numbered xnote kind kind are counted, flm.xnotes.<kind> (see CounterDecl).
feature
The XnotesFeature with the default configuration (the single xnote kind footnote), ready to be listed in a package entry.
labels_of
Reads the optional argument LABELS_ARG of the xnote node node: the \label{…} commands written there, in order, and every other thing written there that is not whitespace or a comment.
list_element_name
The name of the list element of the xnote kind kind, flm.xnotes.<kind>.list: a synthesized element, which no document can write, with one element value per xnote kind, carrying an XnotesListElement.
list_rule_name
The name of the general lowering rule of the list element of the xnote kind kind, flm.xnotes.<kind>.list.lower.default (ListRule).
mark_style_name
The name of the mark style of the numbered xnote kind kind, flm.xnotes.style.<kind>.mark: the counter style in which an xnote’s mark writes its number (1), made from the kind’s mark template.
piece_name
The name of the piece holding the list of the xnote kind kind, which is also the name of the table holding it: flm.xnotes.list.<kind>.
piece_table
The table of the list of the xnote kind kind, flm.xnotes.list.<kind> (piece_name): the table that the kind’s builder (ListBuilder) writes, and from which the backends place the list after the content.
ref_points
The two reference points of one xnote of the xnote kind kind, labeled by labels and showing content where a reference shows content.
regions_apart_from_text
The regions that node’s xnotes are made from, as the node’s XnoteSource returns them, written as content references.
stage_in_place
Stages (builds into the lowered tree, through lw; see Lowerer) one xnote that the node node carries, of the xnote kind kind, in place: the shape an in-place kind writes where the xnote was written. It also reports the problems of the xnote: Empty and flm.run.missing-entry, in the cases that stage_mark lists.
stage_mark
Stages (builds into the lowered tree, through lw; see Lowerer) the mark of one xnote that the node node carries, of the xnote kind kind: the shape a listed kind writes where the xnote was written. It also reports the problems of the xnote: Empty and flm.run.missing-entry, in the cases listed below.
stage_mark_text
Stages (builds into the lowered tree, through lw; see Lowerer) the mark text of the xnote of the xnote kind kind whose own reference point is point: what a mark shows, in the running text and beside the xnote’s entry in a list alike.
style_name
The name of the reference style of the numbered xnote kind kind, flm.xnotes.style.<kind>: the counter style (CounterStyleDecl) in which a \ref writes an xnote’s number, with the kind’s words (Footnote~1).