@daiji256/rehype-mathml

中文文档
1.3.0发布于 2026/10/12MITTypeScriptES Module构建来源已验证近 30 天下载 4259

用 MathML 制作数学的复韵插件

中文使用文档
文档目录12 节
  1. 目录
  2. 这是什么?
  3. 我什么时候用这个?
  4. 安装
  5. 使用
  6. API 密码
  7. unified().use(rehypeMathML[, options])
  8. Options
  9. 标记
  10. HTML 语言
  11. 类型
  12. 许可证

@daiji256/rehype-mathml (英语)

npm version npm downloads

复韵 用 MathML 制作数学的插件 使用teml将 LaTeX 数学转换为 MathML . 使用原因 齿轮 是个轻量级的图书馆 广泛覆盖了LaTeX功能.

目录

这是什么?

这个软件包是 统一 (单位:千美元)复韵) 与 MathML 一起制作数学的插件 . 您可以在 HTML 元素中添加类, 在标记下使用有栅栏的代码, 或者合并 与 remark-math (单位:千美元) $C$ 语法扩展.

我什么时候用这个?

这个项目很有用,因为它让数学在编译时间, 这意味着不需要客户端JavaScript或图像.

此插件是其他插件的 MathML 版本, 如 rehype-mathjax (与 MathJax 交接)和 rehype-katex (与KaTeX交锋. 有了MathML,HTML就变得更简单更轻. 此外,它还支持使用数学字体,例如: 点数。 。 。 .

安装

在Node.js(第16版+)中,安装为 无数字 :

npm install @daiji256/rehype-mathml

为了确保每个浏览器中数学表达式的正确渲染,您需要添加 Temml.woff2 财务报告和审定财务报表 Temml-*.css。 。 。 .

使用

说我们的文件 input.html 包含:

<p>
  Lift(<code class="language-math">L</code>) can be determined by Lift
  Coefficient (<code class="language-math">C_L</code>) like the following
  equation.
</p>
<pre><code class="language-math">
  L = \frac{1}{2} \rho v^2 S C_L
</code></pre>

...和我们的模块 example.js 包含:

import { unified } from 'unified';
import rehypeParse from 'rehype-parse';
import rehypeStringify from 'rehype-stringify';
import rehypeMathML from '@daiji256/rehype-mathml';
import { read, write } from 'to-vfile';

const file = await unified()
  .use(rehypeParse, { fragment: true })
  .use(rehypeMathML)
  .use(rehypeStringify)
  .process(await read('input.html'));

file.basename = 'output.html';
await write(file);

...然后运行 node example.js 创建一个 output.html 改为:

<p>
  Lift(<math><!--…--></math>) can be determined by Lift
  Coefficient (<math><!--…--></math>) like the following
  equation.
</p>
<math display="block" class="tml-display" style="display:block math;"><!--…--></math>

...打开 output.html 在浏览器中看到所渲染的数学.

API 密码

此套件不导出标识符 . 默认导出为 rehypeMathML。 。 。 .

unified().use(rehypeMathML[, options])

带a的渲染元素 language-math (或 math-display, (中文(简体) ), math-inline(中文(简体) ) 分类 数学ML。 。 。 .

Options

配置( TypeScript 类型).

import type { Options as TemmlOptions } from 'temml';

type Options = Partial<TemmlOptions>;

见 选项 打开 temml.org 需要更多信息.

标记

此插件支持启用的语法扩展 remark-math。 。 。 . 它还支持通过使用栅栏代码生成的数学:

```math
C_L
```

HTML 语言

含有一个 language-math, (中文(简体) ), math-inline,或 math-display 类被改变. 元素被由temml所转化出的MathML所取代. 无论是a math-display 分类或使用 <pre><code class="language-math"> 将 结果是“显示”数学:数学是自身线上的一个障碍.

类型

此软件包已全部输入 类型脚本。 。 。 . 它输出额外类型 Options。 。 。 .

许可证

麻省理工学院 © 大吉256号

版本与发布记录

@daiji256/rehype-mathml 共发布 9 个版本,首次发布于 2024/11/15;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.3.0latest2026/10/1230 天前
1.2.22025/12/2310 个月前
1.2.12025/06/111.4 年前
1.2.02025/02/191.7 年前
1.1.12024/11/182 年前
1.1.02024/11/162 年前

关于 @daiji256/rehype-mathml 的常见问题

@daiji256/rehype-mathml 是什么?

用 MathML 制作数学的复韵插件

如何安装 @daiji256/rehype-mathml?

在项目目录运行 npm install @daiji256/rehype-mathml,或使用 pnpm add / yarn add / bun add。

@daiji256/rehype-mathml 支持 TypeScript 吗?

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

@daiji256/rehype-mathml 支持 ESM 还是 CommonJS?

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

@daiji256/rehype-mathml 可以商用吗?

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

@daiji256/rehype-mathml 的下载量有多少?

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

@daiji256/rehype-mathml 还在维护吗?

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