Hand-written input
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.
Binary minus and negative literals
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 : 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 : reads (parseLatex Sd "\\frac{dx}{dt}") (dNode x "t") = true
Neither dx nor dt declared: the derivative of x.
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 : (parseLatex Sdx1 "\\frac{dx}{dt}").isNone = true
Only dx declared: no derivative, and dt is unknown, so the input is refused.
Field keys
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 : 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
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.