Skip to main content

Module theorems

Module theorems 

Source
Expand description

The theorems feature: the theorem-like environments of mathematical writing. These are numbered, titled block environments such as theorem, lemma and definition, and the proof environment, whose title can refer back to the statement it proves. Every environment is declared from the feature’s configuration (TheoremsConfig), so a host can add environments of its own (an exercise) or remove shipped ones.

§What an author writes

\begin{lemma}[Key lemma]\label{lem:key}
  Every bounded monotone sequence converges.
\end{lemma}

\begin{proof}[*lem:key]
  By completeness.
\end{proof}

prints, on the text backend,

Lemma 1 (Key lemma). Every bounded monotone sequence converges.

Proof (Lemma 1). By completeness. □

Each environment is one theorem kind (lemma above). It takes an optional title in brackets, then two fields in any order, \label{…} (repeatable) and \noproofref (which says that no proof of the statement is coming), and a body laid out as blocks (elements). A proof’s title written [*lem:key] is a back-reference: it refers to the statement labeled lem:key and shows that statement’s word and number in the proof’s heading; [**lem:key] refers to the same statement and shows nothing in the heading. The language guide describes these environments for authors under Theorems.

§Theorem kinds and theorem classes

Every theorem kind belongs to one theorem class (TheoremClass), which holds what a family of kinds shares: whether its kinds are numbered and in which counter, the heading template, the closing mark, and whether a title beginning with * is read as a back-reference. A kind (TheoremKind) adds its words (Lemma, Lemmas, and variants such as the abbreviation Lem.) and whether each of its statements expects a proof. The default configuration (TheoremsConfig::new) declares:

  • theorem, proposition, lemma, corollary and conjecture in the class theoremlike, and definition and remark in the class definitionlike, all numbered in one shared counter;
  • proof in the class prooflike: unnumbered, closed by the mark □, its title read as a back-reference.

The feature’s code refers to no kind and no class by name: a host’s exercise is an environment in its own right, declared in the configuration. The configuration is fixed when the registry is built (see settings, options and configuration).

§Numbers, labels and back-references

Every theorem is one reference point of the reference kind theorem (see reference points, labels and anchors). A theorem of a numbered kind is numbered by the numbering feature in its class’s counter and shown in a counter style of its kind, whose words are the kind’s (numbers): \ref{lem:key} reads Lemma~1; in a document that numbers theorems within sections it reads Lemma~2.3 on every output except the recomposed LaTeX, where LaTeX numbers the theorems (see the limitation). Its anchor is the environment’s name and its number, lemma-1. A theorem of an unnumbered kind accepts no label and has no anchor.

A back-reference is a reference site, which the references feature resolves as it resolves \ref. title_reading is the function that decides whether a title is a back-reference. On a class that reads back-references, a title that begins with a star is kept as typed: its reader places it under an opaque wrapper, so that its label meets the label of a \label as written, and [*lem:a--b] refers to \label{lem:a--b}. Every other title is content (see a starred title is kept as typed).

§The check of proofs

A statement of a kind that expects a proof (by default theorem, proposition, lemma and corollary) should have a proof whose back-reference refers to it, unless it carries \noproofref. The feature’s check stage (check) reports a statement that has neither as the Warning flm.theorems.missing-proof, and a title that begins with a star but is not a well-formed back-reference as the Error flm.theorems.bad-relation-ref. The stage is a member of the flm.validated collection, which every standard workflow demands, so it runs, with the same reports, under the check workflow and under every render. It reads the document tree: a theorem inside a user definition that the plan keeps unexpanded is not checked (see check).

