code wiki / _hdl_build / nx_tex_gate.nx
nx_tex_gate.nx
buildroot/runtime/_hdl_build/nx_tex_gate.nx
about
nx_tex_gate.nx -- REFEREE for the sovereign LaTeX-math -> MathML renderer (nx_tex).
Proves the renderer is CORRECT + produces WELL-FORMED MathML on a battery of hand-verified
Known-Answer Tests, and degrades GRACEFULLY on bad input. GREEN iff every check holds.
CHECKS (all on REAL tx_render output, nothing hand-faked):
A. EXACT-MATHML KATs (11): each LaTeX input must render byte-for-byte to the hand-verified
expected MathML. Covers: x^2 (msup), \frac{a}{b} (mfrac), \sqrt{x+1} (msqrt over mrow),
\sum_{i=1}^{n} i (munderover, sum-style limits), \int_{0}^{\infty} x (msubsup, integral
limits + greek \infty), \alpha+\beta (greek entities), the BM25-style \frac{f}{f+k}
(the exact shape of the ranker the wiki search uses), a_i^2 (msubsup -- sub AND sup on one
base, NOT nested), a relations chain (\le \neq \approx as proper <mo> entities), and
\left( a+b \right) (fenced mrow).
B. WELL-FORMEDNESS: every KAT output passes a balanced-tag check (a tag stack: every opener
is closed by the matching closer in order, no underflow, empty at end) AND is wrapped in a
single <math>...</math>. This is asserted INDEPENDENTLY of the exact-string check, so even
a future renderer change that still produces balanced output is verified structurally.
C. NEGATIVE CONTROL (graceful degradation): an UNSUPPORTED command (\badcmd{x}) must NOT crash
and must yield balanced MathML containing an <merror> fallback (no malformed bytes). A
second teeth case proves the well-formedness checker has TEETH: a deliberately UNBALANCED
string (<math><mrow></math>) must be REJECTED by the checker (else greens are fabricatable).
VERIFICATION DOCTRINE: MathML is a STANDARD (non-novel) format. The renderer is sovereign; rigor
comes from these hand-verified expected-MathML KATs + the balanced-tag well-formedness proof.
A 3rd-party structural cross-check (latexml / node+mathjax) is the NEXT rigor step -- this gate
probes for those tools and logs the cross-check as PENDING when (as here) none is runnable. We do
NOT claim a 3rd-party comparison was made. Evidence -> knowledge/status/tex_gate.log.
Sovereign: imports nx_tex + nx_framed_append + nx_syscalls. license_tier: ORIGINAL
dependencies 3 imports · 0 importers
imports: nx_tex.nxnx_framed_append.nxnx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 32 | const TG_LOG: *u8 = "knowledge/status/tex_gate.log" |
| 33 | const TG_RECCAP: i64 = 1024 |
| 34 | const TG_OUT_CAP: i64 = 65536 |
| 65 | const C_LT: i64 = 60 // < |
| 66 | const C_GT: i64 = 62 // > |
| 67 | const C_SLASH: i64 = 47 // / |
| 68 | const C_SP: i64 = 32 // space |
| 69 | const C_NUL: i64 = 0 |
| 79 | const WF_STACK_MAX: i64 = 256 |
| 80 | const WF_NAME_MAX: i64 = 32 |
functions
| 37 | func tg_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 38 | func tg_num(v: i64) -> i64 |
| 47 | func tg_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != 0 as u8 { dst[off + i] = s[i]; i = i + 1 } return off + i } called by 1: tg_kat |
| 48 | func tg_catn(dst: *u8, off: i64, v: i64) -> i64 |
| 57 | func tg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } called by 1: well_formed |
| 58 | func tg_streq(a: *u8, b: *u8) -> i64 |
| 81 | func well_formed(s: *u8) -> i64 |
| 143 | func tg_kat(name: *u8, latex: *u8, expect: *u8) -> i64 |
| 176 | func main() -> i64 |