Math

Adds toolbar and addbar buttons for math formula blocks rendered with KaTeX. Supports inline and display delimiters ($...$, $$...$$, \(...\), \[...\]).

Click Math in the toolbar or addbar to insert a formula, or open an existing math block to edit it. Requires KaTeX loaded on the page (window.katex).

Click Math in the toolbar to insert a formula. Try inline $E=mc^2$ or display $$\\sum_{i=1}^{n} i$$.

$$\\sum_{i=1}^{n} i$$

Load the bundle

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css">
<script src="/assets/redactor/redactor.js"></script>
<script src="/assets/redactor/plugins/math/math.js"></script>

Initialization

const app = Redactor('#entry', {
    plugins: ['math']
});

Options

  • context (boolean)
    • default false
    • When true, adds the button to the context toolbar as well.
  • classname (string)
    • default 'math'
    • CSS class on math block elements.
  • delimiters (object[])
    • default [{ left: '$$', right: '$$', display: true }, { left: '$', right: '$', display: false }, ...]
    • Delimiter pairs for parsing and validating formulas. Each entry: { left, right, display }.
  • icon (string)
    • SVG icon HTML for the toolbar and addbar buttons.
Redactor('#entry', {
    plugins: ['math'],
    math: {
        context: false,
        classname: 'my-math'
    }
});

Formula examples:

  • Inline: $E=mc^2$ or \(E=mc^2\)
  • Display: $$\int_0^1 x^2 dx$$ or \[\int_0^1 x^2 dx\]

Language strings

en: {
    math: {
        math: 'Math',
        label: 'Type an expression (use $$$...$$$ or \\[...\\] for blocks, and $...$ or \\(...\\) for inline formulas)'
    }
}

Events

This plugin does not emit events.

API

insert

Opens the insert form or inserts a formula from form data.

save

Saves the edited formula on the current math block and re-renders with KaTeX.

remove

Removes the current math block.

app.math.remove();