§What the feature provides to the pipeline

  • Elements. THEOREM (flm.theorems.theorem), with one element value per configured kind, available in text mode. Three synthesized elements, NAME_ELEMENT, TITLE_POINTER and RELATION, hold the parts of a theorem’s heading (heading); no document can write them.
  • The general lowering rules, each the default on every backend: THEOREM_RULE and the rules of the three heading elements, NAME_RULE, TITLE_POINTER_RULE and RELATION_RULE. A theorem becomes a flm.pres.block of role flm.theorems.theorem whose kind tokens are the class’s name and the kind’s (theoremlike lemma), with its heading as a run-in decoration at the head of its first paragraph and, for a class with a closing mark, the mark as a final decoration at the end of its last paragraph (rules; see decorations and roles and kinds). The heading is the class’s heading template, with the kind’s word and number in a span of role flm.theorems.name and the title in a span of role flm.theorems.title; the title is lowered where the heading shows it, never copied (heading). The text and html backends write a stop after the heading (their render option run_in_stop, a period by default; see TextRenderOptions::run_in_stop and HtmlRenderOptions::run_in_stop) unless the heading already ends in punctuation; the text backend writes a non-breaking space before the closing mark. At every theorem the general rule requires the feature’s style identifier flm.theorems.style (html::STYLE).
  • On the html backend, the stylesheet flm.theorems.style (html), which the requirement brings into a page holding a theorem and which sets the kind’s word and number apart from the title.
  • On the latex-rendered backend, the definition piece flm.latex.def.flmx.theorems (latex_rendered), which the same requirement brings into the style file and which registers the look of each class of theorem.
  • On the latex-recomposed backend, rules of their own (latex): a theorem is written back as the environment the author wrote, and the style file declares each kind the document uses. A proof’s back-reference is written in one of two forms, which the backend’s render option resolved_proof_refs chooses: as the author wrote it, for the phfthm LaTeX package to read (the default), or resolved into the proof’s title, over the amsthm package alone. The rendering guide describes this output under Theorems in the recomposed LaTeX.
  • Counters and counter styles (numbers), contributed to the numbering feature’s service slots.
  • A check stage, CHECK_PROOFS (flm.theorems.check-proofs), providing the capability of the same name, a member of the flm.validated collection (check).
  • A configuration, TheoremsConfig, whose fields are the feature’s settings keys. A build hook (LateInit) compiles the heading templates, the closing marks and the kinds’ words once the language is built; a text that does not compile fails the registry build.

§Interactions with other features

  • The numbering feature. Without it, no theorem is numbered: a heading shows the kind’s word alone (Theorem), and a theorem’s anchor comes from its first label.
  • The references feature. It resolves labels and back-references and computes anchors. Without it, no label resolves, a theorem has no anchor, a back-reference shows its label’s text, and the check reports no missing proof.
  • The feature reads the tables of these two features optionally, and declares them through peer declarations (PeerName); it declares the same way the argument role that the references feature gives the argument of a theorem’s \label field (DEFINED_LABEL_ARG_ROLE). It therefore builds and renders in a registry that holds neither. The rules of the latex-recomposed backend are registered under peer declarations of their backend and of the LaTeX family’s elements; in a registry without them, those rules are set aside (excluded from rule selection; see PeerName).
  • User definitions. A theorem written in a user definition’s template is checked and numbered where the template is expanded in the tree. The title’s reader sees a star written in the template ([*#1]), and keeps that title as typed. It does not see a star that arrives through a placeholder (a template [#1] used as \pf{*lem:a--b}): that title is laid out as content, and a label holding --, quotes, an apostrophe or ... does not resolve through it. A theorem in the template of a kept definition (a user definition whose use sites the plan leaves in the tree; see kept definitions) whose title holds a placeholder where a back-reference’s star could be is expanded at each use site instead (TitleReading::Unknown).

§Map of the items

Re-exports§

pub use check::CHECK_PROOFS;
pub use elements::NOPROOFREF_FIELD;
pub use elements::POINT_KIND;
pub use elements::THEOREM;
pub use elements::TITLE_ARG;
pub use elements::TheoremElement;
pub use elements::TitleReading;
pub use elements::has_noproofref;
pub use elements::theorem_args;
pub use elements::title_reading;
pub use heading::NAME_ELEMENT;
pub use heading::NAME_PLACEHOLDER;
pub use heading::NAME_ROLE;
pub use heading::NAME_RULE;
pub use heading::NameRule;
pub use heading::RELATION;
pub use heading::RELATION_RULE;
pub use heading::RelationRule;
pub use heading::TITLE_PLACEHOLDER;
pub use heading::TITLE_POINTER;
pub use heading::TITLE_POINTER_RULE;
pub use heading::TITLE_ROLE;
pub use heading::TitlePointerRule;
pub use rules::THEOREM_RULE;
pub use rules::TheoremRule;

Modules§

check
This module defines the check stage CHECK_PROOFS (flm.theorems.check-proofs) of the theorems feature. The stage checks that each theorem whose kind expects a proof has a proof, and that the back-references in the titles of proofs are valid. In this module, a theorem is an environment of any theorem kind, such as lemma or proof.
elements
The element of the theorems feature, THEOREM (flm.theorems.theorem), with one element value per configured theorem kind: its arguments and fields, the reference point every theorem declares, and the back-reference a proof’s title declares (title_reading).
heading
The heading and the closing mark of a theorem: the compilation of every class’s heading template, every class’s closing mark and every kind’s word when the registry is built; the instantiation of a heading at a theorem; and the three synthesized elements that an instantiated heading holds, with their general lowering rules.
html
The stylesheet of the theorems feature on the html backend, flm.theorems.style (stylesheet), and the markup it selects on.
latex
The lowering rules of the theorems feature for the latex-recomposed backend, and the definition pieces they require. The rendering guide describes this output for users under Theorems in the recomposed LaTeX.
latex_rendered
The definition piece of the theorems feature on the latex-rendered backend, flm.latex.def.flmx.theorems (piece).
numbers
The numbers of theorems: the counters and the counter styles that the theorems feature declares. 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.
rules
The general lowering rule of a theorem, TheoremRule (THEOREM_RULE), the default on every backend that has no rule of its own for theorems: a block that opens with the theorem’s heading and, for a class with a closing mark, closes with the mark.

Structs§

BadRelationRef
The error that is reported when the title of a proof begins with a star but is not a valid back-reference (id flm.theorems.bad-relation-ref).
MissingProof
The warning that is reported when a theorem has no proof although its kind expects one (id flm.theorems.missing-proof).
PointerRefused
Error representing a node of a theorem heading whose content pointer does not refer to the title of a theorem (id flm.theorems.pointer-refused).
StageFailed
Error raised when the check stage of the theorems feature fails to read a table (id flm.theorems.stage-failed).
TheoremClass
One theorem class: what a family of theorem kinds shares. A class says whether its kinds are numbered and in which counter, how their heading is written, whether a closing mark ends them, and whether a title beginning with * is read as a back-reference to the statement a theorem proves.
TheoremKind
One theorem kind: one environment an author writes, such as theorem, lemma, proof or a host’s exercise. Its key in TheoremsConfig::kinds is the environment’s name.
Theorems
The theorems feature (FlmFeature): it registers one element value of THEOREM per kind of its TheoremsConfig, each written as the environment of the kind’s name, together with the heading elements, the lowering rules, the check stage, and the counters and counter styles of the numbered kinds (contributed to the numbering feature). See the module documentation.
TheoremsConfig
The configuration of the Theorems feature: the theorem classes and the theorem kinds, the number format of every kind, and the label types every numbered kind accepts.

Constants§

ABBREVIATED_VARIANT
The name of the variant of a theorem kind’s words written abbreviated, abbreviated: \ref[abbreviated]{lem:x} reads Lem.~4 where the kind declares that variant. The references feature defines the name.
CAPITAL_VARIANT
The name of the variant of a theorem kind’s words written with a capital initial, capital: the variant that \ref[S]{…} and \ref[capital]{…} ask for. The references feature defines the name.
DEFAULT_CLOSING_MARK
The closing mark of the shipped theorem class prooflike, □ (TheoremClass::closing_mark).
DEFAULT_HEADING
The heading template of every shipped theorem class, #{name}\IfValueT{#{title}}{ (#{title})}: the kind’s word and number, then the title between parentheses where the theorem has one, as in Lemma 4 (Key lemma), or Lemma 4 alone (TheoremClass::heading describes the placeholders).
DEFAULT_LABEL_TYPES
The label types a numbered theorem kind accepts by default (TheoremsConfig::label_types): thm, prop, cor, lem, rem, def, dfn, x and topic. Every numbered kind accepts every one of them: \label{lem:x} on a theorem is accepted.
FEATURE
The feature’s registered name, theorems.
LOWERCASE_VARIANT
The name of the variant of a theorem kind’s words written all in lowercase, lowercase: \ref[lowercase]{lem:x} reads lemma~4. The references feature defines the name.

Functions§

feature
The Theorems feature under the default configuration (the eight kinds of TheoremsConfig::new), ready to be listed in a package entry (PackageEntry).