code wiki / (root) / nx_mathml_lib.nx

nx_mathml_lib.nx

buildroot/runtime/nx_mathml_lib.nx

20690 B482 linesdepth 4pulls 6 transitivereach 4 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_mathml_lib.nx -- LATEX SUBSET -> MATHML, THE SOVEREIGN MATH TYPESETTER. WHY THIS EXISTS (measured 2026-09-03). The estate had already chosen MathML as its math rendering path and already had the symbols, and NOTHING joined them: nx_paper_native's grammar takes ".MATH <id> <mathml>" with the MathML subtree VERBATIM, so an author had to hand-write MathML; nx_unicode_math carries ~50 UTF-8 math symbols but no layout. nx_capsearch over 7,266 sources (corpus_complete=1) returns no LaTeX reader of any kind. The missing primitive was the CONVERTER, and it is the one every math surface needs: a board note, a paper, a document in the unified portal, and the applied-math UI all want to write a formula the way a mathematician writes it and have it render. WHY MATHML AND NOT A JAVASCRIPT TYPESETTER. MathML is rendered NATIVELY by the browser, so a page that emits it carries NO third-party runtime, no script, and no network fetch -- which is the estate's standing rule that the oracle stays outside and nothing foreign enters the build or run path. A page using MathJax or KaTeX would import the oracle instead of building the twin. This organ therefore emits markup the browser already understands, and the same bytes render in the Nishi browser. SCOPE, DECLARED RATHER THAN IMPLIED. This is a SUBSET of LaTeX math: numbers, identifiers, operators, superscripts, subscripts, fractions, roots, grouping, the Greek letters and the operator/relation symbols nx_unicode_math already carries, and upright function names. It does NOT do matrices, alignment environments, macros, or text mode. ★AN UNKNOWN COMMAND IS REFUSED BY NAME AND NEVER SILENTLY DROPPED: a typesetter that quietly discards what it does not understand produces a formula that is wrong in a way the reader cannot see, which is worse than no formula at all. SAFETY. Every character that reaches the output as CONTENT goes through the shared html escaper (nx_html_escape.nx). The converter never copies raw input into markup, so a formula carrying markup characters cannot break out of its element -- the same escape-by-construction property the unified document portal is built on. license_tier: ORIGINAL

dependencies 3 imports · 3 importers

syscalls.nx nx_html_escape.nx nx_unicode_math.nx nx_mathml_lib.nx nx_math_page.nx nx_mathml.nx nx_mathml_gate.nx

imports: syscalls.nxnx_html_escape.nxnx_unicode_math.nx

imported by: nx_math_page.nxnx_mathml.nxnx_mathml_gate.nx

structs

51struct LmCtx

consts

34const LM_OK: i64 = 0
35const LM_ERR_UNKNOWN_CMD: i64 = 0 - 1 // a backslash command this subset does not implement
36const LM_ERR_SHORT: i64 = 0 - 2 // the output buffer could not hold the result
37const LM_ERR_UNBALANCED: i64 = 0 - 3 // a { without its } , or a } with no
38const LM_ERR_DEPTH: i64 = 0 - 4 // nesting deeper than LM_MAX_DEPTH
39const LM_ERR_EMPTY: i64 = 0 - 5 // nothing to typeset
41const LM_MAX_DEPTH: i64 = 32
42const LM_MAX_CMD: i64 = 32 // longest command name accepted, e.g. leftrightarrow
48const LM_EXPAND: i64 = 24
49const LM_HEAD_RESERVE: i64 = 128

functions

66func lm_slen(s: *u8) -> i64
called by 2: lm_litlm_cmd_is
73func lm_lit(c: *LmCtx, s: *u8) -> i64
83func lm_text(c: *LmCtx, s: *u8, n: i64) -> i64
called by 1: lm_atom calls 1: lm_lit
107func lm_at(c: *LmCtx) -> i64
112func lm_is_digit(b: i64) -> i64
called by 1: lm_atom
117func lm_is_alpha(b: i64) -> i64
called by 1: lm_atom
123func lm_is_space(b: i64) -> i64
called by 1: lm_skip_space
131func lm_skip_space(c: *LmCtx) -> i64
137func lm_cmd_is(c: *LmCtx, a: i64, len: i64, lit: *u8) -> i64
150func lm_symbol(c: *LmCtx, a: i64, len: i64) -> *u8
179func lm_blackboard(letter: i64) -> *u8
191func lm_operator(c: *LmCtx, a: i64, len: i64) -> *u8
227func lm_funcname(c: *LmCtx, a: i64, len: i64) -> *u8
called by 1: lm_atom calls 1: lm_cmd_is
240func lm_group(c: *LmCtx) -> i64;
called by 2: lm_scriptlm_atom
241func lm_atom(c: *LmCtx) -> i64;
called by 2: lm_seqlm_group
242func lm_script(c: *LmCtx, open_tag: *u8, close_tag: *u8) -> i64;
called by 1: lm_atom
245func lm_seq(c: *LmCtx, stop_at_brace: i64) -> i64
called by 1: lm_group calls 3: lm_skip_spacelm_atlm_atom
262func lm_group(c: *LmCtx) -> i64
287func lm_script(c: *LmCtx, open_tag: *u8, close_tag: *u8) -> i64
311func lm_atom(c: *LmCtx) -> i64
424func lm_err_name(e: i64) -> *u8
called by 2: mp_mathmain
437func lm_to_mathml(latex: *u8, n: i64, out: *u8, cap: i64, display: i64, badoff: *i64, badlen: *i64) -> i64
called by 4: mp_mathmainmg_convmain calls 1: lm_lit
480func lm_out_cap_for(n: i64) -> i64