@aarkue/tiptap-math-extension

中文文档
1.4.0发布于 2025/09/14MITTypeScriptESM + CJS近 30 天下载 4.2万

Math/LaTeX Extension for the TipTap Editor

原始使用文档
文档目录7 节
  1. Usage
  2. Features
  3. Display Inline LaTeX
  4. Evaluate LaTeX Expression
  5. Screenshots + Demo
  6. Options
  7. Related or Used Projects

Math/LaTeX Extension for the TipTap Editor

Use inline math expression / LaTeX directly in your editor!

npm license npm version npm downloads

Usage

See the demo at /example for a quick introduction on how to use this package. The package is now available on NPM as @aarkue/tiptap-math-extension. It can be installed using npm install @aarkue/tiptap-math-extension.

To correctly render the LaTeX expressions, you will also need to include the KaTeX CSS. If you are using vite you can use import "katex/dist/katex.min.css"; in the component which renders the tiptap editor. This requires that you also install the katex npm package using npm i katex (https://www.npmjs.com/package/katex). There are also different ways to include the CSS, for instance by using a CDN like jsdelivr.net. See https://katex.org/docs/browser for more information. Note, however, that only the CSS needs to be included manually, as the JS is already bundled with this plugin.

Features

Display Inline LaTeX

Writing a math expression surrounded by $-signs automatically creates a rendered LaTeX expression. The delimiters are also configurable via the corresponding option.

To edit or delete the LaTeX, simply press backspace with the cursor placed before the expression. The rendered LaTeX will disappear and the LaTeX source will become normal editable text again.

Evaluate LaTeX Expression

Note: Since version 1.2.0 this feature needs to be explicitly enabled. This can be done using the evaluate configuration option:

const editor = useEditor({
  extensions: [StarterKit, MathExtension.configure({ evaluation: true })],
  content: "<p>Hello World!</p>",
});

Calculation results can be shown inline, using the Evaluatex.js library.

Define variables using the := notation (e.g., x := 120). Then, expressions can include this variable (e.g., x \cdot 4=). End the calculating expressions with = to automatically show the computed result.

Screenshots + Demo

Try out the demo directly online at https://aarkue.github.io/tiptap-math-extension/!

2023-06-03_16-05

2023-06-03_16-05_1

https://github.com/aarkue/tiptap-math-extension/assets/20766652/96f31846-d4a8-4cb2-b963-ff6da57daeb1

Options

There are a few options available to configure the extension. See below for typescript definitions of all available options and their default value.

export interface MathExtensionOption {
  /** Evaluate LaTeX expressions */
  evaluation: boolean;
  /** Add InlineMath node type (currently required as inline is the only supported mode) */
  addInlineMath: boolean;
  /** KaTeX options to use for evaluation, see also https://katex.org/docs/options.html */
  katexOptions?: KatexOptions;
  /** Delimiters to auto-convert. Per default dollar-style (`dollar`) ($x_1$ and $$\sum_i i$$) are used.
   *
   * The `bracket` option corresponds to `\(x_1\)` and `\[\sum_i i \]`.
   *
   * Alternatively, custom inline/block regexes can be used.
   * The inner math content is expected to be the match at index 1 (`props.match[1]`).
   */
  delimiters?:
    | "dollar"
    | "bracket"
    | {
        inlineRegex?: string;
        blockRegex?: string;
        inlineStart?: string;
        inlineEnd?: string;
        blockStart?: string;
        blockEnd?: string;
      };
      
  /** If and how to represent math nodes in the raw text output (e.g., `editor.getText()`)
   * 
   * - `"none"`: do not include in text at all
   * - `"raw-latex"`: include the latex source, without delimiters (e.g., `\frac{1}{n}`)
   * - `{placeholder: "[...]`"}: represent all math nodes as a fixed placeholder string (e.g., `[...]`)
   * 
   * The option delimited-latex is currently disabled because of issues with it re-triggering input rules (see also https://github.com/ueberdosis/tiptap/issues/2946).
   * 
   * - ~`"delimited-latex"`: include the latex source with delimiters (e.g., `$\frac{1}{n}$`)~
   */
    renderTextMode?: "none"|"raw-latex"|{placeholder: string}, // |"delimited-latex"
}
export const DEFAULT_OPTIONS: MathExtensionOption = { addInlineMath: true, evaluation: false, delimiters: "dollar", renderTextMode: "raw-latex" };

See https://katex.org/docs/options.html for a complete list of the available KaTeX options.

  • Tiptap Editor: The extensible editor for which this is an extension.
  • KaTeX: A LaTeX rendering engine for the web, used to render LaTeX expressions.
  • Evaluatex.js: Used to evaluate LaTeX expressions to a numeric value (e.g., 1 + (2 \cdot 3) = 7).
  • Vite: Used to serve the example demo project.

版本与发布记录

@aarkue/tiptap-math-extension 共发布 19 个版本,首次发布于 2024/03/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.0latest2025/09/141.1 年前
1.3.62025/04/301.5 年前
1.3.52025/04/171.6 年前
1.3.42025/01/241.8 年前
1.3.32024/08/092 年前
1.3.3-beta.6beta2024/07/232 年前

关于 @aarkue/tiptap-math-extension 的常见问题

@aarkue/tiptap-math-extension 是什么?

Math/LaTeX Extension for the TipTap Editor

如何安装 @aarkue/tiptap-math-extension?

在项目目录运行 npm install @aarkue/tiptap-math-extension,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@tiptap/core(^3.0.0)、@tiptap/pm(^3.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aarkue/tiptap-math-extension 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aarkue/tiptap-math-extension 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@aarkue/tiptap-math-extension 可以商用吗?

@aarkue/tiptap-math-extension 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aarkue/tiptap-math-extension 的下载量有多少?

根据 npm 官方下载统计,@aarkue/tiptap-math-extension 在 2026/10/05 – 2026/11/03 这 30 天内被下载 41,977 次,日均约 1,399 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aarkue/tiptap-math-extension 还在维护吗?

最新版本 1.4.0 发布于 2025/09/14(1.1 年前);至今共发布 19 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/03/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。