{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "equation-docs",
  "title": "Equation",
  "description": "Block and inline LaTeX equation nodes rendered with KaTeX.",
  "files": [
    {
      "path": "../../content/docs/(plugins)/(elements)/equation.mdx",
      "content": "---\ntitle: Equation\ndescription: Block and inline LaTeX equation nodes rendered with KaTeX.\ndocs:\n  - route: /docs/components/equation-node\n    title: Equation Element\n  - route: /docs/components/equation-toolbar-button\n    title: Equation Toolbar Button\n  - route: https://pro.platejs.org/docs/examples/equation\n    title: Plus\n---\n\nEquation adds block and inline void nodes for LaTeX expressions. Both nodes store source in `texExpression` and render through KaTeX. This page covers kit setup, block versus inline ownership, insertion, input rules, Markdown serialization, and registry UI behavior.\n\n<ComponentPreview name=\"equation-demo\" />\n\n<PackageInfo>\n\n## Features\n\n- Block `equation` element.\n- Inline void `inline_equation` element.\n- Bound `editor.tf.insert.equation` and `editor.tf.insert.inlineEquation` transforms.\n- Direct `insertEquation` and `insertInlineEquation` helpers.\n- KaTeX rendering in editable and static UI.\n- `$...$` inline input rule and `$$` block input rule.\n- Markdown round-trip for inline math and block math.\n\n</PackageInfo>\n\n## Fast Path\n\n<Steps>\n\n### Add The Kit\n\n`MathKit` installs both equation plugins, their registry components, and the default math input rules.\n\n<ComponentSource name=\"math-kit\" />\n\n```tsx\nimport { createPlateEditor } from 'platejs/react';\n\nimport { MathKit } from '@/components/editor/plugins/math-kit';\n\nexport const editor = createPlateEditor({\n  plugins: MathKit,\n});\n```\n\n### Render The Nodes\n\n`equation-node` owns the block equation, inline equation, editable popover, textarea input, KaTeX render target, static elements, and DOCX fallback elements.\n\n<ComponentSource name=\"equation-node\" />\n\n### Add The Toolbar Button\n\n`equation-toolbar-button` inserts an inline equation with `insertInlineEquation(editor)`.\n\n<ComponentSource name=\"equation-toolbar-button\" />\n\n</Steps>\n\n## Ownership\n\n| Layer | Owner | What It Does |\n|-------|-------|--------------|\n| `@platejs/math` | Package | Exports base plugins, transforms, `MathRules`, and `getEquationHtml`. |\n| `@platejs/math/react` | Package | Exports React plugins plus `useEquationElement` and `useEquationInput`. |\n| `math-kit` | Registry | Adds block and inline React plugins with input rules and interactive UI components. |\n| `math-base-kit` | Registry | Adds static equation components for read-only rendering. |\n| `equation-node` | Registry UI | Renders editable, static, and DOCX equation elements. |\n| `equation-toolbar-button` | Registry UI | Inserts inline equations from the toolbar. |\n| `@platejs/markdown` | Package | Serializes and deserializes `math` and `inlineMath` nodes when `remark-math` is configured. |\n\nBlock and inline equations share the `TEquationElement` shape, but they are different node types with different plugin keys.\n\n## Manual Setup\n\n<Steps>\n\n### Install Package\n\n```bash\nnpm install @platejs/math\n```\n\n### Add Plugins\n\nUse both React plugins when your editor supports block and inline equations.\n\n```tsx\nimport { MathRules } from '@platejs/math';\nimport {\n  EquationPlugin,\n  InlineEquationPlugin,\n} from '@platejs/math/react';\nimport { createPlateEditor } from 'platejs/react';\n\nimport {\n  EquationElement,\n  InlineEquationElement,\n} from '@/components/ui/equation-node';\n\nexport const editor = createPlateEditor({\n  plugins: [\n    InlineEquationPlugin.configure({\n      inputRules: [MathRules.markdown({ variant: '$' })],\n      node: { component: InlineEquationElement },\n    }),\n    EquationPlugin.configure({\n      inputRules: [MathRules.markdown({ on: 'break', variant: '$$' })],\n      node: { component: EquationElement },\n    }),\n  ],\n});\n```\n\n### Add Static Rendering\n\nUse the base kit when rendering read-only output with `platejs/static`.\n\n<ComponentSource name=\"math-base-kit\" />\n\n### Insert Equations\n\nUse plugin-bound transforms when you already have a configured editor.\n\n```tsx\neditor.tf.insert.equation({ select: true });\neditor.tf.insert.inlineEquation('E = mc^2', { select: true });\n```\n\nUse package helpers directly from toolbar, slash-command, or app-local action code.\n\n```tsx\nimport { insertEquation, insertInlineEquation } from '@platejs/math';\n\ninsertEquation(editor, { select: true });\ninsertInlineEquation(editor, 'E = mc^2', { select: true });\n```\n\n</Steps>\n\n## Value Shape\n\nBoth equation nodes store source in `texExpression`. The child text is only the Slate-required child for a void element.\n\n```tsx\nconst value = [\n  {\n    children: [\n      { text: 'Mass-energy equivalence: ' },\n      {\n        children: [{ text: '' }],\n        texExpression: 'E = mc^2',\n        type: 'inline_equation',\n      },\n      { text: '.' },\n    ],\n    type: 'p',\n  },\n  {\n    children: [{ text: '' }],\n    texExpression: '\\\\\\\\int_{a}^{b} f(x) \\\\\\\\, dx = F(b) - F(a)',\n    type: 'equation',\n  },\n];\n```\n\n| Node | Type | Behavior |\n|------|------|----------|\n| `BaseEquationPlugin` | `equation` | Block void equation. |\n| `BaseInlineEquationPlugin` | `inline_equation` | Inline void equation. |\n| `TEquationElement.texExpression` | `string` | LaTeX source rendered by KaTeX. |\n\n## Input Rules\n\n`MathRules.markdown` creates editor input rules. It is separate from Markdown serialization.\n\n| Rule | Trigger | Behavior |\n|------|---------|----------|\n| `MathRules.markdown({ variant: '$' })` | `$...$` | Deletes the delimited text and inserts an inline equation with the matched expression. |\n| `MathRules.markdown({ on: 'break', variant: '$$' })` | `$$` then line break | Replaces the paragraph fence with a block equation. |\n| `MathRules.markdown({ on: 'match', variant: '$$' })` | `$$...$$` match | Creates a block equation on match. |\n\nMath input rules are disabled inside code blocks, block equations, and inline equations.\n\n## Rendering\n\nThe registry components render KaTeX and keep source editing in a popover.\n\n| Surface | Behavior |\n|---------|----------|\n| Editable block equation | `useEquationElement` calls `katex.render` with display-mode options. |\n| Editable inline equation | Opens a popover when the inline void node is selected and the selection is collapsed. |\n| Popover input | `useEquationInput` writes `texExpression` as the textarea changes. |\n| `Enter` | Submits and closes the input. |\n| `Escape` | Dismisses; inline equations restore the initial expression. |\n| Inline left/right edge arrows | Move selection out of the inline equation. |\n| Static rendering | `getEquationHtml` calls `katex.renderToString`. |\n\nKaTeX is configured with `throwOnError: false`, `strict: 'warn'`, and `trust: false` in the registry UI.\n\n## Markdown\n\nMarkdown math support comes from `@platejs/markdown` plus `remark-math`, as configured by the registry `MarkdownKit`.\n\n```mdx\nInline $x+1$ math\n```\n\n```mdx\n$$\nx+1\n$$\n```\n\nInline math deserializes to `inline_equation`. Block math deserializes to `equation`. Serialization writes the same Markdown math shapes from `texExpression`.\n\n## Plate Plus\n\n<ComponentPreviewPro name=\"equation-pro\" />\n\n## API Reference\n\n| API | Package | Use |\n|-----|---------|-----|\n| `BaseEquationPlugin` | `@platejs/math` | Headless block equation plugin. |\n| `BaseInlineEquationPlugin` | `@platejs/math` | Headless inline equation plugin. |\n| `EquationPlugin` | `@platejs/math/react` | React block equation plugin. |\n| `InlineEquationPlugin` | `@platejs/math/react` | React inline equation plugin. |\n| `insertEquation(editor, options)` | `@platejs/math` | Inserts a blank block equation. |\n| `insertInlineEquation(editor, texExpression?, options?)` | `@platejs/math` | Inserts an inline equation. Defaults to the selected string when no expression is passed. |\n| `editor.tf.insert.equation(options)` | plugin-bound transform | Bound block equation insert transform. |\n| `editor.tf.insert.inlineEquation(texExpression?, options?)` | plugin-bound transform | Bound inline equation insert transform. |\n| `MathRules.markdown(options)` | `@platejs/math` | Creates inline or block math input rules. |\n| `useEquationElement(options)` | `@platejs/math/react` | Renders an equation into a KaTeX DOM target. |\n| `useEquationInput(options)` | `@platejs/math/react` | Wires the equation textarea and keyboard behavior. |\n| `getEquationHtml(options)` | `@platejs/math` | Returns static KaTeX HTML. |\n| `TEquationElement` | `platejs` | Element shape with `texExpression`. |\n",
      "type": "registry:file",
      "target": "content/docs/plate/(plugins)/(elements)/equation.mdx"
    }
  ],
  "type": "registry:file"
}