Skip to main content

Module lists

Module lists 

Source
Expand description

The lists feature (Lists): list environments whose items are begun by \item, the label shown beside each item, and references to items. By default the list environments are itemize, enumerate and description.

§Lists and list kinds

A list is an environment whose body is a sequence of items, each begun by \item. Each list environment has one list kind, which the feature’s configuration, ListsConfig, declares under the environment’s name: for each list kind, whether its items are numbered and which label is shown beside them at each nesting depth (ListKind). The default configuration declares three list kinds:

\begin{itemize}          \begin{enumerate}        \begin{description}
\item First              \item First              \item[Term] What it means.
\item Second             \item Second             \item[Other] More.
\end{itemize}            \end{enumerate}          \end{description}

• First                  1. First                 Term  What it means.
• Second                 2. Second                Other More.

A list nested in an item of another list of the same list kind is at the next nesting depth, and shows the list kind’s next label template: - then ▸ for itemize, (i) then a- for enumerate; the last template serves every deeper list. Only lists of the same list kind are counted: an enumerate inside an itemize inside an enumerate is at depth 2 and shows (i), as in LaTeX. The language guide describes lists for authors.

§The optional argument of a list

Each list environment takes an optional argument, a key-value argument with two keys:

  • label is the list’s own label template, used beside its items in place of the depth’s template. It is written in the language of a counter style’s number template: every #{name} is the item’s number in the number format name, and every other character is FLM text written as is.
  • ref is the list’s own reference template, in the same language: the template through which a reference to one of its items writes the item’s number, in place of the depth’s reference template. The key is named after the key of LaTeX’s enumitem package that does the same.

label= written alone sets both templates to the same text:

