Skip to content

Added free-text and free-math modes (multiline latex support) - #3060

Open
Shrookin wants to merge 3 commits into
arnog:masterfrom
Shrookin:pr/free-text-free-math
Open

Added free-text and free-math modes (multiline latex support)#3060
Shrookin wants to merge 3 commits into
arnog:masterfrom
Shrookin:pr/free-text-free-math

Conversation

@Shrookin

@Shrookin Shrookin commented Aug 21, 2026

Copy link
Copy Markdown

Summary

Adds two experimental multiline mathfield modes:

  • free-text: prose-first editing with inline LaTeX escapes.
  • free-math: math-first editing with multiline rows and inline text islands.

Both modes use a multiline root represented as an array of rows, preserving the document's line structure rather than flattening it into a single mathfield row.

free-text

free-text is intended for document-like editing while retaining MathLive's rendering and editing engine.

  • Ordinary prose is rendered with MathLive's text font.
  • Newlines, empty lines, trailing lines, and tabs are preserved.
  • A backslash enters an editable LaTeX run.
  • Once a LaTeX expression is completed, it is retained as a math island inside the prose.
  • Small inline symbols can be followed immediately by prose.
  • Larger mathematical structures, such as integrals, sums, products, fractions, and piecewise expressions, retain their mathematical atom structure and remain visually distinct from ordinary prose.
  • Text styles are stored as atom styles and support bold, italic, underline, and strike-through.
  • Bullet and numbered list text is preserved, including empty-row and continuation behavior handled by the editor.

free-math

free-math is intended for math-oriented multiline input.

  • Ordinary characters are parsed as math atoms using MathLive's math font and layout rules.
  • Newlines create separate editable rows.
  • Empty rows, trailing rows, and tabs are retained.
  • Text can be inserted through text islands such as \\text{...}.
  • Mathematical structures continue to use MathLive's normal atom model instead of being treated as prose.
  • Clipboard and value serialization preserve the complete multiline structure.

Keyboard compatibility

Free modes use document-editing semantics for their primary keys:

  • Tab inserts a literal tab.
  • Enter inserts a new logical line.
  • The regular text and math modes keep their existing behavior unchanged.
  • Ctrl+Tab moves to the next math group in a free mode.
  • Ctrl+Shift+Tab moves to the previous math group.
  • Ctrl/Cmd+Enter preserves the explicit commit/row-insertion command and restores the configured free-mode insertion state afterward.

This keeps placeholder/group navigation and explicit commit behavior available without taking Tab and Enter away from multiline editing.

Serialization and public API

  • Adds free-text and free-math to the public ParseMode and defaultMode types.
  • setValue() respects the configured free mode and parses replacement values with the correct semantics.
  • LaTeX round-tripping preserves empty rows, trailing rows, tabs, text styles, and inline math/text islands.
  • Updates plain-text clipboard behavior for both modes.
  • Updates MathML, Typst, spoken-text, ASCII math, and JSON conversion paths to understand multiline free-mode roots.
  • Keeps free-mode mode detection and style state consistent when moving the caret or changing the active mode.
  • Updates the API documentation and generated public declarations.

Implementation

The implementation reuses MathLive's existing multiline row/environment mechanics while introducing a dedicated free-mode root/parser layer. Rendering and serialization recognize both free modes as their corresponding text or math families, while the editor retains the mode distinction needed for keyboard input, LaTeX escapes, styling, and output.

Tests

  • Full unit suite: 334 tests passed.
  • Snapshot suite: 252 snapshots passed.
  • Focused Chromium free-mode coverage: 7 tests passed.
  • Public TypeScript declaration check passed.
  • Development build passed.

The feature is intentionally marked experimental for maintainer review.

@Shrookin
Shrookin marked this pull request as ready for review August 21, 2026 04:11
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.

1 participant