┌────────────────────────────────────────────────────────────────────┐ │ 📄 shadcn/directory/udecode/plate/(plugins)/(elements)/equation.cn │ └────────────────────────────────────────────────────────────────────┘
╔══════════════════════════════════════════════════════════════════════════════════════════════╗
║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║
title: 数学公式 docs:
最快捷的方式是使用MathKit套件,它包含预配置的EquationPlugin和InlineEquationPlugin以及Plate UI组件。
EquationElement: 渲染块级公式元素InlineEquationElement: 渲染行内公式元素将套件添加到插件中:
import { createPlateEditor } from 'platejs/react';
import { MathKit } from '@/components/editor/plugins/math-kit';
const editor = createPlateEditor({
plugins: [
// ...其他插件,
...MathKit,
],
});
</Steps>
npm install @platejs/math
在创建编辑器时将公式插件包含到Plate插件数组中。
import { EquationPlugin, InlineEquationPlugin } from '@platejs/math/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...其他插件,
EquationPlugin,
InlineEquationPlugin,
],
});
使用自定义组件配置插件来渲染公式元素。
import { EquationPlugin, InlineEquationPlugin } from '@platejs/math/react';
import { createPlateEditor } from 'platejs/react';
import { EquationElement, InlineEquationElement } from '@/components/ui/equation-node';
const editor = createPlateEditor({
plugins: [
// ...其他插件,
EquationPlugin.withComponent(EquationElement),
InlineEquationPlugin.withComponent(InlineEquationElement),
],
});
withComponent: 指定EquationElement渲染块级公式,InlineEquationElement渲染行内公式。您可以在工具栏中添加EquationToolbarButton来插入公式。
EquationPlugin用于块级公式元素的插件。
InlineEquationPlugin用于行内公式元素的插件。
tf.insert.equationtf.insert.inlineEquation插入一个行内公式。
<API name="insert.inlineEquation"> <APIParameters> <APIItem name="texExpression" type="string" optional> 要插入的LaTeX表达式。如未提供则为空公式。 </APIItem> <APIItem name="options" type="InsertNodesOptions" optional> 插入节点的转换选项 </APIItem> </APIParameters> </API>TEquationElementinterface TEquationElement extends TElement {
texExpression: string;
}
║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║
╚══════════════════════════════════════════════════════════════════════════════════════════════╝