Project

EarthSciAST

The EarthSciML Abstract Syntax Tree format: schema, operators, coupling, and five language bindings.

Contents

This is the documentation for the older version v0.16.0. For the latest release, see v0.17.0.

Hand-written input

Lean module Esm.Document.Math.HandWritten, formal/Esm/Document/Math/HandWritten.lean at ed59cfa2b070
Imports Esm.Document.Math.RoundTripLatex, Esm.Document.Math.RoundTripTypst

The round-trip theorems cover what the printer writes; these checks cover spellings a person writes and the printer never does: binary minus without spaces, scientific literals spaced any way, \, between names, the italic-d derivative against declared names, field keys with LaTeX-special characters, and JSON strings. Each is evaluated by the kernel.

def reads (o : Option Json) (e : Json) : Bool

The parse is e.

Binary minus and negative literals

example source
example : reads (parseLatex S "k-0") (node "-" [k, int 0]) = true

-0 is a minus sign and 0: the literal has no sign to carry.

Scientific literals

example source
example : reads (parseLatex S "3 \\times 10^{n}") (node "*" [int 3, node "^" [int 10, .str "n"]]) = true

A non-integer exponent is not the literal shape: an ordinary product.

The thin space

The italic-d derivative and declared names

Operators in the source formats (esm-spec §1.2, esm 2.4.0)

example source
example : reads (parseLatex S "\\frac{\\partial x}{\\partial a}") (pNode x "a") = true

A derivative along an axis other than t is partial, whichever differential writes it.

example source
example : reads (parseLatex S "\\frac{\\partial x}{\\partial t}") (dNode x "t") = true

Along t, \\partial reads as the time derivative D.

example source
example : reads (parseLatex S "\\partial_{a}(x, k)") (dCallNode "a" [x, k]) = true

The trailing-operand form, and the earlier \\operatorname{D}_{x} spelling of it.

example source
example : reads (parseLatex S "\\nabla x") (node "grad" [x]) = true

The four \\nabla forms, told apart by what follows \\nabla.

example source
example : reads (parseLatex S "\\nabla \\cdot \\nabla x") (node "div" [node "grad" [x]]) = true

Trees, not identities: \\nabla \\cdot \\nabla x is div(grad(x)).

example source
example : reads (parseLatex S "\\nabla x \\cdot k") (node "*" [node "grad" [x], k]) = true

The operand is read at the level of a power base: \\nabla x k is a product with grad(x).

example source
example : (parseLatex S "\\nabla x^{2}").isNone = true

\\nabla x^{2} is refused: the operand of a \\nabla form is not a power.

example source
example : reads (parseLatex Sd "\\frac{dx}{dt}") (dNode x "t") = true

Neither dx nor dt declared: the derivative of x.

example source
example : reads (parseLatex Sdx "\\frac{dx}{dt}") (node "/" [.str "dx", .str "dt"]) = true

dx and dt declared: the declared whole words win, a quotient.

example source
example : (parseLatex Sdx1 "\\frac{dx}{dt}").isNone = true

Only dx declared: no derivative, and dt is unknown, so the input is refused.

Field keys

example source
example : Latex.render (keyToks .latex "a%b$") = "\\mathrm{a{\\char037}b{\\char036}}".toList

A key with LaTeX-special characters prints with each written {\char NNN}.

example source
example : reads (parseLatex S "\\operatorname{foo}(x; \\mathrm{a{\\char037}b} = 1)")
    (mkNode "foo" [x] [("a%b", int 1)]) = true

And reads back.

def oddKey : Json

A node whose field key is not an identifier prints in the escape form, where the key is a JSON string with % and $ as \uXXXX: no raw % or $ reaches the LaTeX.

JSON strings render in KaTeX’s text mode

def strOp : Json

An open operator with a string field holding braces.

example source
example : printLatex S strOp = "\\operatorname{myop}(k; \\mathrm{s} = \\text{\"a\\{b\\}\"})"

The string prints inside \text{"…"} with the braces escaped, not as \u007B, which KaTeX refuses in math mode (“accent \u works only in text mode”).

def oddStr : Json

Every other awkward character is {\char NNN}: $, %, ~, \, a line break, a non-ASCII letter, and (seven digits) a character above 999. No $ or line break reaches the LaTeX, and it reads back.

example source
example : reads (parseLatex S "\\operatorname{myop}(k; \\mathrm{s} = \"a\\u007Bb\\u007D\")") strOp = true

The earlier spelling, the string double-quoted with JSON escapes in math mode, still reads.

Array notation (2026-11-15)

example source
example : reads (parseLatex S "\\operatorname{dlon}") (tNode "dlon" []) = true

A bare \operatorname{n} is a template applied with no bindings; with () it is an open operator with no operands.

example source
example : reads (parseLatex S "a \\times [x + 1]") (node "*" [a, node "+" [x, int 1]]) = true

\times [ outside a region is still a product with a bracket group.

def table : Json

A makearray table, the region product spaced any way.

def filtSet : Json

A lone equality filter followed by a superscript set is the filter, not a dense range.