Skip to content

Equations: structured math with inline insertion and editing - #778

Open
hajdukste wants to merge 26 commits into
storytold:mainfrom
hajdukste:codex/finish-equations
Open

hajdukste wants to merge 26 commits into
storytold:mainfrom
hajdukste:codex/finish-equations

Conversation

@hajdukste

@hajdukste hajdukste commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Insert → Equation now inserts a structured equation at the existing text caret, including in a table cell, and replaces selected prose when appropriate. A new equation text box is created when no text caret is active. Equations can be edited directly in the paragraph, then exited with Right Arrow so normal typing resumes with the surrounding text's formatting.

This continues @shuff57's draft #192 and combines its equaSHion typesetting and galleries with the inline interaction developed in #771 and its native-OMML follow-up. The branch preserves #192's original commits and authorship and integrates upstream main through 9859da3. It is proposed as one combined equation contribution for maintainers to review.

What changes

  • Structured fractions, scripts, radicals, matrices and other equation templates, with the Equation ribbon's galleries, symbols and built-in equations.
  • Inline insertion, an editor-only placeholder, typing shortcuts such as a/b and x^2, and navigation between structure slots. Unknown backslash commands remain literal.
  • Right Arrow at the outer end returns to normal text without inserting a space; Left Arrow at the adjacent equation re-enters it. Clicks place the math caret using the rendered geometry, including rotated text, RTL paragraphs and table cells.
  • The engine owns the equation caret, selection, parser state and undo history. Ribbon choices and typing use the same commands. Clearing an existing equation updates the document immediately.
  • Equation fonts follow Home → Font, including Latin Modern Math for a traditional LaTeX appearance. The choice applies to the whole equation, preserves its caret and content, and survives undo/redo and native/PPTX saves, including empty fields.
  • Native RunKind::Math / OMML storage, native-file and PPTX round-trips, and recognized OMML, MathML and delimited-LaTeX paste. This replaces Text: edit equations inline and return to normal text with Right Arrow #771's prototype text-marker representation with Equations on slides: laid out and edited in place with equaSHion #192's structured math model.
  • equaSHion's five library crates are vendored from revision 386b16c, with provenance, licences and documented host adaptations. This resolves Equations on slides: laid out and edited in place with equaSHion #192's dependency on a contributor-owned Git repository. Most of the added lines are the vendored library; its web application, font binaries, screenshots and corpus are excluded.

Scope and font integration

The draft's unfinished Unicode/LaTeX mode controls, conversion buttons, Normal Text, equation numbering and Display/Inline placement controls are omitted. Insertion follows the actual text caret. Imported mathematical display style remains supported; this does not claim complete equation-format parity.

Equations use the selected family, with bundled math fonts supplying missing symbols. Inline equations initially inherit the surrounding font; separate equation boxes start in STIX Two Math. Selected installed or session-added fonts also work on desktop. scripts/equation-fonts.py prepares pinned STIX Two Math (OFL-1.1) and Latin Modern Math (GUST Font License) in an external craft-fonts checkout, verifies file hashes, retains the licences and required documentation, and updates its manifest. Both fonts are included in native and web builds. CI invokes the script explicitly; local setup is documented in docs/equations.md. No font binaries are added to DeckCraft.

Release integration remains to be agreed before shipping: the shared release workflow needs a craft-fonts revision containing both math fonts, or an equivalent explicit preparation step in the shared workflow. Without the prepared math fonts the Ubuntu fallback works, but some math symbols are unavailable. This PR does not publish a separate font-repository or shared-workflow change.

Validation

On macOS with Rust 1.95.0 and the documented font setup:

  • Root workspace tests with serial execution: 1,747 passed, 6 ignored, no failures. One unrelated notes-spelling UI test failed in the parallel run, then passed in isolation and in the complete serial run.
  • Vendored equaSHion tests: 258 passed, 1 ignored, no failures; its formatting and strict Clippy checks pass.
  • Desktop build and all 23 WebAssembly crate checks pass.
  • Root formatting, PDF dependency validation, asset attribution, dependency layering and diff whitespace checks pass.
  • Actual Equation ribbon and Home font-picker interactions are exercised by UI tests. Rendered inline placeholders, fractions, gallery insertion, exit states and Latin Modern Math were visually inspected on synthetic slides. Engine tests cover selection replacement, normal-text formatting after exit, equation font changes, history, native/PPTX saves and table/rotated/RTL caret placement.

