@nextgensoftwares/folio-plugin-math
Equation editing: select, edit, insert and type inline and display math. Guide: Math plugin.
Plugin
| Export | Signature | Description |
|---|---|---|
mathPlugin | (options?: MathPluginOptions) => MathPlugin | keymap, input rule, edit state, UI items (toolbar, slash, math.edit group), the overlay slot popover and the $…$ paste handler |
type MathPlugin | FolioPlugin plus commands: MathCommands, check(latex, display) and recents | |
type MathCommands | math.edit(), math.insert(display?, latex?), math.apply(latex, display?), math.close(), math.toggleDisplay(), math.insertDirect(latex, display?) | |
type MathPluginOptions | renderMath?, katex?, inputRules? (true), paste? (true), bubble? (true), toolbar? (true), shortcut? ('Mod-Shift-M'), recentKey? ('folio-math-recent', null = memory only) | |
type MathRenderer | (latex, display) => string | LaTeX → HTML, same shape as @nextgensoftwares/folio-react's |
type KatexLike | { renderToString(latex, { displayMode?, throwOnError?, output? }) }: pass KaTeX for exact error positions |
Edit state and commands
The open editor is a session held in a ProseMirror plugin state; positions are mapped through every transaction. Nothing is written to the document until it's applied, and applying is one transaction (one undo step).
| Export | Description |
|---|---|
mathEditKey, mathEditPlugin() | the plugin key / plugin holding the session; a folio:pointer meta ≥ 2 (double-click) on a selected equation opens it |
type MathEditSession | { mode: 'edit' | 'insert', from, to, display, latex } |
mathSession(state) | the open session or null |
selectedMath(state) | { node, pos } of a NodeSelection on mathInline / mathBlock, or null |
isMath(node), editSession(node, pos) | helpers |
openMathEditor() | command: open on the selected equation |
startMathInsert(display?, latex?) | command: open to insert at the selection (selected text becomes the LaTeX) |
applyMath(latex, display?) | command: update / switch inline ↔ display / insert; empty LaTeX deletes an edited equation; closes the session |
closeMathEditor() | command: close without changes |
toggleMathDisplay() | command: switch the selected equation between inline and display |
insertMath(latex, display?) | command: insert directly (no editor) |
Input
| Export | Description |
|---|---|
inlineMathRule() | appendTransaction input rule: typing the closing $ of $…$ makes inline math (not for $5 and $10, \$, $$ or code) |
displayMathRule | command (bound to Enter): a paragraph holding only $$ opens a display-equation insert |
mathKeymap({ inputRules, shortcut }) | Enter / Mod-Enter open the selected equation, Backspace/Delete select an adjacent equation first, the shortcut inserts |
mathFromText(schema, text) | $$…$$ → { display }; $…$ spans in one line → a Fragment; else null |
pasteMath(editor, data) | plugin paste handler for plain-text payloads |
Validation
| Export | Description |
|---|---|
checkLatex(latex, display, { katex?, renderMath? }) | → MathCheck; never throws |
type MathCheck | { ok: true, html } or { ok: false, message, from?, to? } |
errorExcerpt(latex, from, to, room?) | { before, bad, after } around the error |
Palette
| Export | Description |
|---|---|
MATH_SYMBOLS | default groups: Structures (fractions, roots, sums, integrals, matrices, cases…), Greek, Operators, Arrows |
type MathSymbol, type MathSymbolGroup | { latex, preview?, name, keywords? }, { id, label, symbols } |
CARET | '‸': where the caret lands in a template (selected text is wrapped there) |
previewOf(symbol) | what a palette button renders |
searchSymbols(groups, query, limit?) | every query word must match name, keywords, LaTeX or group |
insertSymbol(text, start, end, latex) | { text, caret } after inserting at the textarea selection |
class RecentSymbols | get(), add(symbol), subscribe(fn); newest first, max 12, localStorage failures ignored |
UI
| Export | Description |
|---|---|
mathEditItems() | math.edit, math.toggleDisplay, math.copyLatex (group math.edit; hidden unless an equation is selected and no editor is open) |
MATH_EDIT_GROUP | 'math.edit': route it with ui.route |
mathToolbarItems() | math.insert (Insert group; replaces the built-in equation control) with Inline / Display children |
mathSlashItems() | slash.math ("Equation", display; replaces the built-in) and slash.mathInline |
createMathOverlay(deps), type MathOverlayDeps | the overlay slot component: popover + selection outline |
MathForm, type MathFormProps | the popover's form (source, preview, error, inline/display, palette, actions) |
SymbolPalette | the palette component |
MATH_CSS | the plugin's styles (injected by the overlay) |