Mova0.6 pre-release

latex — built-in LaTeX support

Goal: built-in, compiled LaTeX support. Math-mode formulas → our own tree (enums) → back to canonical LaTeX or plain text. Everything is in the binary, no external TeX needed; on the website formulas are drawn by KaTeX. Its place in the mini-lab is described in Context, layers and memory.

How it is built

filewhat it does
data/commands.txt + build.rsa single command table → enums Sym (TeX class, Unicode, whether it is a delimiter), FracKind, Accent, Font, TextStyle, Stack, XArrow, EnvKind and constant matches: name → Entry, character (≤, α) → Sym, environment → EnvKind. The first form is canonical for printing (\leq → \le). A duplicate form or an unknown kind or class is a build error
table.rsmodule table: includes the code that build.rs generates from data/commands.txt (the enums above; lookups lookup_cmd, lookup_char, lookup_env) and holds the hand-written enums Class and Entry
lex.rsmath-mode lexer (TeX rules: \alpha eats spaces, % is a comment, spaces merge) and a stack stream onto which a macro pushes its body
macros.rs\newcommand/\renewcommand/\providecommand with [n][default], \def with #1…#9 (and with delimiters, as in TeX: \def\pair(#1,#2){…}), \let (keeps the old value), \DeclareMathOperator(*); Macros::scan(tex) collects definitions from a document
parse.rsparser: tokens → Node; errors with a byte position (Error::column, Error::context — a ⟦ mark in the source)
ast.rstree: Row, Num, Char, Sym, Group, Frac, Sqrt, Scripts (base, scripts, primes), OpName, LeftRight/Middle, Env (tables), Font, Text, Accent, Stack, XArrow, Class, Not, Unknown (name, arguments, position). Span does not take part in ==
print.rsto_latex (canonical LaTeX), to_text (Unicode: (a + b)/2, x², ℝⁿ, matrix (a b; c d)), to_sexpr (debugging), to_latex_faulty (deliberate defects for the negative control)
gate.rsround-trip gate parse(print(parse(x))) == parse(x); affected — whether a defect touches the tree (for a precise negative control)
extract.rsformulas from .tex: $…$, $$…$$, \(…\), \[…\], equation, align, alignat{n}, gather, multline, eqnarray, flalign, displaymath, math (and starred forms); comments, \$, \verb, verbatim are skipped; $…$ does not cross an empty line
tomath.rs (feature math)bridge to math::Expr and back (see below)
main.rs, corpus.rsCLI: parse, tex, corpus (arXiv metadata .xml.gz, .tex)

What is supported

Bridge to math::Expr (feature math)

to_expr covers a subset: numbers, variables, + − · × / ÷ and implicit multiplication, unary minus, fractions, roots (\sqrt[3]{x} → x^(1/3)), powers, \sin \cos \tan \exp \ln, absolute value |x|, parentheses ((x+1)^2 — in TeX the script attaches to ), and the bridge accounts for this), e, \pi. \sin 2x = sin(2x), \sin x\cos x = sin(x)·cos(x), \sin^2 x = (sin x)². \frac{1}{2} (an irreducible fraction of integers) is a rational literal; \frac{2}{4} stays a division (no step is lost). to_relation handles a chain a = b ≤ c. A refusal carries the kind of reason ("variable", "script", "function", "construct", "relation", "syntax", …). from_expr is the reverse side: printing math steps and answers in LaTeX; a test checks Expr → LaTeX → tree → Expr on a set of expressions (with normalization Div(1,2) ≡ 1/2). The bridge targets the math eval expression tree (math::Expr), not the mathsolve plan language.

CLI

cargo build --release [--features math]
../target/release/latex parse '\frac{a+b}{2} \le \sqrt[3]{x}'   # tree, LaTeX, text, unknowns, round trip (and math::Expr)
../target/release/latex tex main.tex chap1.tex -v                # document formulas with macros from all files
../target/release/latex corpus $MOVA_DATA/raw/math/arxiv-oai --out DIR [--math] [--fault swapfrac|dropsup|droplast] [--limit N]

Real formulas

latex corpus reads arXiv abstracts and titles (arxiv-oai, OAI-PMH arXivRaw metadata, .xml.gz; this source has no .tex), removes duplicates between sets and reports for each formula: parsed or error, Unknown nodes, round trip, and the bridge to math::Expr with the reason for each refusal. It writes the list of unknown commands (unknown.tsv in --out). Abstracts have no preamble, so author macros (\R, \Z, \eps, …) show up as unknowns; in .tex documents they are expanded by Macros::scan.

Negative controls

cargo test and cargo test --features math run unit, end-to-end, bridge and property tests on random inputs.

Independent tests

tests/data/vmm/latex.tsv holds cases from an independent author (the teacher, which did not see the code; prompts alongside), frozen by hash before they were run. Kinds: same and diff (tree equality without positions), err (must be an error), ok (no Unknown, round trip), value (value through the bridge to math::Expr, only with --features math), count (formulas in a document fragment), macro. The runner is tests/vmm_latex.rs; it reads "\n" in the format as a line break only when it is not followed by a letter, so \newcommand survives. Its negative control swaps same and diff.

Licenses

Limits

Licence

Elamur Cosmic License (Elamur Cosmic License). Third-party data keeps its own terms, as noted where it is used.

This page in Markdown https://md.mova.elamur.ai/free/en/docs/latex/