Full cargo xtask ci still stops at pre-existing Rust 1.95 Clippy warnings in main's media, model, animation, pointer and layer-checking code (collapsible_match, nonminimal_bool, manual_range_contains). The remaining gates were run separately. A full-workspace Clippy run allowing only those three known warning categories passes; no lint allowances were added to source code. Unrelated lint cleanup is excluded from this PR. Release packaging has not been validated.

shuff57 and others added 26 commits October 13, 2026 08:21
equashion-math (pptx: linear text of imported equations; text: the tree
an equation run is laid out from; engine: equation commands, MathML and
LaTeX paste, the OMML bridge) and equashion-egui (ui-egui: the
EquationEditor widget) from github.com/shuff57/equaSHion at 9746092.
The workspace manifest notes the [patch] override for a local checkout.
No new versions of existing crates: quick-xml, skrifa, harfrust,
vello_cpu, kurbo and egui unify with ours.

ATTRIBUTION.md lists the fonts equashion-egui bundles (Source Serif 4,
Inter, STIX Two Math, OFL-1.1) under "Bundled through dependencies".

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

The a14:m reader stores the equation's OMML with the namespace
declarations it inherited from a14:m or the slide part, its run text is
the equation's linear form (equashion-math, never empty) instead of the
concatenated m:t text, and the run takes the a:rPr PowerPoint keeps
inside the math runs (size, font, colour). On save the run's formatting
goes back into every m:r that has none, and equations in table cells
are written inside a paragraph-level mc:AlternateContent with a text
fallback (a cell cannot be wrapped as a whole).

Taken from the fork's equation-editor branch (467c95c and the pptx part
of 8187482) with deckcraft_math replaced by equashion_math; the forked
deckcraft-math crate is not carried over.

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

Model: a Math run is one unit for text editing. Typing, Enter and caret
moves never land inside it, a range that touches it deletes, copies,
cuts or formats the whole equation, and word motion steps over it.

Engine: `equashion_bridge` is the one place an equation crosses between
the stored OMML string and equaSHion's tree (OMML import / export, run
text = linear form of the written OMML). Commands, with strict parameter
validation (a typo'd id is an error, never another target):
- insert.equation {linear | omml, display?, rect?}: a text box holding
  the equation (28 pt Liberation Serif), cascaded so inserts do not stack
- equation.update {linear | omml, display?, id?, cell?, paragraph?, run?}
  replaces an equation in a shape or table cell, keeping its formatting
- equation.get / equation.fromLinear (queries): OMML, linear, display, tree
Insert > Equation's linear field now makes a real equation through
insert.equation (the superscript-digit text box is gone).

Taken from the fork's equation-editor branch (8187482 and the table-cell
part of 6861329) on equashion-math. Not carried over: equation.templates
and equation.type (the equation editor widget has the palette and the
typing model), and the forked math crate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A Math run is laid out from its OMML (read by equashion-math) as one
inline atom: fractions, roots, scripts, big operators with limits,
delimiters, matrices, accents, bars, boxes. The atom keeps the run's
character count (an object character plus word joiners), so carets,
selections and line breaking work as for text and it is never split
across lines; bidi sees it as a neutral. Radicals, brackets and sum /
product signs are drawn as vector shapes: Deco gains an optional path,
which the slide renderer and the Morph text transition fill.

Taken from the fork's equation-editor branch (6861329, the layout
before the in-app editor's caret geometry, which equaSHion's widget now
does) on equashion-math; Morph's deco fill is new.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Insert > Equation and a double-click on an equation open the Equation
dialog with equaSHion's widget (palette, canvas with caret, linear field,
display toggle) on a copy of the equation, loaded from the run's OMML
through equation.get. Enter / Insert / Update apply it with one command,
insert.equation (a new text box) or equation.update (that run, even if
the selection moved), so a new or changed equation is one undo step and
Cancel changes nothing. Esc follows the widget's DISCARD_PROMPT (a second
Esc discards changes); the dialog's generic Esc close is off for it, and
an Esc the widget did not see (it lost the keyboard) uses the same rule.
An empty equation is not applied ("Type or build an equation first.").

