Skip to main content

Module stdlib

Module stdlib 

Source
Expand description

The standard features of flm-core: the features and backends that make the library a working FLM processor, and the function that adds them to a package.

A feature (FlmFeature) is a Rust value that contributes a related bundle of things to a registry (elements, stages, tables, lowering rules, backends, services, settings) through the feature builder (FeatureBuilder), and a package is a named bundle of features together with the packages it builds on (PackageEntry). A program declares its own package and adds the standard features to it with add_features. The standard features provide:

  • the commands and environments an author writes: inline formatting, literal characters, headings, mathematics, labels and references, verbatim content, lists, footnotes and the other xnotes, hyperlinks, defined terms, theorems, quotations, annotations, images, floats, tables of cells, citations, included files and user definitions;
  • the stages that structure and check a document: block structure, the element index, the table of reference points, numbering, and the checks every workflow runs (see Every workflow validates below);
  • the document’s metadata (title, authors, date), shown before the content, and the table of contents;
  • four output formats: plain text (text), HTML (html), rendered LaTeX (latex-rendered) and recomposed LaTeX (latex-recomposed), the last two built on latex, which every LaTeX backend shares, with the lowering stage, the presentation elements and the pieces (document-level values such as the title, placed before or after the content; Piece) they share (backends);
  • the check workflow, which validates a document and writes no output.

The standard features process no mathematics: the math feature introduces mathematics into the language, and another feature processes it, for example the feature math-passthrough, which carries every formula to the output as written, or a feature of an extension that typesets formulas. A registry that holds the standard features and no such feature builds and plans every standard workflow, and a render reports each formula as an Error (the math module documentation, Processing mathematics).

The standard features have no special status: each registers through the same feature builder a feature of another crate uses, so a program can add commands, change how a standard element is rendered or add an output format without an extension point made for the purpose (see features and packages, and the extension guide for writing a feature or a package).

§Adding the standard features to a package

A program written in Rust declares its package entry, adds the standard features to it with add_features from a StdlibConfig, and adds the entry to a registry builder with RegistryBuilder::use_package:

use flm_core::core::registry::{PackageEntry, RegistryBuilder, RegistryInputs};
use flm_core::stdlib::{self, StdlibConfig};

let mut builder = RegistryBuilder::new();
builder.use_package(stdlib::add_features(PackageEntry::new("std"), StdlibConfig::new()));
let registry = builder.build(&RegistryInputs::new())?;

// The standard features ship the `check` workflow: validation, no output.
assert!(registry.workflow(stdlib::CHECK_WORKFLOW).is_some());

The package’s name is the program’s choice, and so are the features it adds to the package after the standard ones.

StdlibConfig holds the configuration of each of the sixteen standard features that take one; the other seventeen take none. A feature’s configuration is the plain Rust value the feature is constructed from; it is fixed when the registry is built and cannot vary per document or per render (see settings, options and configuration).

A program that reads its settings as data, for example from a document’s front matter, uses add_features_from_settings instead, in the build function of its package’s PackageFactory: the function reads each feature’s configuration from the settings it is given and leaves out the features those settings switch off.

The pipeline guide (crate::guide::pipeline) explains what a run does with the stages the features declare, and the embedding guide (crate::guide::embedding) shows a complete program.

§The standard features and where each is documented

add_features adds the thirty-three features in this order, each once, after the features the package entry holds. Each is given with the module that documents it:

  1. textstyles (features::textstyles): \emph, \textbf, \textit, \texttt.
  2. literals (features::literals): the commands and characters that stand for one character of text, such as \% and ~.
  3. blocks (features::blocks): paragraphs and blocks, typographic substitutions, and the check of the tree contract.
  4. index (features::index): the table of the nodes whose elements carry each aspect.
  5. refpoints (features::refpoints): the table of every reference point.
  6. numbering (features::numbering): counters, counter styles, and the number of every numbered reference point.
  7. math (features::math): inline and display mathematics: the display-math environments, their equation lines and numbers, the text commands of mathematics.
  8. refs (features::refs): \label, \ref, \hyperref, anchors, and the label check.
  9. headings (features::headings): \section to \subparagraph, and heading kinds a program declares.
  10. verbatim (features::verbatim): content taken exactly as written.
  11. lists (features::lists): itemize, enumerate, description and their \items.
  12. xnotes (features::xnotes): \footnote and the other kinds of xnote.
  13. href (features::href): \href, \url and \email.
  14. defterm (features::defterm): the defterm environment and \term.
  15. theorems (features::theorems): theorem, lemma, proof and the other theorem kinds.
  16. quote (features::quote): quote, blockquote and address.
  17. annotations (features::annotations): a reviewer’s highlights and comments, one command per configured reviewer.
  18. graphics (features::graphics): \includegraphics.
  19. floats (features::floats): figure, table and other float types, with their captions.
  20. cells (features::cells): tables of cells, the cells environment.
  21. citations (features::citations): \cite and the list of cited works.
  22. input (features::input): \input, the content of another file.
  23. userdefs (features::userdefs): macros and environments defined by substitution.
  24. lowering (backends::lowering): the lowering stage, and the lowering rules of the structural elements.
  25. metadata (features::metadata): the document’s title, authors and date.
  26. toc (features::toc): the table of contents, a table of the listed headings and a piece placed before the content.
  27. pieces (backends::pieces): what a backend places before or after the document’s content.
  28. text (backends::text): the plain-text backend and the text workflow.
  29. latex (backends::latex): what every LaTeX backend shares.
  30. latex-recomposed (backends::latex_recomposed): the recomposed-LaTeX backend and the latex-recomposed workflow.
  31. latex-rendered (backends::latex_rendered): the rendered-LaTeX backend and the latex-rendered workflow.
  32. html (backends::html): the HTML backend and the html workflow.
  33. check (CheckWorkflow): the collection flm.validated and the check workflow.

