Files
texrra-engine/docs/NATIVE_QUANTITIES.md
T

147 lines
8.9 KiB
Markdown

# Native mathematical character definitions and quantities — 2026-10-31
2026-11-03 follow-up: [native mag/true and actual per-shipout device state](NATIVE_DEVICE.md)
passes 405 exact true-unit values, actual font/glue consumers and a 15-job/29-page
PDF oracle. Full workspace: 1351/0, all original/new gates pass. The true-unit
strict boundary recorded below is historical; current PDF configuration,
format/NFSS, sessions and complete P2-M1 remain open.
Subsequent font-slot acceptance (2026-11-01): [native font diagnostics](NATIVE_FONT_DIAGNOSTICS.md)
now consumes tracinglostchars/tracingonline using actual TFM/Type1 slots, with
real font predicates, log/terminal delivery and fatal PDF protection. Full
workspace: 1187 passed / 0 failed; prior slice gates remain green. Unchanged
LaTeX now stops at defaultskewchar (522:1), so earlier boundaries/counts on
this page are historical. Full format startup remains false.
Current follow-up (2026-11-01): [native display math](NATIVE_DISPLAY_MATH.md)
is accepted: 1182 workspace tests, 58 vlist / 36 page / 24 quantity-mode-pack
cases and a three-page PDF gate. Unchanged LaTeX now stops at tracinglostchars
(508:1). Earlier counts/boundaries below describe their original slices.
Current follow-up (2026-11-01): [native interline penalties](NATIVE_INTERLINE_PENALTIES.md)
are accepted: 1176 workspace tests, 100 vlist and 64 actual page-ownership cases;
unchanged LaTeX now stops at displaywidowpenalty (502:1). Earlier acceptance
counts/boundaries below describe their original slices, not current startup.
Current follow-up (2026-11-01): [native inline math](NATIVE_MATH_EXECUTION.md)
is accepted: 1171 workspace tests; unchanged LaTeX now stops at clubpenalty
(500:1). This document retains its original slice's evidence and limits;
current math/family coverage is defined by the linked follow-up.
Route-D now owns mathematical character meanings, physical input-line queries,
dimension/glue/mu-glue registers and their basic scanners/arithmetic. These are
executed tokens and typed state, not rewritten source or template-specific
register names. No v1 fallback or version-marker workaround was introduced.
Full acceptance: **1153 workspace tests / 0 failed**; release, fmt/diff and the
math D gate pass. Complete LaTeX format startup has not passed.
## Mathematical characters and input position
- mathchardef defines a distinct MathCharGiven(u16) meaning, bounded to 0..32767.
It preserves all class/family/slot bits. Integer reads, the/number, let, ifx,
meaning, scopes and globaldefs operate on that type. A math character and a
text character with the same numeric code are different meanings.
- Actual execution of a mathematical character still requires the native math
mode/list builder. It errors in the current text demo path, rather than
painting the code as ASCII or dispatching to another renderer.
- inputlineno reads the physical Mouth line counter and active input stack.
Macro definition/call spans do not substitute for scanner position. Nested
input restores the caller's position; CR/LF/CRLF and disabled endlinechar keep
physical line semantics. A final position is retained for explicit shipout
I/O continuations and trusted snapshots. It is read-only, not a TeX-version
flag or a counter incremented every time the primitive is queried.
## Native register state
execution/registers.rs defines RegisterKind, Register, RegisterValue, Glue and
Flex; engine/quantities.rs owns scanners and arithmetic. state.rs owns the
scoped save entries and sparse values. The implementation imports no old
semantic frontend, VM adapter or v1 register store.
- dimen/dimendef, skip/skipdef, muskip/muskipdef have separate native identities.
They use 0..255 in the base bootstrap and 0..32767 in EtexBootstrap. Default
zero values are TeX's initial register state, not fake capability responses.
- Assignment, aliases, local/global/globaldefs restore, register reads and JSON
roundtrip preserve types and source identities. Global assignment removes
all enclosing restore entries. Restored sparse zero state has the same
fingerprint as before the local assignment.
- Dimension and glue quantities are integer sp; math glue uses 1/65536 mu.
Dimension/component magnitude is at most 2^30-1. Stretch/shrink retain their
finite/fil/fill/filll order independently.
- advance, multiply and divide work on the actual stored quantities. Integer
division truncates toward zero; glue addition uses dominant order and handles
cancellation/zero components. No floating-point unit conversion is involved.
- the prints dimensions/glue with TeX print_scaled decimals; number and integer
scans coerce ordinary dimensions/glue to their width in sp. Incompatible
mu/physical units error. ifdim evaluates actual dimensions and relations.
## Scanner and printing boundaries
The fixed-point scanners implement signed integer/decimal coefficients,
decimal comma, exact round_decimals behavior (first 17 fractional digits),
absolute pt/sp/bp/in/pc/cm/mm/dd/cc conversions, internal units, mu glue and
infinite orders. Fractional sp is discarded as TeX specifies. Decimal points
must be adjacent to the integer part; spaces before units are allowed.
Keyword scanning expands input, preserves categories and returns partially
matched tokens on a miss. Units/keywords are case insensitive.
print_scaled produces TeX's decimal representation, including the one-sp and
maximum-dimension boundaries; printing and rescanning roundtrip. The independent
oracle compares exact integer and formatted output, not tolerance-adjusted
fixtures or fitted physical offsets.
**Not implemented here:** dimexpr/glueexpr/muexpr, font-relative em/ex, true-unit
magnification state, layout parameter primitives and native mode/list execution.
Unsupported units/expressions fail explicitly. No demo font metric or fixed
magnification is supplied to make a format check pass. Scratch-register support
does not imply that paragraph parameters or font selection have been executed.
Deep scanner/expression/expandafter input exposed a Rust test-thread stack
overflow during development. Synchronous value scanning, expressions and
recursive expansion now fail at 32 nested calls (or the configured stricter
input-depth limit). Tests cover deeply nested counts, dimension references,
parentheses, numexpr and expandafter. This bounded bootstrap capacity is not
a claim of full TeX capacity; future explicit-stack execution can raise it.
## Independent verification and real format boundary
- The token/primitive suite includes **90 actual pdfTeX INITEX comparisons**,
covering mathematical character meaning/type/scopes and physical input lines.
- Five quantity/state tests include **101 independent real pdfTeX comparisons**:
nine absolute units, decimal/negative/fractional values, print/rescan boundaries,
glue orders/cancellation, mu arithmetic and internal units. Outputs match
exactly, including integer sp and TeX decimal strings.
- Negative tests cover overflow, bad indices, incompatible units, unavailable
font/magnification/expression state, read-only input position and bounded
recursive failures. Nested-file tests distinguish scanner lines from spans.
- A strict native CLI test exports a real PDF with evaluated quantities and
checks extracted text. The existing real file-stream comparisons remain.
The unchanged pinned LaTeX2e entry now executes its mathematical constants,
dimendef/skipdef/toksdef, generic allocators, maxdimen, hideskip and initial zero
dimensions/glue. The source proceeds from **326:1, missing mathchardef**, through
the dimension definitions at 347, to **491:1, missing pretolerance**. Its actual
auxiliary timestamp roundtrip still succeeds. Full format boot remains false;
no source guard or input file was modified.
The following paragraph slice is now accepted: [native paragraph state and
construction](NATIVE_PARAGRAPHS.md), with 119 real INITEX comparisons and real
PDF geometry validation. That phase reached 494:1, missing vbadness. The subsequent [native box slice](NATIVE_BOXES.md)
implements actual vpack diagnostics and advances to binoppenalty (498:1); full
boot remains false. Next implement actual native math/list penalty consumers.
Complete code tables, quantity expressions, fonts/magnification, modes/lists, output routines and native format
images remain open. The existing font/format gap audit is unchanged.
~~~sh
cargo test -p texrra-tex-core --offline --test execution_quantities -- --nocapture
cargo test -p texrra-tex-core --offline --test execution_native -- --nocapture
cargo test --offline --test native_execution --test native_job_io
cargo test --workspace --offline -- --test-threads=1
cargo run --release -- native --initex --etex \
examples/native-bootstrap/quantities.tex /tmp/quantities.pdf
~~~
Current evidence lives under /tmp/texrra-native-registers/. The format probe
still checks the unchanged entry SHA and records format_boot_passed=false.
Logs are /tmp/texrra-register-*.log; older job/time and math evidence is retained.