\begin{enumerate}[label=(#{alph})]                % (a), (b); \ref: Item~(b)
\begin{enumerate}[label=#{arabic}:, ref=#{arabic}] % 1:, 2:;   \ref: Item~2
\begin{itemize}[label={--}]                        % a dash beside every item

A bracket holding no = and made only of the characters []().:-+*aAiI1 is a short form of label=, the syntax of LaTeX’s enumerate package. With one of the characters a, A, i, I, 1, that character stands for the number in the number format it shows: [(i)] is label=(#{roman}), [1.] is label=#{arabic}., [a-] is label=#{alph}-. With none of them, the text is a fixed label: [-], [*], [+]. A short form that writes a number also sets the reference template: the same text with every full stop, colon and hyphen at its end dropped, so [1.:] is label=#{arabic}.:, ref=#{arabic} and [(i)] refers to its items as (#{roman}). A fixed short form refers to its items by its label. Any other text, a Unicode bullet included, is written with label={…}; a ] inside the bracket is protected by braces. A short form holding two of the five characters is an error, since it could mean two things (BadLabelForm). See list_options, short_form and short_form_ref.

A ref= on a list whose list kind is not numbered has no number to write. It is accepted and reported as a Note (RefIgnored), so that a list can be switched between a numbered and an unnumbered list kind without its bracket being rewritten.

§Items

Inside a list’s body, and nowhere else, \item begins an item. \item is declared in a scoped package (ScopedPackageDef), PACKAGE: a set of element declarations that can be written only inside the bodies and arguments whose declarations refer to the package (see scoped packages); the body of every list environment refers to it. Everything after an \item up to the next one, or to the end of the body, is the item’s content, which is block content (e.g. paragraphs, nested lists). An empty item is still an item. Whitespace and comments before the first \item are skipped; any other content there is the error ContentBeforeItem.

An \item takes an optional key-value argument with one key, tag: FLM content shown as the item’s label in place of the list’s template, in a numbered list as in an unnumbered one. A bracket holding no = outside braces is the whole tag: \item[My tag] is \item[tag={My tag}], and \item[tag={a=b}] protects a =. See item_options.

After an \item and its bracket, \label{item:…} fields attach labels to the item, several of them if needed, as they do after a heading’s title. A label is the text an author writes as \label{type:label} after a construct (see labels); an item accepts the label type item only (LABEL_TYPES).

§The label beside an item

The label shown beside an item is, in this order: its tag; else the list’s own label template; else the label template the list kind declares for the list’s depth.

  • A template that writes a number writes the item’s number through that label template, without the word a reference writes before it: 2. beside the item, Item~2 in a reference. The numbering feature’s stage NUMBER, which records each reference point’s counter value in the counter table, records each item’s number with the counter style of the list’s depth, whose number format is the list’s reference template. To write the label, the list’s rule takes that counter style, replaces its number format by the label template (CounterStyle::with_number_format), and compiles the result once per list when the list is lowered.
  • A template that writes no number is a fixed label, shown beside every item.
  • A list of a list kind that declares no template (description) writes no label of its own, and an item there without a tag is the error MissingTag.

A fixed template on a numbered list (\begin{enumerate}[label={*}]) shows * beside every item. Every item is still counted and has its number, which a reference writes through the same template, Item~*, since label= alone sets the reference template too. An explicit empty label={} shows no label at all. Whether a list is numbered depends on its list kind, never on its template: a template that writes a number on an unnumbered list is the error LabelNamesNumber, and the depth’s template is used instead.

§Numbers

The items of a numbered list kind are numbered by the numbering feature, and by nothing else. Each numbered list kind declares a counter (CounterDecl) and one counter style (CounterStyleDecl) per depth, whose number format is the depth’s reference template (numbers). Each list environment of the list kind is a scoped instance of the counter (see scoped instances and, for authors, the numbering guide), so that each list numbers its own items from one, a list nested in a numbered item of another list is counted within that item, and the enclosing list continues after it.

An item carrying a tag is counted in no counter and has no number: \item[Custom] \item \item shows Custom, 1., 2., as in LaTeX.

In a registry without the numbering feature, nothing numbers items. The counters and counter styles are dropped when the registry is built, with one Note for each of the numbering feature’s two service slots, and a numbered list whose label writes a number shows no label and is reported once (NoNumbering); a fixed label and a tag are still shown.

§References to items

Every \item of a list is one reference point: one place in a document that can be referred to, numbered, or given an anchor (RefPoint; see reference points). Its reference kind is item (KIND), and its anchor is derived from its first label or, for an unlabeled item, from its position (ANCHOR_PREFIX). \ref{item:x} shows what is shown beside the item, through the ordinary path of the references feature:

  • for a numbered item, the word and the number written through the list’s reference template: Item~2, Item~(ii), and (ii) under \ref[noprefix];
  • for an item carrying a tag, the tag, however it is written (\item[Custom], tag=Custom, tag={Custom});
  • for an untagged item of an unnumbered list, its label: the list’s own ([-], label=*, label={--}) where it writes one that can be used, else the label template the list kind declares for the depth, so that \ref{item:x} on an itemize item shows •.

An unnumbered list kind’s reference templates, and a ref= on its lists, have no effect. ItemElement describes how the reference point carries that content.

§What the feature registers

Under a ListsConfig, the feature registers:

  • one value of the element type LIST (flm.lists.list) per list kind, written as the environment of the list kind’s name, carrying a ListElement;
  • the scoped package PACKAGE holding \item, whose element ITEM (flm.lists.item) carries an ItemElement, the item’s reference point;
  • for each numbered list kind, a counter and its counter styles, as peer contributions to the numbering feature’s service slots (numbers);
  • peer declarations (PeerName) of the numbering feature’s counter table and of the references feature’s anchors table, which the list rule reads where they exist, and of the references feature’s argument role DEFINED_LABEL_ARG_ROLE, the role of the argument of an item’s \label field;
  • a build hook (LateInit) that compiles every list kind’s label templates, and a numbered list kind’s reference templates, once the registry’s parsing language (BuiltLang) is built; a template that does not compile, or a label template of an unnumbered list kind that writes a number format, fails the registry build;
  • the lowering rules RULE and ITEM_RULE, and the recomposition rule latex::LATEX_RULE of the latex-recomposed backend;
  • its settings: the fields of ListsConfig as data (crate::core::settings).

§How a list is lowered

On every backend except latex-recomposed, the lowering rule RULE (ListRule) lowers a list to one flm.pres.list node holding, per item, a label content slot and an item content slot. Its kind tokens are, in this order:

  • the list kind’s structural token: LIST_NUMBERED for a numbered list kind, LIST_UNNUMBERED for an unnumbered list kind that declares label templates, LIST_TERMS for a list kind that declares none;
  • the environment’s name;
  • LIST_LABELED, since every item’s label is written as content of the label slot.

Each item’s anchor (the identifier its reference point was given) is carried on the list’s payload (ListPayload), one per entry, read from the references feature’s anchors table where there is one, so that a link to the item leads to it. A list inside a footnote keeps its items’ numbers and anchors where the xnotes feature gathers the footnotes, because the footnotes are shown there with their own content, not with a copy of it.

What each backend makes of the flm.pres.list node:

  • HTML: an <ol>, <ul> or <dl> chosen by the structural kind token, as the HTML contract states; the labeled kind token switches off the marker the browser would draw.
  • Text: each label followed by the item’s blocks, every item’s blocks aligned at one column.
  • latex-recomposed: the general rule is not used; the recomposition rule LATEX_RULE writes the list back as its environment and its items as \items (latex).

A list inside a synthesized value (for example a label template that holds a list) has items that the references feature’s stage ANCHORS_STAGE, which gives each reference point its anchor, and the numbering stage never saw. The list is reported once for each table that holds no entry for those items (flm.run.missing-entry), and it is still written, those items without an anchor and without a number.

ITEM_RULE (ItemRule), the default on every backend, lowers an \item that is inside a list but not directly in its body, which begins no item, to nothing, and reports ItemOutsideList.

§Interactions with other features

  • The numbering feature numbers the items of numbered lists; without it, see Numbers.
  • The refs feature checks the labels, computes the anchors and resolves \ref; without it, no item has an anchor, and nothing is reported.
  • The refpoints feature collects the items’ reference points.
  • The LaTeX family (the latex helpers and the latex-recomposed backend) owns the constructs the recomposition rule stages; without them, that rule is set aside (excluded from rule selection; see PeerName) and the registry still builds.

§Diagnostics

Every condition is reported under flm.lists.* by the lowering rules; each is an Error except the Note RefIgnored, and each item’s documentation states the recovery: UnknownKey, MissingValue, BadLabelForm, BadLabel, LabelNamesNumber, RefIgnored, ContentBeforeItem, MissingTag, NoNumbering, ItemOutsideList, NoEnumitemFormat, NumberReadAsCharacters.

The mistakes in how a list is written (its optional arguments, the content before its first item, an item missing its tag) and the problems of the label beside its items (a template that cannot be used, a numbered list that nothing numbers) are reported by whichever rule lowers the list, so every backend reports them alike, the recomposed LaTeX included. The recomposition rule alone reports NoEnumitemFormat and NumberReadAsCharacters, since only it writes a list’s own templates as LaTeX. A list’s own template that does not compile is reported once: the reference template of a numbered list in a registry with the numbering feature by the numbering stage, which compiles it (flm.numbering.bad-number-format), and every other template by the list’s rule (BadLabel).

§Items of this module

Modules§

latex
The recomposition rule of the lists feature for the latex-recomposed backend (LATEX_RULE, ListLatexRule): it writes a list back as its LaTeX environment, under the list kind’s name, and each item as \item. The rule is the default on the latex-recomposed backend only; the rendering guide describes the output for authors.
numbers
The numbers of list items: the counter and the counter styles that each numbered list kind declares to the numbering feature.

Structs§

BadLabel
The error that is reported when a label template or a reference template in the optional argument of a list is not valid (flm.lists.bad-label).
BadLabelForm
The error that is reported when a short label form contains more than one of the characters a, A, i, I and 1 (flm.lists.bad-label-form).
ContentBeforeItem
The error that is reported when the body of a list contains content before its first \item (flm.lists.content-before-item). Whitespace, blank lines and comments do not count as content here.
ItemElement
The data of the ITEM element, and its Referenceable aspect, which declares the reference point of the item an \item begins.
ItemOptions
What an \item’s optional argument gives: the item’s tag, where it writes one. Returned by item_options.
ItemOutsideList
The error that is reported when an \item inside a list is not placed directly in the body of the list (flm.lists.item-outside-list).
ItemRule
The lowering rule ITEM_RULE of an \item, the default on every backend. A list’s rule lowers the content of its items and never an \item node, so an \item that the lowering reaches on its own is one that begins no item. The rule writes nothing for it and reports it as ItemOutsideList.
ItemTag
An item’s tag, as item_options reads it: the content the author wrote for the item’s label, from \item[My tag], \item[tag=My tag] or \item[tag={My tag}].
LabelNamesNumber
The error that is reported when the label template of an unnumbered list contains a number format (flm.lists.label-names-number).
ListBody
A list’s body as list_items reads it, with the label templates that apply to its items.
ListElement
The data of one element value of LIST: the list kind it is.
ListItem
One item of a list, as list_items reads it: its \item, its tag, its labels and its content.
ListKind
A list kind: what every list environment of one name is, how its items are numbered and which labels are shown beside them.
ListOptions
What a list’s optional argument gives: the list’s own label template and its own reference template, where it writes them in a way that can be read. Returned by list_options.
ListRule
The lowering rule RULE of a list, the default on every backend except latex-recomposed. It stages (builds into the lowered tree; see Lowerer) one flm.pres.list node whose kind tokens are the list kind’s structural token, the list environment’s name and LIST_LABELED, and which holds one entry per item: the item’s label in the label content slot, the item’s content lowered through the rules in the item content slot, and the item’s anchor on the payload (ListPayload). The module documentation of the feature describes the result in full. The rule reports every mistake in how the list is written and every problem of its labels (see the feature’s diagnostics).
Lists
The lists feature (FlmFeature). Under a ListsConfig, it registers one flm.lists.list element value per list kind, written as the environment of the list kind’s name; the scoped package holding \item; the counters and counter styles of the numbered list kinds, as peer contributions to the numbering feature; the build hook (LateInit) that compiles every list kind’s label templates and a numbered list kind’s reference templates; and the lowering rules RULE, ITEM_RULE and latex::LATEX_RULE. See the module documentation.
ListsConfig
The configuration of the Lists feature: the list environments, each environment’s name mapped to its list kind (ListKind).
MissingTag
The error that is reported when an item has no tag in a list that has no label template (flm.lists.missing-tag).
MissingValue
The error that is reported when a key in the optional argument of a list or of an \item is written without = (flm.lists.missing-value).
NoEnumitemFormat
The error that is reported on the latex-recomposed backend when the label template or the reference template of a list contains a number format that LaTeX’s enumitem package does not support (id flm.lists.no-enumitem-format).
NoNumbering
The error that is reported when the items of a numbered list need a number and the registry does not contain the numbering feature (id flm.lists.no-numbering).
NumberReadAsCharacters
The error that is reported on the latex-recomposed backend when the label template or the reference template of a list contains a number format inside content that is read as characters, such as verbatim content (id flm.lists.number-read-as-characters).
OwnLabel
The label template a list writes in its optional argument, as list_options reads it.
RefIgnored
The note that is reported when the optional argument of an unnumbered list contains the key ref (flm.lists.ref-ignored).
UnknownKey
The error that is reported when the optional argument of a list or of an \item contains an unknown key (flm.lists.unknown-key).

Constants§

ANCHOR_PREFIX
The prefix of an item’s anchor, item: an unlabeled item’s anchor is item--<position><four letters>, a labeled item’s anchor is item-<label> (see ANCHORS).
FEATURE
The feature’s registered name, lists.
ITEM
The element of \item, flm.lists.item, carrying an ItemElement.
ITEM_COMMAND
The name of the command that begins an item, item.
ITEM_RULE
The name of the lowering rule of the element ITEM, flm.lists.item.lower.default (ItemRule): the rule of an \item that begins no item.
KIND
The reference kind of an item’s reference point, item.
LABEL_KEY
The key of a list environment’s optional argument that gives the list’s own label template, label.
LABEL_TYPES
The label types an item accepts: item only. \label{item:first} labels an item; a label of another type written after an \item defines nothing and is reported by the label check as flm.refs.label-type-not-accepted.
LIST
The element type name shared by every list kind, flm.lists.list. Each list kind is one element value of this type, carrying a ListElement.
OPTIONS_ARG
The name of the optional key-value argument of a list environment and of an \item, options.
PACKAGE
The name of the scoped package (ScopedPackageDef) that holds \item, flm.lists.items. The body of every list environment refers to it, so \item can be written inside a list’s body and nowhere else.
REF_KEY
The key of a list environment’s optional argument that gives the list’s own reference template, ref: the name the LaTeX package enumitem gives the same key.
RULE
The name of the general lowering rule of the element LIST, flm.lists.list.lower.default (ListRule), the default on every backend except latex-recomposed.
TAG_KEY
The only key of an \item’s optional argument, tag: the item’s tag.

Functions§

enclosing_list
The list in which the \item node node begins an item: the list environment whose body holds node as a direct child. None for an \item located anywhere else, such as in a group or an argument inside a list, which begins no item.
feature
The Lists feature under the default configuration (the list kinds itemize, enumerate and description), ready to be listed in a package entry.
is_item
Whether node is an \item.
item_of
The \item node node read on its own: its tag and its labels, with no content. None for a node that is not an \item.
item_options
Reads the optional argument of the \item node node: the item’s tag, and what could not be read. This function reports nothing; the list’s lowering rule reports what could not be read.
list_items
The items of the list environment node, split at the \item nodes of its body, with the label templates that apply to them.
list_options
Reads the optional argument of the list environment node: the list’s own label template, its own reference template, and what could not be read. This function reports nothing; the list’s lowering rule reports what could not be read.
nesting_chain
The lists of the same list kind as list that contain list, list included, outermost first: its nesting chain. Their number is list’s nesting depth; for a node that is not a list, the chain is empty. For a numbered list kind, the scoped instances under which an item of list is counted are taken from this chain: list itself, and every list of the chain whose item holding the next list is untagged (see ItemElement).
short_form
The label template that the short label form text stands for: Some(Ok(template)) for a text made only of the short form’s characters and holding at most one of the five number characters a, A, i, I, 1; Some(Err((first, second))) for one holding more (its readings with the first and with the second as the number); and None for a text that is not a short form.
short_form_ref
The reference template that the short label form text gives its list. Where short_form reads text as a template that writes a number, it is text with every full stop, colon and hyphen at its end dropped, then translated: 1.: gives #{arabic}, a- gives #{alph}, (i) gives (#{roman}). A short form that writes no number is a fixed label, and its reference template is the label itself: - gives -. None where short_form does not return a template.