The order is the order in which the registry registers them. It breaks the tie between two stages a plan could run in either order, it decides which feature is recorded as the owner of an element value two features both declare (the one placed last), and, where two features define one command name in the same parsing mode, it decides whose definition applies: the later one, and the clash is reported unless the feature order places that feature explicitly after the other, or that feature declares an override. A weak declaration of the name applies only where no feature declares the name ordinarily in that mode, whatever the order (see crate::lang::mint::packages).

§Every workflow validates: the collection flm.validated

A collection is a name for a set of capabilities that any feature may add to: demanding the collection demands every member, and a collection can be demanded but never provided (CollectionDef).

The check feature (CheckWorkflow) declares the collection VALIDATED (flm.validated) and the workflow CHECK_WORKFLOW (check), which demands the collection and nothing else: a run of check validates the document and writes no output. The workflows of the four standard backends, text, html, latex-rendered and latex-recomposed, demand the collection beside their output. A render therefore reports the problems check reports: a label written twice or a cited key with no entry is reported alike by a render and by check.

The members the standard features add are:

  • flm.blocks.contract-checked (blocks): every tree satisfies the tree contract, or its violations are reported.
  • flm.refs.check-labels (refs): no label is written twice, every label’s type is one its construct accepts, and every reference that resolves to nothing is reported.
  • flm.theorems.check-proofs (theorems): every statement that expects a proof and has none is reported, and so is every malformed back-reference of a proof.
  • flm.floats.check-handlers (floats): every content handler that a float type used in the document requires and no feature registers is reported.
  • flm.citations.check (citations): every cited key with no entry is reported.
  • flm.metadata.read (metadata): the document’s metadata is parsed, and the problems the parse finds are reported.
  • flm.input.spliced (input): the content of every included file is in place in the document’s trees.

The feature that processes mathematics adds one more member, the check of the formulas. Its check stage provides flm.math.content, which the math feature declares (a stage has checked the content of every formula), and which no standard feature provides or adds. The feature math-passthrough adds flm.math.content itself; its stage flm.math-passthrough.check accepts every formula and reports every equation line that holds no mathematics. An extension adds to a collection only a capability named under its own stem, so the math-mathjax extension adds math-mathjax.check, which its check provides beside flm.math.content. Where two such features are registered, the plan request prefers one stage, because a capability with two providers and nothing to choose between them makes the plan build fail (PlanError::Contested).

A feature adds its member from its own registration (FeatureBuilder::collection_member), in any order of registration. In a registry that does not hold the check feature, the build drops the member without a diagnostic, so a feature that adds a check still registers on its own. A registry that holds a standard backend feature but not the check feature fails to build, because the backend’s workflow demands the collection flm.validated, which no feature then declares; a program that wants the checks without the rest of the standard features registers check_feature beside its own features.

The checks read the document’s trees as the plan’s rewrites leave them. Where a render of the recomposed LaTeX keeps the use sites of a user definition (to write them back as calls), the checks see the call and not the definition’s expansion; LaTeX checks that content when it compiles the output.

An Error a check reports does not stop a render. The stages of the standard backends have no effect outside the run’s store, so the run’s error gate (see the error gate) does not stop them: the output is computed, and the diagnostics are reported beside it.

An unresolved reference is the only problem whose severity depends on the workflow. The label check of the refs feature reads how the references were resolved, so every plan that demands the collection runs the resolution of references and reports the references that resolve to nothing. A plan that renders nothing cannot know whether a label would resolve in a render, because a render may install the external index of labels defined in other documents (EXTERNAL_INDEX). An unresolved reference is therefore a Warning under check, regardless of RefsRenderOptions, and an Error under a rendering workflow unless those options allow it. A label written twice and a label of a type its construct does not accept are Errors under every workflow, because each is a fact of the document alone.

Modules§

backends
Rendering: the standard backends, and what every backend shares — the presentation vocabulary, the lowering stage and the pieces stage.
features
The standard features of stdlib, one feature per submodule; the standard backend features are in stdlib::backends.

Structs§

CheckWorkflow
The check feature: it declares the collection VALIDATED (flm.validated) and the workflow CHECK_WORKFLOW (check), which demands that collection, and nothing else.
StdlibConfig
The configuration of the standard features: one field for each of the sixteen standard features that take a configuration. The other seventeen features take none.

Constants§

CHECK_FEATURE
The registered name of the CheckWorkflow feature, check. The feature and the workflow it declares (CHECK_WORKFLOW) have the same name.
CHECK_WORKFLOW
The name of the check workflow, check: it demands VALIDATED and nothing else, so a run of it validates the document and writes no output.
VALIDATED
The name of the collection flm.validated, which every check of the standard features joins: demanding it demands every member, so a plan that demands it runs every check the registry holds.

Functions§

add_features
Returns entry with the thirty-three standard features added after the features it holds, each once, in the order the module documentation lists them, with the sixteen configurable features constructed from the fields of config.
add_features_from_settings
Returns entry with the standard features added after the features it holds, in the order of add_features, each configured from the settings, and without the features the settings switch off.
check_feature
Returns the CheckWorkflow feature, ready to be listed in a package entry or registered beside the features whose checks the collection flm.validated gathers.