Gathering detailed insights and metrics for rehype-mathjax-2
Gathering detailed insights and metrics for rehype-mathjax-2
Gathering detailed insights and metrics for rehype-mathjax-2
Gathering detailed insights and metrics for rehype-mathjax-2
npm install rehype-mathjax-2
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
4.0.3
Package Id
rehype-mathjax-2@4.0.3
Unpacked Size
24.77 kB
Size
7.55 kB
File Count
18
NPM Version
9.5.1
Node Version
18.16.1
Published on
Oct 11, 2024
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 <span class=math-inline>
and
<div class=math-display>
with MathJax.
This package is a unified (rehype) plugin to render math.
You can combine it with remark-math
for math in markdown or add
math-inline
and math-display
classes in HTML.
unified is a project that transforms content with abstract syntax trees (ASTs). rehype adds support for HTML to unified. hast is the HTML AST that rehype uses. This is a rehype plugin that transforms hast.
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
, is similar but uses
KaTeX instead.
This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:
1npm install rehype-mathjax
In Deno with esm.sh
:
1import rehypeMathjax from 'https://esm.sh/rehype-mathjax@4'
In browsers with esm.sh
:
1<script type="module"> 2 import rehypeMathjax from 'https://esm.sh/rehype-mathjax@4?bundle' 3</script>
Say we have the following file example.html
:
1<p> 2 Lift(<span class="math math-inline">L</span>) can be determined by Lift Coefficient 3 (<span class="math math-inline">C_L</span>) like the following equation. 4</p> 5 6<div class="math math-display"> 7 L = \frac{1}{2} \rho v^2 S C_L 8</div>
And our module example.js
looks as follows:
1import {read} from 'to-vfile' 2import {unified} from 'unified' 3import rehypeParse from 'rehype-parse' 4import rehypeMathjax from 'rehype-mathjax' 5import rehypeStringify from 'rehype-stringify' 6 7const file = await unified() 8 .use(rehypeParse, {fragment: true}) 9 .use(rehypeMathjax) 10 .use(rehypeStringify) 11 .process(await read('example.html')) 12 13console.log(String(file))
Now running node example.js
yields:
1<p> 2 Lift(<span class="math math-inline"><mjx-container class="MathJax" jax="SVG"><!--…--></mjx-container></span>) can be determined by Lift Coefficient 3 (<span class="math math-inline"><mjx-container class="MathJax" jax="SVG"><!--…--></mjx-container></span>) like the following equation. 4</p> 5 6<div class="math math-display"><mjx-container class="MathJax" jax="SVG" display="true"><!--…--></mjx-container></div> 7<style> 8mjx-container[jax="SVG"] { 9 direction: ltr; 10} 11/* … */ 12</style>
This package exports no identifiers.
The default export is rehypeMathjaxSvg
.
unified().use(rehypeMathjaxSvg[, options])
Transform <span class="math-inline">
and <div class="math-display">
with
MathJax.
This package includes three plugins, split out because MathJax targets have a big memory and bundle size footprint: SVG, CHTML, and browser:
Render math as SVG
(import rehypeMathjaxSvg from 'rehype-mathjax/svg.js'
, default).
About 566kb minzipped.
Render math as CHTML
(import rehypeMathjaxChtml from 'rehype-mathjax/chtml.js'
).
About 154kb minzipped.
Needs a fontURL
to be passed.
Tiny wrapper that expects MathJax to do work client side
(import rehypeMathjaxBrowser from 'rehype-mathjax/browser.js'
).
About 1kb minzipped.
Uses options.displayMath
(default: ['\\[', '\\]']
) for display math and
options.inlineMath
(default: ['\\(', '\\)']
) for inline math.
You need to load MathJax on the client yourself and start it with corresponding markers. Options are not passed to MathJax: do that yourself on the client.
options
All options, except when using the browser plugin, are passed to MathJax.
options.tex
These options are passed to the TeX input processor.
The browser plugin uses the first delimiter pair in tex.displayMath
and
tex.inlineMath
to instead wrap math.
options.chtml
These options are passed to the CommonHTML output
processor.
Passing 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 // …
options.svg
These options are passed to the SVG output processor.
The HTML produced by MathJax does not require any extra CSS to render correctly.
This plugin transforms elements with a class name of either math-inline
and/or
math-display
.
This package is fully typed with TypeScript.
An extra Options
type is exported, which models the accepted options.
Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.
This plugin works with unified version 6+ and rehype version 4+.
Using rehype-mathjax
should be safe assuming that you trust MathJax.
Any vulnerability in it could open you to a cross-site scripting (XSS)
attack.
Always be wary of user input and use rehype-sanitize
.
When you don’t trust user content but do trust MathKax, you can allow the
classes added by remark-math
while disallowing anything else in the
rehype-sanitize
schema, and run rehype-katex
afterwards.
Like so:
1import rehypeSanitize, {defaultSchema} from 'rehype-stringify' 2 3const mathSanitizeSchema = { 4 ...defaultSchema, 5 attributes: { 6 ...defaultSchema.attributes, 7 div: [ 8 ...defaultSchema.attributes.div, 9 ['className', 'math', 'math-display'] 10 ], 11 span: [ 12 ['className', 'math', 'math-inline'] 13 ] 14 } 15} 16 17// … 18 19unified() 20 // … 21 .use(rehypeSanitize, mathSanitizeSchema) 22 .use(rehypeMathjax) 23 // …
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