@daiji256/rehype-mathml

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

rehype plugin to render math with MathML

原始使用文档
文档目录12 节
  1. Contents
  2. What is this?
  3. When should I use this?
  4. Install
  5. Use
  6. API
  7. unified().use(rehypeMathML[, options])
  8. Options
  9. Markdown
  10. HTML
  11. Types
  12. License

@daiji256/rehype-mathml

npm version npm downloads

rehype plugin to render math with MathML by converting LaTeX math to MathML using temml. The reason for using temml is that it is a lightweight library with a wide coverage of LaTeX functions.

Contents

What is this?

This package is a unified (rehype) plugin to render math with MathML. You can add classes to HTML elements, use fenced code in markdown, or combine with remark-math for a $C$ syntax extension.

When should I use this?

This project is useful as it renders math with MathML at compile time, which means that no client-side JavaScript or images are needed.

This plugin is the MathML version of other plugins like rehype-mathjax (renders with MathJax) and rehype-katex (renders with KaTeX). With MathML, the HTML becomes simpler and lighter. Additionally, it supports the use of math fonts like Noto Math.

Install

In Node.js (version 16+), install with npm:

npm install @daiji256/rehype-mathml

To ensure proper rendering of mathematical expressions in every browser, you need to add Temml.woff2 and Temml-*.css.

Use

Say our document input.html contains:

<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>

…and our module example.js contains:

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);

…then running node example.js creates an output.html with:

<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>

…open output.html in a browser to see the rendered math.

API

This package exports no identifiers. The default export is rehypeMathML.

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

Render elements with a language-math (or math-display, math-inline) class with MathML.

Options

Configuration (TypeScript type).

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

type Options = Partial<TemmlOptions>;

See Options on temml.org for more info.

Markdown

This plugin supports the syntax extension enabled by remark-math. It also supports math generated by using fenced code:

```math
C_L
```

HTML

The content of any element with a language-math, math-inline, or math-display class is transformed. The elements are replaced by MathML transformed by temml. Either a math-display class or using <pre><code class="language-math"> will result in “display” math: math that is a block on its own line.

Types

This package is fully typed with TypeScript. It exports the additional type Options.

License

MIT © Daiji256

版本与发布记录

@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 是什么?

rehype plugin to render math with 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 和提交记录判断。