The dialog sits at the bottom centre so more of the slide stays visible.
The widget shares the app's egui context and installs nothing into it:
it draws with its own bundled fonts, and only the dialog's Ui gets the
theme accent as selection stroke (DeckCraft's is the white text colour,
which left the widget's caret and focus ring invisible). A kittest test
pins that the shared fonts and style are unchanged.

Engine: a double-click on an equation (a box holding only an equation,
or the equation's extent in mixed text, or a table cell holding only an
equation) requests the dialog with {edit, id, cell?, paragraph, run},
taken from the fork's 8e6fce4. The fork's in-app eqdialog.rs is replaced
by the widget and not carried over.

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

In front of edit.paste's text path, `equashion_bridge::clipboard_equation`
recognises clipboard text that is, trimmed, exactly one OMML m:oMath /
m:oMathPara element, one MathML <math> element, or LaTeX in $..$, $$..$$,
\(..\) or \[..\]; equaSHion reads it. It becomes an equation at the
insertion point of the text being edited (replacing the selection, with
the formatting there), else in a new equation text box as Insert >
Equation makes, one undo step, display from oMathPara / display="block"
/ $$ / \[. Single $ follows the Markdown rule (no space just inside), so
prices stay text. A payload that cannot be read pastes as text with a
status note. edit.pasteText (Paste and Match Formatting) stays literal.

Detection follows WordCraft's equaSHion port; the paste placement and
the engine tests come from the fork's dd5ebd2. Not carried over: reading
an HTML clipboard fragment (f6a8d68), since the app pastes plain text and
equaSHion's own Copy MathML puts the bare <math> element there.

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

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ions in the ribbon

Shown while the Equation dialog is open (and brought up when it opens): eleven
structure galleries, a Symbols menu with the eight sets, and Ready-made
Equations. They insert into the dialog's editor at the caret.

Needs equaSHion aa71dc0 (galleries, gallery_face); Cargo.toml still pins 9746092,
so build with a [patch] to a local checkout until it is bumped.

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

Picture buttons for the eleven galleries and the ready-made equations, the
3x10 symbol strip with its set menu, tile galleries with section headings,
Display / Inline / Justification, Close Equation (applies, as Insert does).
Unicode, LaTeX, Convert, Normal Text and Number are shown disabled: the
equaSHion editor has no equivalent yet.

Needs equaSHion 3ddd502.

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

No dialog window: Insert > Equation opens the editor in the middle of the slide,
a double-click on an equation opens it where that equation is drawn (equation.get
now says where, in slide points), sized to match. The Equation tab does the choosing.
Enter, Esc, a click on the slide outside it, or Close Equation leave it and keep the
edit as one undo step; an empty new equation is dropped.

Needs equaSHion 9b34e8c (inline mode).

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

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…quaSHion to the pushed tip

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
deckcraft-text's own 1,300-line equation layout is replaced by equashion-layout,
the engine the editor draws with: one model, one layout, one set of fonts, so
the slide shows what was typed in place. Glyphs become filled outlines (the
equation fonts are equaSHion's, not the deck's faces).

Needs equaSHion 9b34e8c; Cargo.toml still pins 9746092.

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

A plain click on an equation, selected or not, opens the in-place editor on release;
a drag from it still moves the box. A click on an equation inside text being edited
opens it too. Alt+= opens a new equation.

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

Typing and the Equation tab update the equation on the slide as they go (one undo
step for the whole edit); the editor overlays equaSHion's caret exactly on the
document's own drawing (equation.place gives its left edge, baseline and size).
Esc, Enter, a click on the slide away from it, or Close Equation leave it.

Needs equaSHion d8de4c0.

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

Library crates are unchanged from 9b6b169; only the rev moves.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Rebasing the equation work onto upstream's text changes left three seams:
Deco literals need both upstream's line style and the equation path, the
shaping key is upstream's four-part tuple, and upstream's per-run bidi
rules would resolve an equation inside right-to-left text as left to
right. Equation characters in a right-to-left paragraph now go with the
text around them, as text in a right-to-left language would.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Library crates are unchanged from ee62762; only the rev moves.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Empty slots under a radical, in a fraction or in a script show a dotted box
on the page, and the editor widget's caret and highlight sit on it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Merge PR storytold#192 and port the inline interaction work from storytold#771 through its native-OMML follow-up. Keep the session in charge of caret state, commands and history, with galleries and on-slide math geometry shared by typing and pointer input.

Vendor the pinned equaSHion libraries with provenance, use approved external STIX fonts, and omit unfinished draft controls. Preserve upstream main behavior and document validation and remaining release integration.
Merge upstream main at 9859da3, retaining both equation and PDF writer notices. No source-code conflicts.

Validation: 1743 workspace tests passed; 6 ignored. Formatting, PDF dependency validation, assets, layering and all 23 wasm checks passed. Full CI remains blocked by the existing Clippy warnings on main. Paused lint cleanup is excluded from this commit.
@shuff57

shuff57 commented Oct 16, 2026

Copy link
Copy Markdown

Thanks, @hajdukste. I went through #778 against #192's current head and against upstream equaSHion 386b16c, including the engine's inline module, the UI tests, the vendored crates and the font script. I'd like to take your inline model as the basis for where this goes. Here is what I'd suggest, so we don't duplicate each other's work.

Why your model. Your engine owns the equation caret, selection and undo, driven by equaSHion's Editor. That is what makes selection replacement, adjacent equations and hit testing in rotated, RTL and table-cell text possible, and #192's overlay can't do those without rebuilding the same state. So I don't want to port them piece by piece into #192. I'd rather build on yours.

What I'd change before it is the basis:

  1. equaSHion stays a git dependency, not a fork. Your vendored copy differs from 386b16c in a few places, and I'd rather those live upstream. I'll add these to equaSHion main: public SeqGeo row geometry, InputState with serde on Caret, the is_blank fix for styled empty text, and a host hook for adding fonts. I'll also review your two edit.rs changes (the guard before a typed backslash command, and the fraction/parenthesis condition), since they change typing behaviour for WordCraft too. I'll say here when it is done, and then Equations on slides: laid out and edited in place with equaSHion #192 bumps its rev.
  2. The default equation font stays equaSHion's bundled Source Serif 4. Changing it to STIX Two Math from craft-fonts means a build without scripts/equation-fonts.py loses some symbols, and the release workflow isn't settled. I'd rather keep the default working with no external step.
  3. One arrow path. Equations on slides: laid out and edited in place with equaSHion #192 has its own arrow handoff (ea29df1e, b7576c4e) that uses the widget. Yours replaces it. I'd keep yours and drop mine where they overlap.

Your part, and where it lands. Once the equaSHion commit is in, please rebase your five commits onto equashion-editor on shuff57/deckcraft (currently b7576c4e) and open a PR against that branch, the way you did with shuff57#1. Your authorship stays. I'll review and merge it there, so #192 stays the one PR to storytold and carries your work. The Home → Font selection (including Latin Modern Math) can be a separate PR after that, once the craft-fonts question is settled.

#778. Once your PR is merged into #192, #192 contains everything, so #778 can be closed in its favour. That is your call, since it is your PR. The aim is to give the maintainers one equation contribution to review, not three.

I haven't built or run either branch, so I'm going on your reported test results. If anything above doesn't fit what you built, say so before you start.

@hajdukste

Copy link
Copy Markdown
Contributor Author

Soudns good! Let me know when the equaSHion commit is in and I will rebase my five commits in there!

@hajdukste

Copy link
Copy Markdown
Contributor Author

Currently, I prefer #1029 as the solution because it uses similar approach as WordCraft and does not have dependancy on another repo.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing feature The reference application has it and we do not, or only part of it needs decision Needs a product or scope decision by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants