$$
\frac{\mathrm{d} N}{\mathrm{d} t} = -\lambda N
$$
The constructs ([`Esm.Document.Source.RItem`](/generated/document-formats/esm-document-source-items#Esm.Document.Source.RItem)), and where they may appear:
* front matter: the first line is `---`, then the YAML of the front-matter entries
([`Esm.Document.Yaml`](/generated/document-formats/esm-document-yaml)), then a line `---`;
* at the start of a line: a fenced block ```` ```esm:description ```` holding a
description verbatim, or ```` ```esm:<key> ```` holding a path block's value in YAML;
a display equation `$$`, its LaTeX on the following lines, then `$$` (optionally
followed by an equation label `{#eq-x}`, which is discarded); a component directive
`::model[Name]` or `::reaction-system[Name]` on a line of its own;
* at the start of a line: a reaction, `$$\ce{…}$$ {#id key=value …}` on one line, in
mhchem ([`Esm.Document.Source.Reaction`](/generated/document-formats/esm-document-source-reaction)) with the rate as LaTeX math over the arrow,
`->[{$k$}]` (braced, since mhchem ends the label at the first `]`), and the reaction's
`id` and other fields in the label;
* at the start of a line: a template, a display whose math is
`\operatorname{f}(a, b) \coloneqq body`, or a rule,
`\text{rule } \operatorname{r}: \; lhs \Rightarrow rhs`; with other fields the display sits in a
container `:::template{key=value …}` or `:::rule{key=value …}` closed by `:::`;
* at the start of a line: a subsystem included by reference,
`::subsystem[Name]{ref="…" key=value …}`;
* at the start of a line: a plot directive `::plot{key=value …}` on one line, an analysis
with exactly one plot: the analysis's fields, the plot as the attribute `plot`;
* at the start of a line: a container `:::initialization` or `:::constraints` on a line
of its own, then display equations, then a line `:::`; each equation in it is an
initialization equation or a constraint;
* anywhere in a line: a declaration `:var[$N$]{…}`, `:param[…]{…}` or `:species[…]{…}`,
the name in LaTeX math and the attributes as `key=value` pairs, each value a YAML
scalar or a single-quoted YAML flow collection (`shape='["x", "y"]'`).
Everything else is prose, which the parser skips: [`lex`](#Esm.Document.Source.Md.lex) reads a construct where one
starts and otherwise drops one character. A code span is skipped whole: a run of
backticks (not a ```` ```esm: ```` fence at the start of a line) runs to the next
occurrence of the same run, so `` `:var[x]` `` or a fenced code block holding an example
is prose; a run with no such occurrence after it is literal. So the parse depends only on
the sequence of constructs ([`lex_render`](#Esm.Document.Source.Md.lex_render)): inserting or removing prose and code spans,
and adding or removing equation labels, never changes it.
Restrictions this places on prose outside code spans ([`Inert`](#Esm.Document.Source.Md.Inert)): prose may not contain a
declaration opener (`:var[`, `:param[`, `:species[`) anywhere, nor start a line with
```` ```esm: ````, `$$`, `::model[`, `::reaction-system[`, `| decl | name |`,
`:::initialization` or `:::constraints`, nor start a line with a table row holding a `rate`
cell (a reaction table, which the lexer refuses). In particular display math (`$$`) at the
start of a line is always a model equation, so outside a model it rejects the file;
illustrative math in prose uses inline `$…$` or another delimiter.
The reader first drops a leading byte-order mark and, when the first line ends in CRLF,
reads every CRLF as LF (`decodeText`).
## Spellings
<div class="lean-decl" id="Esm.Document.Source.Md.fenceEsm">
<div class="lean-decl-head"><span class="lean-kind">def</span> <a class="lean-name" href="#Esm.Document.Source.Md.fenceEsm" title="Esm.Document.Source.Md.fenceEsm"><code>fenceEsm</code></a> <a class="lean-src" href="https://github.com/EarthSciML/EarthSciAST/blob/86bed77c797f79bad4895e685007ce09e6451cf7/formal/Esm/Document/Source/Markdown.lean#L84">source</a></div>
```lean
def fenceEsm : List Char
A declared name, as LaTeX math under the empty symbol table (so it reads the same
whatever else the document declares).
Attribute values: YAML scalars and flow collections
An attribute value is a YAML scalar (100, "mol", true) or a flow collection,
["x", "y"], {a: 1, "b c": [2]}: elements and entries separated by , , keys bare when
they are identifiers that YAML reads as strings, else quoted. A list or object (empty ones
too) is written single-quoted, shape='["x", "y"]', since remark-directive refuses an
unquoted value holding a bracket or brace; inside the quotes ' is ' and & is
&, the character references remark-directive decodes. The unquoted form is still
read.
A value whose YAML starts with a bracket or brace (a list or an object, empty ones
included): micromark-extension-directive, and so remark-directive, refuses such a value
unquoted.
The text of a single-quoted attribute value: ' as ' and & as &, the
character references micromark-extension-directive decodes inside a quoted value.
def fenceAt (f : Nat) (u : List Char) : Option (RItem × List Char)
A fenced block after ```esm:.
Templates and rules
A template is a display whose math starts with its header, \operatorname{f}(a, b) \coloneqq,
then its body: $$, \operatorname{f}(a, b) \coloneqq body on one line, $$. A rule is
\text{rule } \operatorname{r}: \; lhs \Rightarrow rhs. The header (the name, the parameters
as names under the empty symbol table) and the rule’s split at its arrow are read here, by
the lexer; only the body and the left-hand side are math. With other fields the display is
wrapped in a container directive whose attributes hold them, :::template{description="…"}
or :::rule{params='["u"]' priority=1}, closed by a line ::: (attributes after the
closing $$ would keep remark-math from closing the display).
The first two columns are the directive and the name; every other column header is an
attribute key, and a cell is a YAML scalar or empty (the attribute is absent).
The start of a reaction table with a rate column: a line starting with | that has a
cell rate. It is not a reaction notation (Notation.variants, rejected), and the lexer
refuses it rather than skipping it as prose, which would drop its reactions.
def tableAt (f : Nat) (s : List Char) : Option (List RItem × List Char)
A declarations table, at its | decl | name |.
Code spans
A run of backticks in prose opens a code span (or, at the start of a line, a fenced code
block), which runs to the next occurrence of the same run; nothing inside it is a
construct. A run with no such occurrence after it is literal.
The Markdown lexer: the constructs of a text, skipping prose one character at a
time and code spans whole. bol: the text starts at the beginning of a line. A malformed
construct is an error (none).
A reaction the Markdown syntax can hold: sides the side syntax holds, a rate on one
line without $, an id label, and attributes the attribute syntax holds.
Prose that the lexer skips: at no character does a construct start (a block
construct only matters at the start of a line), and it holds no backtick (code spans are
their own pieces, Seg.code). t is the text after the prose.
A document body whose constructs read back: each construct’s content is spellable,
block constructs start a line, labels are labels, and prose is inert.
theorem contBody_many (r : Role) (t : List Char) : ∀ (raws : List String),
(∀ raw ∈ raws, itemOK (.eqn raw) = true) → ∀ g,
(raws.flatMap dispTxt).length + t.length + 4 < g →
contBody r g (raws.flatMap dispTxt ++ dEnd ++ '\n' :: t) = some (raws.map (.eqx r), t)
A container holding several displays reads as their equations, in order: each
display followed by a blank line, then the closing ::: line (the printer writes one
display per container).
theorem lex_render : ∀ (segs : List Seg) (bol : Bool), Valid bol segs →
∀ f, (render segs).length < f → lex f bol (render segs) = some (segItems segs)
The Markdown lexer reads back every valid document body: exactly its constructs,
whatever prose surrounds them and whatever labels the equations carry.