Skip to content

Visual equation editor: OMML equations, 2-D layout, in-place typing - #55

Closed
shuff57 wants to merge 9 commits into
storytold:mainfrom
shuff57:equation-editor
Closed

shuff57 wants to merge 9 commits into
storytold:mainfrom
shuff57:equation-editor

Conversation

@shuff57

@shuff57 shuff57 commented Oct 10, 2026

Copy link
Copy Markdown

Visual equation editor

Insert → Equation used to be a one-line text field that swapped a few tokens for Unicode and inserted an italic text box. This replaces it with a real equation object and an editor where you type into the formatted math (x, ^, 2 shows a raised exponent immediately).

What it adds

  • deckcraft-math (new layer-1 crate): math tree, OMML reader/writer (unknown elements preserved as raw XML, bounded against hostile input), linear-text parser/exporter, template catalogue, and a caret/selection editing model.
  • Commands: insert.equation, equation.update, equation.get, equation.templates, equation.fromLinear, equation.type. Equations are stored as RunKind::Math OMML and round-trip through PPTX. The importer now sets run text via to_linear(from_omml) and keeps run properties.
  • Layout: TeX-style 2-D layout in deckcraft-text (fractions, roots, scripts, big operators with limits, delimiters, matrices); Math runs are inline atoms that keep character/caret counts.
  • Editor dialog: template palette, live preview, in-place typing with caret and selection (^ _ /, sqrt, Greek names, symbol shortcuts, auto-paired brackets), undo/redo, copy/cut, Tab between places. Double-click on an equation reopens it. The linear text field remains as a secondary path.

Known limitations

  • Radical and bracket fit is rougher than KaTeX; the real fix is a math-capable OFL font (STIX Two / Latin Modern Math) via craft-fonts. Noted in ROADMAP.md.
  • OMML that rebinds the m prefix to a non-OMML URI is mis-namespaced on rewrite (documented in code; Office does not produce this).
  • Editing happens in the dialog preview, not directly on the slide.
  • Not tested against real PowerPoint; OMML shapes follow the public ECMA-376 spec and hand-written samples only.

Verification

cargo xtask ci (fmt, clippy, tests, assets, layers, wasm) passed on this branch. No Autodesk/Microsoft/Adobe assets or third-party math-editor code were used; MathLive and KaTeX were only observed in a browser as comparison references.

Opened as a draft: this is a large change (about 40 commits) and I'm happy to squash or split it however you prefer.

🤖 Generated with Claude Code

@echelon

echelon commented Oct 10, 2026

Copy link
Copy Markdown
Member

Thank you, @shuff57, this is impressive work: a clean-room OMML editor with about 196 tests, no new external crates and no bundled fonts.

It can't merge yet: #4 (UAX #9 bidi + Arabic shaping) landed and rewrote the paragraph cell model in crates/text/src/lib.rs (cells now carry level/glyphs/head/boundary and are built from the logical text). The equation atoms need to be re-slotted into that model, not mechanically merged. There are also small conflicts in text/tests.rs, engine/tools.rs, render/lib.rs, pptx/tests/roundtrip.rs and Cargo.lock.

Could you rebase onto main, add a test with an equation inside a right-to-left (Arabic) paragraph, and get cargo xtask ci green? We'd love to land it then.

If you're not on our Discord yet, come join us: https://discord.gg/artcraft

@shuff57
shuff57 marked this pull request as ready for review October 10, 2026 15:56
@shuff57

shuff57 commented Oct 10, 2026

Copy link
Copy Markdown
Author

Thanks! Rebased onto current main (d556ff9) and squashed to 4 commits.

Bidi integration. The equation atoms are re-slotted into the new paragraph cell model rather than merged mechanically: an equation is one U+FFFC object (a bidi neutral) followed by zero-width U+2060 joiners, one per remaining character of the run. It takes part in bidi and line breaking but is kept out of font shaping, only its first character is a caret stop or break point, and it is placed from the per-cell visual edges, so it lands correctly at any embedding level. The equation box itself is drawn whole and never mirrored. Glyph runs set cells so the morph transition treats an equation as one character.

