Gathering detailed insights and metrics for rehype-mathjax
Gathering detailed insights and metrics for rehype-mathjax
Gathering detailed insights and metrics for rehype-mathjax
Gathering detailed insights and metrics for rehype-mathjax
rehype-mathjax-dumi-tmp
rehype plugin to transform inline and block math with MathJax
remark-html-katex
Deprecated: this package is no longer maintained. Please use `remark-rehype` to move from remark (markdown) to rehype (HTML) and then replace `remark-html-katex` with [`rehype-katex`][rehype-katex] or [`rehype-mathjax`][rehype-mathjax].
rehype-mathjax-2
rehype plugin to transform inline and block math with MathJax
npm install rehype-mathjax
Typescript
Module System
Node Version
NPM Version
rehype-mathjax@7.1.0
Updated on Feb 20, 2025
rehype-mathjax@7.0.0
Updated on Feb 12, 2025
rehype-katex@7.0.1
Updated on Aug 19, 2024
rehype-mathjax@6.0.0
Updated on Dec 21, 2023
rehype-mathjax@5.0.0
Updated on Sep 19, 2023
rehype-katex@7.0.0
Updated on Sep 19, 2023
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
446 Stars
288 Commits
65 Forks
9 Watchers
1 Branches
30 Contributors
Updated on Jul 11, 2025
Latest Version
7.1.0
Package Id
rehype-mathjax@7.1.0
Unpacked Size
41.50 kB
Size
11.49 kB
File Count
26
NPM Version
11.1.0
Node Version
23.1.0
Published on
Feb 20, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
rehype plugin to render elements with a language-math
class with
MathJax.
This package is a unified (rehype) plugin to render math.
You can add classes to HTML elements, use fenced code in markdown, or combine
with remark-math
for a $C$
syntax extension.
This project is useful as it renders math with MathJax at compile time, which means that there is no client side JavaScript needed.
A different plugin, rehype-katex
, does the same but with
KaTeX.
This package is ESM only. In Node.js (version 18+), install with npm:
1npm install rehype-mathjax
In Deno with esm.sh
:
1import rehypeMathjax from 'https://esm.sh/rehype-mathjax@7'
In browsers with esm.sh
:
1<script type="module"> 2 import rehypeMathjax from 'https://esm.sh/rehype-mathjax@7?bundle' 3</script>
Say our document input.html
contains:
1<p> 2 Lift(<code class="language-math">L</code>) can be determined by Lift Coefficient 3 (<code class="language-math">C_L</code>) like the following equation. 4</p> 5<pre><code class="language-math"> 6 L = \frac{1}{2} \rho v^2 S C_L 7</code></pre>
…and our module example.js
contains:
1import rehypeMathjax from 'rehype-mathjax' 2import rehypeParse from 'rehype-parse' 3import rehypeStringify from 'rehype-stringify' 4import {read, write} from 'to-vfile' 5import {unified} from 'unified' 6 7const file = await unified() 8 .use(rehypeParse, {fragment: true}) 9 .use(rehypeMathjax) 10 .use(rehypeStringify) 11 .process(await read('input.html')) 12 13file.basename = 'output.html' 14await write(file)
…then running node example.js
creates an output.html
with:
1<p> 2 Lift(<mjx-container class="MathJax" jax="SVG"><!--…--></mjx-container>) can be determined by Lift Coefficient 3 (<mjx-container class="MathJax" jax="SVG"><!--…--></mjx-container>) like the following equation. 4</p> 5<mjx-container class="MathJax" jax="SVG" display="true"><!--…--></mjx-container> 6<style> 7mjx-container[jax="SVG"] { 8 direction: ltr; 9} 10/* … */ 11</style>
…open output.html
in a browser to see the rendered math.
This package has an export map with several entries for plugins using different strategies:
rehype-mathjax/browser
— browser (±1kb)rehype-mathjax/chtml
— CHTML (±154kb)rehype-mathjax/svg
— SVG (±566kb)rehype-mathjax
— same as SVGEach module exports the plugin rehypeMathjax
as
the default export.
unified().use(rehypeMathjax[, options])
Render elements with a language-math
(or math-display
, math-inline
)
class with MathJax.
options
(Options
, typically optional)
— configurationTransform (Transformer
).
Options
Configuration (TypeScript type).
chtml
(unknown
, optional)
— configuration for the output, when CHTML;
see CommonHTML Output Processor Options on
mathjax.org
svg
(unknown
, optional)
— configuration for the output, when SVG;
see SVG Output Processor Options on
mathjax.org
tex
(unknown
, optional)
— configuration for the input TeX;
see TeX Input Processor Options on
mathjax.org
When using rehype-mathjax/browser
, only options.tex.displayMath
and
options.tex.inlineMath
are used.
That plugin will use the first delimiter pair in those fields to wrap
math.
Then you need to load MathJax yourself on the client and start it with the
same markers.
You can pass other options on the client.
When using rehype-mathjax/chtml
, options.chtml.fontURL
is required.
For example:
1 // … 2 .use(rehypeMathjaxChtml, { 3 chtml: { 4 fontURL: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/output/chtml/fonts/woff-v2' 5 } 6 }) 7 // …
This plugin supports the syntax extension enabled by
remark-math
.
It also supports math generated by using fenced code:
1```math
2C_L
3```
The content of any element with a language-math
, math-inline
, or
math-display
class is transformed.
The elements are replaced by what MathJax renders.
Either a math-display
class or using <pre><code class="language-math">
will
result in “display” math: math that is a centered block on its own line.
The HTML produced by MathJax does not require any extra CSS to render correctly.
This package is fully typed with TypeScript.
It exports the additional type Options
.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, rehype-mathjax@7
,
compatible with Node.js 18.
This plugin works with unified version 6+ and rehype version 4+.
Assuming you trust MathJax, using rehype-mathjax
is safe.
A vulnerability in it could open you to a
cross-site scripting (XSS) attack.
Be wary of user input and use rehype-sanitize
.
When you don’t trust user content but do trust MathJax, run rehype-mathjax
after rehype-sanitize
:
1import rehypeMathjax from 'rehype-mathjax' 2import rehypeSanitize, {defaultSchema} from 'rehype-sanitize' 3import rehypeStringify from 'rehype-stringify' 4import remarkMath from 'remark-math' 5import remarkParse from 'remark-parse' 6import remarkRehype from 'remark-rehype' 7import {unified} from 'unified' 8 9const file = await unified() 10 .use(remarkParse) 11 .use(remarkMath) 12 .use(remarkRehype) 13 .use(rehypeSanitize, { 14 ...defaultSchema, 15 attributes: { 16 ...defaultSchema.attributes, 17 // The `language-*` regex is allowed by default. 18 code: [['className', /^language-./, 'math-inline', 'math-display']] 19 } 20 }) 21 .use(rehypeMathjax) 22 .use(rehypeStringify) 23 .process('$C$') 24 25console.log(String(file))
rehype-katex
— same but with KaTeXrehype-highlight
— highlight code blocksrehype-autolink-headings
— add links to headingsrehype-sanitize
— sanitize HTMLrehype-document
— wrap a document around the treeSee contributing.md
in remarkjs/.github
for ways
to get started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
security policy file detected
Details
Reason
Found 3/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More