Project

EarthSciAST

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

Contents

The Typst math round trip, at the string level

Lean module Esm.Document.Math.RoundTripTypst, formal/Esm/Document/Math/RoundTripTypst.lean at 29ec73bddfdc
Imports Esm.Document.Math.TokTypst

Two printers: printTypst writes an expression (an == at its top is a comparison, as in an event’s condition, and prints as any expression does), and printTypstEqn writes the expression an equation is printed as (Source.eqExpr ), an equation x = faq with output indices in its defining form x_s = …, s ∈ S (Math.print ). The one reader takes both back.

def printTypst (S : Sym) (e : Json) : String

The Typst math spelling of an expression under the symbol table S.

def printTypstEqn (S : Sym) (e : Json) : String

The Typst math spelling of an equation’s expression (==(lhs, rhs)) under the symbol table S: in its defining form when it has one.

def parseTypst (S : Sym) (s : String) : Option Json

Read Typst math under the symbol table S.

theorem parseTypst_printTypst (S : Sym) (e : Json) (he : isE e = true) :
    parseTypst S (printTypst S e) = some e

The Typst round trip: every well-formed expression reads back from its Typst spelling, under every symbol table (collisions included: the printer switches the names involved to the explicit form).

theorem parseTypst_printTypstEqn (S : Sym) (e : Json) (he : isE e = true) :
    parseTypst S (printTypstEqn S e) = some e

The Typst round trip of an equation’s expression, its defining form included.

A template body

A template’s body prints in the defining form when it is a faq with output indices that has one (_s := …, s ∈ S after the template’s head), otherwise as any expression; the printer writes the defining form only when the reader gives the body back.

def defTypstText (S : Sym) (b : Json) : Option (List Char)

The Typst text of a template body in its defining form: the defining form of the stand-in equation y = b (defEq ), without the y, with := for =.

def parseTypstBody (S : Sym) (s : String) : Option Json

Read a template body: an expression, or the defining form (_s := …, s ∈ S).

def printTypstBody (S : Sym) (b : Json) : String

The Typst text of a template body: in the defining form when it has one that reads back, otherwise as any expression.

theorem parseTypstBody_printTypstBody (S : Sym) (b : Json) (hb : isE b = true) :
    parseTypstBody S (printTypstBody S b) = some b

The round trip of a template body.