Tests added (crates/text/src/tests.rs), run against a real Arabic face:

  • equation_in_arabic_paragraph_follows_reading_order: Arabic word, equation, Arabic word in an RTL paragraph (reading order, box not mirrored, caret edges, char counts)
  • equation_alone_in_an_rtl_paragraph_sits_at_the_start_edge
  • equation_between_latin_and_arabic_keeps_logical_neighbours

cargo xtask ci is green (fmt, clippy, test, assets, layers, wasm). I also rendered RTL paragraphs with mid-line, end-of-line, wrapped, justified (kashida) and highlighted equations and checked them by eye, and double-clicked an equation in an RTL paragraph in the app to confirm the editor opens and updates it in place.

shuff57 and others added 8 commits October 10, 2026 20:01
OMML tree, linear (LaTeX-ish) format, templates, bounded namespace handling and
lossless round-trip of PowerPoint equations; pptx reader/writer keep Math runs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
insert.equation, equation.update/get/templates/fromLinear with strict param
validation; Math runs are atomic for copy/cut/format and whole-run deletion.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Fractions, roots, scripts, big operators with limits, delimiters and matrices,
laid out as inline atoms that keep caret and character counts; drawn vector
shapes for radicals, brackets and sum/product signs (Deco carries a path).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Palette dialog with live preview, a math editor model (caret, selection,
structure typing, undo/redo, clipboard) and MathLive-style typing grammar.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…L, delimited LaTeX)

edit.paste recognises clipboard text that is exactly one equation payload:
an m:oMath / m:oMathPara (optional XML declaration), a presentation MathML
<math> element, or LaTeX in $$..$$ / \[..\] (display) or $..$ / \(..\)
(inline) delimiters spanning the whole text. It inserts a real equation in
one undo step; markup that does not parse is pasted as text, as before,
with a one-line status note. Keep Text Only / Paste and Match Formatting
still paste the literal text.

math crate: xml::well_formed (strict check before trusting the lenient
reader), clip.rs (detection), mathml.rs (bounded presentation-MathML
reader; a parallel implementation, equaSHion has no MathML reader yet).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…on; \bar macron is an accent

A pasted HTML clipboard fragment (<!--StartFragment--> or <body>) whose
only content is one <math> or <m:oMath> element reads like the bare
element. MathML over-marks U+0305 and the macron become the \bar accent,
matching equaSHion's to_mathml; checked against equaSHion's writer (19 of
19 sample equations read to the same linear form as its OMML).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…re ROADMAP)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…isuals

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@hajdukste

hajdukste commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

@shuff57 @echelon I've submitted a follow-up that adds direct editing on the slide to this PR's equation editor:

Follow-up: shuff57/deckcraft#1

Your PR already provides the structured math editor, fractions, roots, scripts, matrices, symbol shortcuts, layout, and native OMML/PPTX support. The follow-up reuses that work, including your existing Editor. Its main addition is making those editing capabilities available directly on the slide, where this PR currently uses the dialog preview.

The added interactions are:

  • Insert → Equation immediately creates an active field showing Type equation here, at the text caret or in a new text box.
  • Clicking an equation lets you edit it directly on the slide, including fraction and exponent slots and equations in table cells.
  • The active field has gray shading and an empty contextual Equation tab. Leaving restores the previous ribbon tab.
  • Right Arrow at the end of the root math row returns to surrounding text without inserting a character, and restores the surrounding text's formatting. Left Arrow can reenter the equation.
  • Explicit backslash commands such as \alpha remain visible until Space converts them. Existing bare-name shortcuts remain available.

The follow-up targets your equation-editor branch and contains one additional commit. Your commits and authorship are preserved, and the existing dialog and template palette remain available.

Validation: 337 core tests, 32 UI tests, and all 23 wasm checks passed; synthetic UI previews were inspected. Regression coverage includes document undo/redo, native/PPTX saves, rotated/RTL placement, and table cells. Full CI stopped on existing Rust 1.95 Clippy diagnostics, documented in the follow-up. This does not include a rebase onto main or resolve this PR's merge conflicts.

