Skip to main content

Module construct

Module construct 

Source
Expand description

The four LaTeX construct elements (a macro call, an environment, raw LaTeX text and a definition) with their typed payloads, and the placeholder rule of the recomposed LaTeX.

A construct element is a presentation element that mirrors one construct of an output format, so that format-specific output is structured data in the lowered tree rather than a string (construct element). A lowering rule stages one of these four elements to write LaTeX that no shared presentation element (crate::stdlib::backends::pres) can express: the shared elements include no catch-all element and no element that carries raw bytes for a named format. The four are named flm.pres.latex.<name>, and every LaTeX backend writes them natively. Like every presentation element, each node carries exactly one typed payload on the node’s extension (FlmNodeExt), and holds its content only in its content slots (the named groups of a presentation node’s children; read). A content slot of these nodes is a node slot in techy’s sense (techy’s ParsedSlot): a part of a node’s content outside its arguments, such as an environment’s body.

elementpayloadcontent slots
MACRO (flm.pres.latex.macro)LatexMacroPayload: the command name, the shape of each argument written, and whether the arguments are handed over in one groupone ARG_SLOT per argument that has content (a star has none), in order
ENVIRONMENT (flm.pres.latex.environment)LatexEnvironmentPayload: the environment name, the argument shapes, whether the body is verbatim, whether the arguments are handed over in one group, whether the environment takes its body as an argumentthe argument slots, then the body slot (BODY_SLOT)
RAW (flm.pres.latex.raw)LatexRawPayload: LaTeX text written byte for bytenone
DEFINITION (flm.pres.latex.definition)LatexDefinitionPayload: a macro or environment definition’s name, how many arguments it takes, and how it is written; or a feature’s declaration and the name it is guarded onbody for a macro and a declaration, BEGIN_SLOT and END_SLOT for an environment

An emitter writes every construct from its payload and normalizes the call syntax: a mandatory argument is always braced, no space follows a command name, and \begin{name} is followed directly by its arguments and body. The content of each content slot is the document’s own and is written through the emitter’s sink (super::sink). A definition node is never written where it occurs in the tree: the emitter records the definition for the style file (super::style).

§Projections

Every payload implements PresPayload with a self-contained projection (the value written when a lowered tree is serialized, crate::dump::session, and printed by the projection, crate::dump::project) and has a registered reader that rebuilds the payload from that projection (payload_readers). The projections are: macro: {name, args?, packed?}; environment: {name, args?, verbatim, packed?, body?}; raw: {text}; definition: {kind, name, source?, args?, packed?, robust?, body?, feature?}. The optional keys are written only when they hold something:

  • args: on a call, the list of shape names (LatexArgShape::as_str), one per argument the call writes, present when the list is not empty; on a definition, how many arguments the definition takes, present when it takes at least one.
  • packed: the arguments are handed over in one brace group, one pair of braces around each (LatexMacroPayload::packed, LatexDefinitionPayload::packed); a call and the definition it calls agree on it.
  • robust: a macro definition is written as a robust command rather than as an expandable macro (LatexDefinitionPayload::robust); only a macro definition carries it.
  • body: the environment takes what is written between \begin and \end as its last argument rather than letting LaTeX set it between the begin code and the end code (LatexDefinitionPayload::body_argument, LatexEnvironmentPayload::body_argument); only an environment carries it, its definition and its calls alike, with the same value.
  • source: the name the document declared, where it differs from name.
  • feature: the feature that wrote the definition from its configuration (LatexDefinitionPayload::feature).

§Reading a node’s content slots

Two readers at the end of the module (arg_slots, slot_named) pair a node’s content slots with its payload for an emitter.

§The placeholder rule

When a lowering rule of the latex-recomposed backend copies a template (the template of a kept user definition, kept, or a list label template), it records on the copy of each placeholder a LatexPoint value: the LaTeX text written at that placeholder. The placeholder rule (placeholder_rule, flm.placeholder.lower.latex-recomposed), which the latex feature registers, writes that text.

Structs§

LatexDefinitionPayload
The payload of flm.pres.latex.definition: a macro or environment definition, or a feature’s declaration (LatexDefinitionKind::Declaration), that the style file must hold for the recomposed LaTeX to compile.
LatexEnvironmentPayload
The payload of flm.pres.latex.environment: the environment’s name, the shape of each of its arguments, whether its body is verbatim, and whether the environment takes its body as an argument of its own.
LatexMacroPayload
The payload of flm.pres.latex.macro: the command’s name and the shape of each of its arguments, in the order they are written.
LatexPoint
The LaTeX text that a copy of a template writes at one of the template’s placeholders: for a kept user definition, the parameter (#1) that a placeholder of one of its arguments becomes, or a part of the test that a conditional becomes; for a list label template, the enumitem command that a number format becomes.
LatexRawPayload
The payload of flm.pres.latex.raw: LaTeX text the emitter writes byte for byte. The node is childless.
PlaceholderLatexRule
The implementation of PLACEHOLDER_LATEX_RULE: it lowers a copy of a template node that carries a LatexPoint to a raw LaTeX node (LatexRawPayload) holding the carried text: the parameter that a placeholder of a kept user definition becomes, a part of the test that a conditional becomes, or the enumitem command that a number format of a list’s own label template becomes.

Enums§

LatexArgShape
The shape of one argument of a macro or environment construct: how the emitter writes the argument, and whether the argument has a content slot.
LatexDefinitionKind
What a flm.pres.latex.definition node defines: a macro, an environment, or a feature’s declaration.

Constants§

ALL
The four construct elements, in registration order.
ARG_SLOT
The name of every argument’s content slot on a macro or environment node. The name repeats once per argument, so these content slots are read by index (arg_slots).
BEGIN_SLOT
The name of the content slot holding an environment definition’s begin code.
DEFINITION
flm.pres.latex.definition — a macro or environment definition, or a feature’s declaration, written into the style file and never where the node occurs in the tree.
END_SLOT
The name of the content slot holding an environment definition’s end code.
ENVIRONMENT
flm.pres.latex.environment — an environment: \begin{name}, its arguments, its body, \end{name}.
MACRO
flm.pres.latex.macro — a macro call: \name followed by its arguments, one content slot per argument that has content.
PLACEHOLDER_LATEX_RULE
The name of the placeholder rule, flm.placeholder.lower.latex-recomposed.
PLAIN_ARGUMENT_LIMIT
The largest number of arguments a definition written into the style file takes one by one: nine, because a LaTeX macro body can refer to nine parameters (#1 to #9).
RAW
flm.pres.latex.raw — raw LaTeX text written byte for byte; the node has no children.

Functions§

arg_slots
The arguments of a macro or environment node paired with their content slots: for each shape in args, the shape and the content of its content slot — None for a Star, which has no content slot, and for an argument the node carries no content slot for (a hand-built node; a node a rule built always has them).
payload_readers
The payload readers of the four construct elements: what a reading session (reader_with) needs, beside the shared vocabulary’s own (payload_readers), to read a stored lowered tree of a LaTeX backend back into typed payloads.
placeholder_rule
The placeholder rule (PlaceholderLatexRule), ready to be registered by the latex feature (super::LatexFamily). It is written for the language’s placeholder element, produces flm.pres.latex.raw, and is the default on the latex-recomposed backend only, the only backend for which templates are copied with LatexPoint values.
register
Registers the four construct elements with their payload types. The latex feature (super::LatexFamily) calls this from its own registration; a second registration in one registry declares the elements twice and fails the build.
slot_named
The content of the content slot named name on node, the first one of that name when the name repeats; None when the node has no such slot.