Commit Graph
14 Commits
Author SHA1 Message Date
David MannandClaude Opus 5.5 1929e79ebb Merge storytold main into next (20 Nov, second sync)
Merges main at 8f92ed1334 (#2550 and the rest of main since the 20 Nov sync).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 16:38:55 +01:00
FredApps 66179f4eca Consolidate related books tests 2026-11-19 13:06:40 +01:00
kiwi4boy 3e61d2e436 math: invisible brackets export to LaTeX as a TeX group
A script whose base isn't simple prints as `〖a^b〗^c` in linear text (port of
wordcraft#6084), and LaTeX export copied the brackets into the .tex, where the
exporter's preamble can't set them. They are now a TeX group, `{a^b}^c`; one
without its partner is dropped. Also pins that `〖a+b〗 ^2` keeps the delimiter.

Port of the review fix on wordcraft#6084.
2026-11-16 22:21:40 -05:00
kiwi4boy 4a5cb98651 craft-math: review fixes: a number base after a number, a cap on kept OMML, is_number without a Vec
From the second review round:

- A number base right after a digit, `.` or `,` keeps its brackets. Bare, it continued the number
  before it: `1` then `23^4` was written `123^4` and read back with 123 as the base, and the same
  for a one-digit base (`12^4`), `x.` then `5^2` and `1,` then `5^2`. This came with the bare
  number base, before the first review round. A number base after a letter or an operator stays
  bare (`a2^4`, `1+2^4`).
- Both parses of kept OMML are capped at the elements the reader keeps (MAX_ELEMENTS × 2) instead
  of craft-xml's defaults, and roxmltree gets the same cap as `nodes_limit`. Kept OMML can come
  from a hostile JSON document; larger kept OMML is written from its nodes. The reader can't keep
  more than this, so OMML read from a file is unaffected.
- is_number scans bytes instead of collecting a Vec<char>: everything a number holds is ASCII.

The two new tests fail without their fix.
2026-11-12 22:51:39 -05:00
kiwi4boy ae00359d2b craft-math: review fixes: number bases, a comma after a script, whitespace in kept OMML
From the review of this series:

- A base that is one number by the parser's rule (1,000 as well as 2.5 and .5) is written bare,
  1,000^2 rather than 〖1,000〗^2. lin_base tested numbers with digits and points only, so a
  comma made it a multi-letter base. The rule is now is_number, the parser's number_len over the
  whole text; simple_operand, which fractions share, is unchanged.
- A bare script followed by a comma and a digit is ended with a space: x^2 then ,3 was written
  x^2,3, and the number script read the ,3 back into the exponent. Only a comma before a digit
  gets one; x^2, y is written as before.
- Kept OMML whose element name is followed by a tab, carriage return or line feed (all XML
  whitespace) is written back like one followed by a space, instead of from the nodes.

Each new test fails without its fix.
2026-11-12 22:36:13 -05:00
kiwi4boy 21f838c14e craft-math: a number is one item in the linear format (port of wordcraft#6236)
The parser pushed digits one character at a time, so a script took only the last digit as its
base: 10^3 built 1 followed by 0³, where Word builds 10³. A number is now read as one atom, by the
rule Word follows: digits, with a . or , continuing it only when a digit follows (2.5, 3.14, 1,000)
and a leading . before a digit starting one (.5); a trailing point (2.) isn't part of it, and
letters and signs are separate items. A script or a fraction operand takes the whole number (10^3,
2.5/3). A number script follows the same rule (x^.5, x_1,000; x^2. keeps the point out), keeping
letters after the digits (#1609).

Ported from storytold/wordcraft#6236 (issue wordcraft#6229): its change to math_linear.rs and its
tests/number_bases.rs, with only paths and crate names changed. Its typing test (engine) and the
docs/typing-parity.md note stay in WordCraft.
2026-11-12 22:01:24 -05:00
kiwi4boy cc63fb5074 craft-math: a multi-letter script base survives linear text (port of wordcraft#6230)
The parser attaches a script to the last character before it (mc^2 is m, c²), so a base of
several letters from a Word or LibreOffice file, written bare, read back split. lin_base now writes
such a base in invisible brackets, 〖mc〗^2, as Word linearizes it; a number (10^3, as Word writes
it) and an upright function name stay bare.

Ported from storytold/wordcraft#6230 (issue wordcraft#6228), which is stacked on wordcraft#6084:
its own change to math.rs and its tests/linear_multichar_base.rs. The ODT test that pinned
LibreOffice's E=mc^2 (<msup><mi>mc</mi>…) moves with it: in craft-odf it now expects E=〖mc〗^2,
as in the WordCraft PR. It runs only with craft-odf's `text` feature.
2026-11-12 21:59:46 -05:00
kiwi4boy 8d2481a748 craft-math: an empty shown n-ary limit survives linear text (port of wordcraft#6085)
to_linear wrote a limit only when it wasn't empty, so half-typed ∑_ (an empty, shown lower limit)
came out as ∑▒() and read back with both limits hidden. A shown limit is now written even when
empty, as _() or ^().

Ported from storytold/wordcraft#6085 (issue wordcraft#6076): its change to math.rs and its
tests/linear_empty_limits.rs, with only paths and crate names changed.
2026-11-12 21:53:35 -05:00
kiwi4boy 10f2625365 craft-math: a script on a script prints back the same in linear text (port of wordcraft#6084)
to_linear wrote a script base that isn't simple in parentheses, so sSup(sSup(a, b), c) came out
as (a^b)^c and read back with a visible delimiter. It now writes 〖a^b〗^c, as Word does, and the
parser takes a lone 〖…〗 group as the base itself, as Word builds 〖a+b〗^2, instead of an invisible
delimiter. simple_operand is split out of lin_operand so both use one rule.

From the PR's review: an invisible delimiter that is itself a script base gets an outer pair
(〖〖a〗〗^2); a one-character operator base is written 〖⊗〗_i, since a script after an operator reads
as a pre-script; and only a base just closed by 〗 (after_group) is unwrapped, so an explicit ├a┤^2
keeps its delimiter.

Ported from storytold/wordcraft#6084 (issue wordcraft#6075): its changes to math.rs and
math_linear.rs and its tests/linear_script_base.rs. In the function-name branch of the parser,
where #6083 (stacked scripts) and this PR both change the `attach_script` calls, the stacked-script
chain is kept and the calls pass this PR's new `group` argument (`false`).
2026-11-12 21:53:35 -05:00
kiwi4boy ef0f27a306 craft-math: stacked scripts in the linear format nest to the right (port of wordcraft#6083)
a^b^c built (a^b)^c; Word builds a^(b^c), and the same for a_b_c and x^2^3. After a script
operand, the same script operator now nests inside it. The chain stops at WRAP_DEPTH like every
other wrap, so the #1456 guard holds. a_b^c, a^b_c and (a^b)^c are unchanged.

From the PR's review: sin^2^3 on the function-name path nests to the right too (script_chain for
the first script; a second script joins only when it is the other operator, log_2^3). A level that
would make the whole tree too deep keeps its operator as text, as expr does at its own cap, and a
^ or _ the chain left at its cap isn't taken as the start of a function's operand.

Ported from storytold/wordcraft#6083 (issue wordcraft#6074): its change to math_linear.rs and its
tests/stacked_scripts.rs, with only paths and crate names changed. Its typing test (engine) and
the docs/typing-parity.md note stay in WordCraft.
2026-11-12 21:53:35 -05:00
Dylan M. Taylor d93991706b craft-math: operator names take their LaTeX scripts directly again (restores #1019) (#1068)
#1019 (22161d2d) wrote \sin^2\theta as \sin ^{2}{\theta } so it reads back as
the same tree. The squash merge of #1038, whose branch predated it, put
math_latex.rs and the corpus test back as they were before. This applies
#1019's change again, unchanged, with its test.
2026-11-11 21:30:41 -05:00
Dylan M. Taylorandshuff57 bdf06f1029 Add craft-latex: LaTeX documents read and written, on craft-flow (stacked) (#1038)
* Add craft-wordmodel: WordCraft's document model without its editing code

WordCraft's crates/doc (wordcraft-doc, at 07f97737) moved as it is, so the DOCX,
RTF, ODT and other text-format crates can read into and write from one model.
Module paths, type names and serde attributes are unchanged: an app that
re-exports the crate keeps its native file format.

Left in the app: range editing (edit.rs), IME text and equation editing. Not
model, and already in craft-libs: code pages (craft-rtf), the ZIP entry-count
check (craft-opc), the compound-file guard (craft-cfb). The paragraph walks
moved to walk.rs and the unit helpers of wordcraft-geom to geom.rs.

* craft-wordmodel: math_tree, the arguments of an equation node and a walk over its runs

The DOCX reader and writer walk an equation's runs. The walk and the child
accessors it uses were in WordCraft's equation editor (math_edit.rs), which
stays in the app; they are structure, not editing.

* craft-mime: detect, for bytes that name no character set

is_text, decode (BOM, unmarked UTF-16, UTF-8, else the legacy encoding
the bytes look like), legacy and legacy_label, behind a detect feature
that brings in chardetng. Moved from WordCraft's crates/formats/src/txt.rs
at 06c2ae6f with its text-sniffing tests. Also charset::is_known, so a
caller can tell a label decode would read as UTF-8 from one it knows.

* craft-wordmodel: keep the document operations (edit.rs) with the model

The DOCX and RTF readers use them: alternative-format chunks are merged into
a document with adopt_blocks, and a reader formats ranges with format_range
and inserts objects. They operate on the document, not on a view, so they
belong beside it. The tests that drove them come back with them; the
paragraph walks stay in walk.rs and edit re-exports them.

base64 0.23, as WordCraft and craft-offcrypto use.

* Add craft-math: the equation tree with OMML, MathML, LaTeX and UnicodeMath

The math tree, LaTeX, linear-format, symbol and tree-walk modules come
from craft-wordmodel (storytold/craft-libs#963, WordCraft's crates/doc at
07f97737) unchanged, with the run colour (Rgb) and the symbol-font tables
they use. MathML is WordCraft's crates/formats/src/mathml.rs and OMML is
WordCraft's crates/docx/src/read/math.rs and write/math.rs (06c2ae6f /
07f97737), moved onto craft-xml. The HTML-specific MathML tests stay in
WordCraft; the rest moved with the code.

mathml::parse and omml::parse/read_str/write_str are new: string entry
points for callers that have no tree of their own.

* craft-math: read MathLive's and other spellings of LaTeX math commands

\abs{...} (an absolute value), \lvert \rvert \lVert \rVert, \nparallel,
\backprime, \infinity, \cross, \differentialD, \exponentialE and
\imaginaryI (MathLive's d, upright e and i), \emph, \textsf, \hbox,
\mathnormal and \underleftarrow / \underrightarrow /
\underleftrightarrow were unknown and read as literal text. They are read
as equaSHion's typed-input parser reads them (storytold/craft-libs#29).

* craft-math: equaSHion's equation corpus as test data

corpus/equations.tsv, corpus/latex.tsv and the OMML samples of
storytold/craft-libs#29 (7a6ef6b9), unmodified.

* craft-math: corpus round trips, GridCraft's OMML cases, entry points and limits tested; README

The corpus equations go through OMML, MathML and LaTeX and back; the OMML
samples are written back as kept and from the tree. GridCraft's OMML to
LaTeX test cases (crates/xlsx/src/omml.rs) give LaTeX that reads back the
same through the tree. omml::parse and read_str are tested against other
prefixes, the strict namespace, kept OMML, junk, the element cap and deep
nesting.

* Add craft-flow: the flow model the text formats map to, on craft-wordmodel

WordCraft's crates/formats/src/model (07f97737) moved as it is: Flow,
FBlock, Para, Inline, Fmt, tables and cells, pictures, to_doc and
from_doc, picture sniffing, colours, base64 and the Dropped report. Only
the paths changed (wordcraft_doc is craft_wordmodel); the report helpers
are public so the format crates can call them; the image re-encoding
helper stays with WordCraft's RTF writer.

* Add craft-markdown: Markdown read and written, on craft-flow

WordCraft's crates/formats/src/markdown (07f97737) with its 35 tests,
moved onto craft-flow and craft-wordmodel. Character references come from
craft-html. The table cell budget lives in craft-flow, which names it in
its warning. Two test lines that wrote plain text through WordCraft's txt
module stay in WordCraft.

* WIP: craft-latex sources from WordCraft (unmodified)

* Add craft-latex: LaTeX documents read and written, on craft-flow

WordCraft's crates/formats/src/latex (07f97737) with its 21 tests, moved
onto craft-flow and craft-wordmodel; bytes are decoded by craft-mime's
detect. The LaTeX parts of WordCraft's cross-format tests (nesting,
column specs, labels, no TeX commands from the document, the fuzz and
round-trip properties) come along as tests/hostile.rs. The ligature test
builds its three-font paragraph as a flow instead of reading HTML.

* craft-math: latex_text, LaTeX math and the linear format converted as text

WordCraft's crates/formats/src/latex/math.rs (07f97737): the converter its
LaTeX document reader and writer use, which keeps the source's spacing.
It moves here so craft-math is the one place that converts LaTeX math;
craft-latex calls it, and its output does not change. Its tests (from
WordCraft's latex tests and cross-format tests) come along.

* craft-math: latex_text's group finders are public, for craft-latex's length parser

* craft-latex: math through craft_math::latex_text; label timing test by ratio

The document math converter moved to craft-math (#1040) unchanged; this
crate calls it there (and its length parser uses its group finders), so
export output is the same. The label test compared one read with a
ten-second wall clock and failed on a loaded machine; it now compares the
fastest of three reads of 25,000 and 100,000 labels, which a linear read
keeps near 4x and a quadratic one near 16x.

---------

Co-authored-by: shuff57 <62350898+shuff57@users.noreply.github.com>
2026-11-11 20:58:36 -05:00
Dylan M. Taylorandshuff57 22161d2d6a craft-math: operator names take their LaTeX scripts directly (\sin^2\theta round trip) (#1019)
* Add craft-math: the equation tree with OMML, MathML, LaTeX and UnicodeMath

The math tree, LaTeX, linear-format, symbol and tree-walk modules come
from craft-wordmodel (storytold/craft-libs#963, WordCraft's crates/doc at
07f97737) unchanged, with the run colour (Rgb) and the symbol-font tables
they use. MathML is WordCraft's crates/formats/src/mathml.rs and OMML is
WordCraft's crates/docx/src/read/math.rs and write/math.rs (06c2ae6f /
07f97737), moved onto craft-xml. The HTML-specific MathML tests stay in
WordCraft; the rest moved with the code.

mathml::parse and omml::parse/read_str/write_str are new: string entry
points for callers that have no tree of their own.

* craft-math: read MathLive's and other spellings of LaTeX math commands

\abs{...} (an absolute value), \lvert \rvert \lVert \rVert, \nparallel,
\backprime, \infinity, \cross, \differentialD, \exponentialE and
\imaginaryI (MathLive's d, upright e and i), \emph, \textsf, \hbox,
\mathnormal and \underleftarrow / \underrightarrow /
\underleftrightarrow were unknown and read as literal text. They are read
as equaSHion's typed-input parser reads them (storytold/craft-libs#29).

* craft-math: equaSHion's equation corpus as test data

corpus/equations.tsv, corpus/latex.tsv and the OMML samples of
storytold/craft-libs#29 (7a6ef6b9), unmodified.

* craft-math: corpus round trips, GridCraft's OMML cases, entry points and limits tested; README

The corpus equations go through OMML, MathML and LaTeX and back; the OMML
samples are written back as kept and from the tree. GridCraft's OMML to
LaTeX test cases (crates/xlsx/src/omml.rs) give LaTeX that reads back the
same through the tree. omml::parse and read_str are tested against other
prefixes, the strict namespace, kept OMML, junk, the element cap and deep
nesting.

* craft-math: an operator name with a script keeps applying to its argument in LaTeX

to_latex wrote \sin^2\theta as {\sin }^{2}{\theta }, which reads back as
(\sin)^2 followed by θ: the braces cut the name off from its argument. An
operator name written as a command now takes its scripts directly
(\sin ^{2}{\theta }). The corpus test no longer needs its exception.

---------

Co-authored-by: shuff57 <62350898+shuff57@users.noreply.github.com>
2026-11-11 20:36:47 -05:00
Dylan M. Taylorandshuff57 85b4dabf0f Add craft-math: equations as one tree with OMML, MathML, LaTeX and UnicodeMath (#1013)
* Add craft-math: the equation tree with OMML, MathML, LaTeX and UnicodeMath

The math tree, LaTeX, linear-format, symbol and tree-walk modules come
from craft-wordmodel (storytold/craft-libs#963, WordCraft's crates/doc at
07f97737) unchanged, with the run colour (Rgb) and the symbol-font tables
they use. MathML is WordCraft's crates/formats/src/mathml.rs and OMML is
WordCraft's crates/docx/src/read/math.rs and write/math.rs (06c2ae6f /
07f97737), moved onto craft-xml. The HTML-specific MathML tests stay in
WordCraft; the rest moved with the code.

mathml::parse and omml::parse/read_str/write_str are new: string entry
points for callers that have no tree of their own.

* craft-math: read MathLive's and other spellings of LaTeX math commands

\abs{...} (an absolute value), \lvert \rvert \lVert \rVert, \nparallel,
\backprime, \infinity, \cross, \differentialD, \exponentialE and
\imaginaryI (MathLive's d, upright e and i), \emph, \textsf, \hbox,
\mathnormal and \underleftarrow / \underrightarrow /
\underleftrightarrow were unknown and read as literal text. They are read
as equaSHion's typed-input parser reads them (storytold/craft-libs#29).

* craft-math: equaSHion's equation corpus as test data

corpus/equations.tsv, corpus/latex.tsv and the OMML samples of
storytold/craft-libs#29 (7a6ef6b9), unmodified.

* craft-math: corpus round trips, GridCraft's OMML cases, entry points and limits tested; README

The corpus equations go through OMML, MathML and LaTeX and back; the OMML
samples are written back as kept and from the tree. GridCraft's OMML to
LaTeX test cases (crates/xlsx/src/omml.rs) give LaTeX that reads back the
same through the tree. omml::parse and read_str are tested against other
prefixes, the strict namespace, kept OMML, junk, the element cap and deep
nesting.

---------

Co-authored-by: shuff57 <62350898+shuff57@users.noreply.github.com>
2026-11-11 20:31:02 -05:00