Happy to adapt the follow-up to your preferred integration approach.

@shuff57

shuff57 commented Oct 15, 2026

Copy link
Copy Markdown
Author

Pointing reviewers at #192, which is the successor to this PR.

#192 replaces this branch's own deckcraft-math crate with the equaSHion editor (the same one WordCraft uses in #801). It is based on current main with no conflicts, and it covers the same ground as this PR: OMML import/save, layout, in-place editing on the slide, an Equation ribbon tab, and paste of OMML/MathML/LaTeX.

I'm leaving both open so you can choose. If #192 is the direction you prefer, this one can be closed in its favour. If you'd rather keep this approach, it still needs the rebase onto the main that has moved on since.

@hajdukste, thanks for the on-slide editing follow-up in shuff57#1. #192 already edits equations on the slide itself, so that work may overlap with it; I'll look at what is worth carrying over.

@hajdukste

Copy link
Copy Markdown
Contributor

@shuff57 @echelon An update to my earlier comment: I’ve also opened #778, combining the equaSHion work from #192 with my inline-editing additions, preserving the original commits and authorship.

It was based on an earlier version of #192, before the latest updates. I’ve asked @shuff57 to look at it as a possible combined basis so we can agree which PR to carry forward.

@Harrison-Booth

Harrison-Booth commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

This PR conflicts with main (cmd/edit.rs, cmd/mod.rs, tools.rs, model/src/edit.rs, pptx read/write dml.rs, roundtrip.rs, render/src/lib.rs, text/src/lib.rs and tests.rs, ui-egui/src/dialogs.rs and more), so this review covers the PR branch as submitted, not a merged build. I did not review the 11k lines line by line; I focused on the claim that the description says was untested ("Not tested against real PowerPoint").

What I ran, on Linux and Windows (copy of the PR head sources, scratch directory outside the repo, CARGO_BUILD_JOBS=2):

  • cargo test -p deckcraft-math: 127 passed, 0 failed.
  • A scratch example (not part of the PR) used insert.equation with four equations — (a+b)/c = sqrt(x^2+1), sum_(i=1)^n i^2, int_0^1 x dx, [a, b; c, d] — and the PR's deckcraft_pptx::export to write a .pptx.
  • I opened that file in real Microsoft PowerPoint through COM (read-only, a temporary copy, closed without saving) and exported slide 1 to PNG. PowerPoint opened it without raising an error (alerts were suppressed, so I cannot say whether a repair prompt would have appeared) and drew all four as real equations: a stacked fraction with a radical, a summation with under/over limits, an integral with bounds, and a bracketed 2×2 matrix. Its TextRange.Text for each box contained the math characters rather than the linear source. The four overlap each other in the image only because my script inserted them at the same position.

What this does not cover: only these four equations were opened in PowerPoint; editing one there and saving it back, and reading an equation written by PowerPoint (the importer), were not tested. The editor dialog and in-place typing are UI code and were not run. macOS was not run. The ui-egui and engine suites were not run, and I did not run cargo xtask ci.

Notes:

  • The roundtrip tests added to crates/pptx/tests/roundtrip.rs are in a file main has since moved to tests/it/roundtrip.rs, so they need moving as part of the conflict resolution.
  • The description says the branch has about 40 commits and offers to split it. Given the size (new deckcraft-math crate, engine commands, layout in deckcraft-text, editor dialog), the four-part split named in the commit titles (math crate, engine commands, layout, editor) would make it much easier to review.

@shuff57

shuff57 commented Oct 29, 2026

Copy link
Copy Markdown
Author

Closing in favour of #192, which supersedes this PR. #192 replaces this branch's own deckcraft-math crate with the equaSHion editor (shared with WordCraft), covers the same ground (OMML import/save, 2-D layout, in-place editing on the slide, Equation ribbon tab, paste of OMML/MathML/LaTeX) and carries over the bidi work and Arabic tests. Thanks to everyone who reviewed and tested this one, especially the PowerPoint check of the exported equations.

@shuff57 shuff57 closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants