nx_paper_native.nx
buildroot/runtime/nx_paper_native.nx
about
nx_paper_native.nx -- PAPERS AS NATIVE NISHI DOCS, NOT PDF (operator 2026-08-13: "i dont want
the papers in 3rd party formats like pdf ... ingested into html or whatever from the first bit
up we can do in nishi that makes it native to nishi os and browser").
NXPAP2 (2026-08-14) -- v1 was a readable DIGEST, measured NOT sota. Against the real LaTeXML
source of one paper (arXiv 2411.15205, 242,460 B) v1 preserved: 0 of 82 <math>, 0 of 8 <figure>,
0 of 84 bibitems, and collapsed all 10 <h3> subsections into their parent section. It also
DECODED source entities (< -> <) and then copied section text into HTML unescaped, so decoded
markup reached the page raw. NXPAP2 fixes all of it, and REFUSES rather than drop silently.
FORMAT: line-oriented, greppable, sovereign. Header `KEY\tVALUE` lines, then typed blocks:
.SEC <level>\t<id>\t<title> sectioning, level 1..3, id = the source anchor
.PARA <inline> one paragraph of SAFE inline html (see below)
.MATH <id>\t<mathml> display equation, MathML subtree VERBATIM
.FIG <id> figure open | .TBL <id> table open
.IMG <url> one image of the current figure (absolute url)
.CAP <inline> caption of the current figure/table
.ROW <cell>\t<cell>... one table row, cells are inline
.REF <key>\t<label>\t<text> one parsed reference
SAFE INLINE is the load-bearing invariant: source entities are kept VERBATIM (never decoded),
every tag is dropped except (a) <math>..</math> copied byte-for-byte so MathML survives to the
browser natively, and (b) fragment links rebuilt as anchors so citations and cross-references
stay real links. Nothing else reaches the output, so the emitted page cannot carry injected
markup -- escaping is by construction, not by a filter that must be remembered.
FIDELITY IS ENFORCED, NOT HOPED FOR: the ingest counts <math>, <figure> and bibitems in the
SOURCE and in what it EMITTED, prints both, and REFUSES (exit 3) if it emitted fewer. A silent
drop -- the v1 defect -- is impossible by construction.
nx_paper_native abs <cvf-abstract.raw> <out.nxpap> [arxiv-html.raw]
nx_paper_native view <in.nxpap> <out.html>
exit: 0 ok | 1 io | 2 usage | 3 refuse (named). license_tier: ORIGINAL. No hw writes (Rule 26).
dependencies 1 imports · 0 importers
imports: nx_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
| 35 | const PN_MAGIC_1048576: i64 = 1048576 |
| 43 | const PN_ARXBASE: *u8 = "https://arxiv.org/html/" |
functions
| 45 | func pn_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 46 | func pn_puts(s: *u8) -> i64 { sys_write(1, s, pn_len(s)); return 0 } |
| 47 | func pn_num(v: i64) -> i64 |
| 59 | func pn_app(d: *u8, off: i64, s: *u8) -> i64 |
| 65 | func pn_appn(d: *u8, off: i64, src: *u8, a: i64, b: i64) -> i64 |
| 71 | func pn_find(src: *u8, a: i64, b: i64, pat: *u8) -> i64 |
| 92 | func pn_count(src: *u8, a: i64, b: i64, pat: *u8) -> i64 |
| 102 | func pn_num_to(d: *u8, off: i64, v: i64) -> i64 |
| 113 | func pn_attr_s(src: *u8, a: i64, b: i64, attr: *u8) -> i64 |
| 118 | func pn_write(path: *u8, buf: *u8, n: i64) -> i64 |
| 127 | func pn_txt(d: *u8, off: i64, src: *u8, a: i64, b: i64) -> i64 |
| 155 | func pn_inline(d: *u8, off: i64, src: *u8, a: i64, b: i64, cnt: *i64) -> i64 |
| 232 | func pn_figure(d: *u8, off: i64, src: *u8, a: i64, b: i64, istbl: i64, cnt: *i64) -> i64 |
| 315 | func pn_refs(d: *u8, off: i64, src: *u8, a: i64, b: i64, nref: *i64) -> i64 |
| 382 | func pn_bodystart(src: *u8, n: i64) -> i64 |
| 389 | func pn_body(d: *u8, off: i64, src: *u8, n: i64, cnt: *i64, nfig: *i64, nref: *i64, nsec: *i64) -> i64 |
| 508 | func pn_meta(src: *u8, a: i64, b: i64, key: *u8, r: *i64) -> i64 |
| 521 | func pn_hdr(out: *u8, off: i64, fb: *u8, n: i64, key: *u8, label: *u8, r: *i64) -> i64 |
| 532 | func pn_ingest(inp: *u8, outp: *u8, axp: *u8) -> i64 |
| 637 | func pn_field(fb: *u8, p: i64, e: i64, idx: i64, r: *i64) -> i64 |
| 654 | func pn_view(inp: *u8, outp: *u8) -> i64 |
| 839 | func main(argc: i64, argv: *i64) -> i64 |