@aparte/plugin-katex

中文文档
1.0.0发布于 2026/11/07MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 2391

Maths for aparté via KaTeX — formulas drawn as they stream, under any Markdown provider.

原始使用文档
文档目录4 节
  1. Which Markdown provider
  2. While a reply streams
  3. Options
  4. Two entry points

@aparte/plugin-katex

Maths for aparté via KaTeX. Every $…$, $$…$$, \(…\) and \[…\] in a reply is drawn as a formula — while the reply streams, under whichever Markdown provider recognises maths.

A formula drawn from a display block, with the prices around it left as text, in an aparté chat
npm install @aparte/plugin-katex @aparte/core katex
import 'katex/dist/katex.min.css';
import { setupKatex } from '@aparte/plugin-katex';

setupKatex();

@aparte/core and katex are peer dependencies. KaTeX's stylesheet is yours to import: its fonts are relative URLs your bundler resolves. Without it each formula shows twice, and the plugin says so once in the console.

Which Markdown provider

Maths has to be recognised before Markdown reads it — \, and a*b*c mean something else to Markdown. @aparte/plugin-marked (one-shot and /streaming) and @aparte/plugin-streaming-markdown recognise it on their own once this plugin is registered. A provider of your own hands maths over by emitting <code class="language-math math-inline">TeX</code>, or <pre><code class="language-math math-display"> for a block — the markup remark-math already produces.

A single $ follows Pandoc's rule, so a price stays a price: $5 and $10 is text.

While a reply streams

A formula is drawn as it arrives. One KaTeX cannot parse yet — \frac{1}{ — keeps the last drawing that it could, so nothing flashes red mid-stream. Once the reply is finished, a formula that still does not parse shows its TeX, quietly, with KaTeX's message as a tooltip.

Options

setupKatex(options?, config?) takes KatexOptions:

optiondefault
livetruefalse draws a formula once it has closed
katex{}KaTeX's own options: macros, leqno, fleqn, output…
maxLength4000a longer formula shows as TeX

What the plugin keeps, whatever katex says: trust is false (no \href, no \htmlClass), maxSize and maxExpand are capped, and macros is copied for each formula, so a \gdef in one reply cannot reach the next.

Two entry points

@aparte/plugin-katex loads KaTeX on the first formula. If you would rather hand it over — your own build, a CDN copy — use the entry that imports nothing from katex:

import katex from 'katex';
import { setupKatexWith } from '@aparte/plugin-katex/core';

setupKatexWith(katex);

setupKatexWith takes the instance, or a function returning a promise of it, and any object shaped like KatexLike (a renderToString). Both functions return a disposer.

ESM only.

版本与发布记录

@aparte/plugin-katex 共发布 15 个版本,首次发布于 2026/10/29;过去 12 个月发布了 15 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.0latest2026/11/07今天
0.32.12026/11/025 天前
0.32.02026/11/025 天前
0.31.02026/11/026 天前
0.30.12026/11/016 天前
0.30.02026/11/016 天前

关于 @aparte/plugin-katex 的常见问题

@aparte/plugin-katex 是什么?

Maths for aparté via KaTeX — formulas drawn as they stream, under any Markdown provider.

如何安装 @aparte/plugin-katex?

在项目目录运行 npm install @aparte/plugin-katex,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:katex(>=0.18.2 <1.0.0)、@aparte/core(>=1.0.0 <2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aparte/plugin-katex 支持 TypeScript 吗?

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

@aparte/plugin-katex 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aparte/plugin-katex 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aparte/plugin-katex 可以商用吗?

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

@aparte/plugin-katex 的下载量有多少?

根据 npm 官方下载统计,@aparte/plugin-katex 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,391 次,日均约 80 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aparte/plugin-katex 还在维护吗?

最新版本 1.0.0 发布于 2026/11/07(今天);至今共发布 15 个版本,其中过去 12 个月发布了 15 个;首次发布于 2026/10/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。