Features
Libraries
Inline and block formulas written in LaTeX, drawn by KaTeX, with a symbol palette while editing.
Installation#
bash
pnpm dlx shadcn@latest add @zui/document-editor @zui/editor-mathUsage#
tsx
import type { DocJSON, IEditor } from '@zeroxsolutions/editor-core/document/core/index';
import { math } from '@/components/editor/document/features/math';
import { standardKit } from '@/components/editor/document/features/standard';
import { Editor } from '@/components/editor/document/react';tsx
const features = [standardKit(), math()];
function NotesEditor({ content }: { content: DocJSON }) {
return <Editor features={features} content={content} />;
}math adds mathInline, a formula inside a line of text, and mathBlock, a formula on its own line, both written in LaTeX in the latex attribute and drawn by KaTeX. Its slash items are "Inline math" and "Math block", and the commands insertMathInline and insertMathBlock take an optional latex.
Run the command on the editor that Editor hands to onReady, as Document Editor shows:
tsx
function insert(editor: IEditor) {
editor.run('insertMathBlock', { latex: 'x^2 + y^2 = r^2' });
}The Viewer draws the same block, with the same feature in its features, wherever a stored document is only read.