code wiki / _hdl_build / nx_tex.nx

nx_tex.nx

buildroot/runtime/_hdl_build/nx_tex.nx

32547 B699 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind librarytopic tex
docsdependenciesstructsconstsfunctions

about

nx_tex.nx -- SOVEREIGN LaTeX-math -> presentation MathML renderer (IMS Thrust D, rung 1). The core of the "arXiv PDF->HTML / LaTeX" capability: turn a real, useful subset of LaTeX math into WELL-FORMED presentation MathML (<math>...</math>, every open tag closed) with a tokenizer + a small recursive-descent parser. PURE + DETERMINISTIC (no clock, no network) so it is trivially gateable by exact-MathML KATs. Scratch memory via sys_mmap only. SUBSET COVERED (rung 1): * digits / decimal numbers -> <mn>123</mn> / <mn>1.5</mn> * letters / multi-letter identifiers -> <mi>x</mi> (one <mi> per letter, MathML-standard) * operators + - = < > -> <mo>+</mo> ... ; '*' -> &#x2217; ; '/' -> <mo>/</mo> * superscript a^b -> <msup>base sup</msup> * subscript a_b -> <msub>base sub</msub> * both a_b^c (or a^b_c) on a base -> <msubsup>base sub sup</msubsup> * \frac{a}{b} -> <mfrac>a b</mfrac> * \sqrt{x} -> <msqrt> x </msqrt> * big operators with optional _lower ^upper limits (either order): \sum -> munderover(&#x2211;, lower, upper) (sum-style, limits under/over) \prod -> munderover(&#x220F;, lower, upper) \int -> msubsup(&#x222B;, lower, upper) (integral-style, limits as sub/sup) (one limit -> munder/mover or msub/msup ; no limits -> bare <mo>) * greek \alpha..\omega and \Gamma..\Omega -> the Unicode glyph in <mi> * \cdot \times \div \pm \le \ge \neq \approx \equiv \to \cdots \ldots -> proper <mo> * \infty \partial \nabla -> proper <mi> * grouping { ... } -> <mrow>...</mrow> (transparent) * \left( ... \right) with ( ) [ ] | and \{ \} -> <mrow><mo>(</mo>...<mo>)</mo></mrow> Anything UNSUPPORTED (unknown \command) degrades GRACEFULLY: emitted as an html-escaped <merror><mtext>\name</mtext></merror> and parsing CONTINUES -- never a crash, never malformed output. tx_render writes the full <math ...>...</math>, NUL-terminates, and returns byte length. VERIFICATION DOCTRINE: MathML is a STANDARD (non-novel) format -> the implementation is 100% sovereign here; nx_tex_gate proves the output against hand-verified expected-MathML KATs + a balanced-tag well-formedness check, plus a 3rd-party structural cross-check WHEN a reference (latexml/node) is runnable (otherwise flagged PENDING). No overclaiming. Sovereign: imports only nx_syscalls (sys_mmap). license_tier: ORIGINAL

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_tex.nx nx_math_render_page.nx nx_tex_gate.nx

imports: nx_syscalls.nx

imported by: nx_math_render_page.nxnx_tex_gate.nx

structs

85struct Tx

consts

39const TX_OK: i64 = 0
40const TX_BAD_INPUT: i64 = 2840
41const TX_TOO_BIG: i64 = 2841
44const TX_OUT_CAP: i64 = 65536 // max MathML bytes for one expression (>> any real formula)
45const TX_IN_CAP: i64 = 8192 // max LaTeX source length accepted
46const TX_MAX_DEPTH: i64 = 64 // recursion guard (deep nesting degrades, never loops)
47const TX_NAME_CAP: i64 = 64
48const TX_LIMB_CAP: i64 = 16384 // per-limit side buffer for big operators
51const TX_NUL: i64 = 0
52const TX_SP: i64 = 32
53const TX_DQUOTE: i64 = 34
54const TX_AMP: i64 = 38
55const TX_STAR: i64 = 42
56const TX_PLUS: i64 = 43
57const TX_MINUS: i64 = 45
58const TX_DOT: i64 = 46
59const TX_SLASH: i64 = 47
60const TX_0: i64 = 48
61const TX_9: i64 = 57
62const TX_LT: i64 = 60
63const TX_EQ: i64 = 61
64const TX_GT: i64 = 62
65const TX_UA: i64 = 65
66const TX_UZ: i64 = 90
67const TX_BSLASH: i64 = 92
68const TX_CARET: i64 = 94
69const TX_USCORE: i64 = 95
70const TX_LA: i64 = 97
71const TX_LZ: i64 = 122
72const TX_LBRACE: i64 = 123
73const TX_BAR: i64 = 124
74const TX_RBRACE: i64 = 125
75const TX_LPAREN: i64 = 40
76const TX_RPAREN: i64 = 41
77const TX_LBRACK: i64 = 91
78const TX_RBRACK: i64 = 93

functions

96func tx_emit(t: *Tx, s: *u8) -> i64
104func tx_emit_byte(t: *Tx, b: i64) -> i64
110func tx_is_digit(c: i64) -> i64 { if c >= TX_0 { if c <= TX_9 { return 1 } } return 0 }
called by 1: tx_atom
111func tx_is_lower(c: i64) -> i64 { if c >= TX_LA { if c <= TX_LZ { return 1 } } return 0 }
called by 1: tx_is_alpha
112func tx_is_upper(c: i64) -> i64 { if c >= TX_UA { if c <= TX_UZ { return 1 } } return 0 }
called by 1: tx_is_alpha
113func tx_is_alpha(c: i64) -> i64
120func tx_peek(t: *Tx) -> i64 { if t.pos >= t.n { return 0 } return t.src[t.pos] as i64 }
121func tx_adv(t: *Tx) -> i64 { t.pos = t.pos + 1; return 0 }
122func tx_skip_sp(t: *Tx) -> i64
129func tx_streq(a: *u8, b: *u8) -> i64
139func tx_setz(dst: *u8, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[i] = s[i]; i = i + 1 } dst[i] = 0 as u8; return 0 }
called by 1: tx_op_glyph
142func tx_emit_escaped(t: *Tx, c: i64) -> i64
151func tx_merror(t: *Tx, label: *u8) -> i64
called by 1: tx_command calls 2: tx_emittx_emit_escaped
163func tx_read_cmd(t: *Tx, buf: *u8, cap: i64) -> i64
182func tx_emit_named(t: *Tx, name: *u8) -> i64
called by 1: tx_command calls 2: tx_streqtx_emit
241func tx_op_glyph(name: *u8, b: *u8) -> i64
called by 1: tx_command calls 2: tx_streqtx_setz
256func tx_count_top_elems(s: *u8) -> i64
called by 1: tx_group
288func tx_group(t: *Tx) -> i64
320func tx_render_group_side(t: *Tx, side: *u8) -> *u8
340func tx_command(t: *Tx) -> i64
445func tx_emit_fence(t: *Tx) -> i64
471func tx_factor(t: *Tx) -> i64
523func tx_atom(t: *Tx) -> i64
590func tx_expr(t: *Tx) -> i64
608func tx_expr_until_right(t: *Tx) -> i64
648func tx_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: tx_render
650func tx_render(latex: *u8, out: *u8) -> i64
670func tx_render_inline(latex: *u8, out: *u8) -> i64
691func main() -> i64