Version: dev

This is the documentation for the development version. For the latest release, see v0.12.1.

Hand-written input

Lean module Esm.Document.Math.HandWritten, formal/Esm/Document/Math/HandWritten.lean at 184aa13d35e5
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

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.