Gathering detailed insights and metrics for rehype-katex
Gathering detailed insights and metrics for rehype-katex
Gathering detailed insights and metrics for rehype-katex
Gathering detailed insights and metrics for rehype-katex
rehype-katex-svelte
rehype plugin to transform .math-inline, .math-display with KaTeX to Svelte markup
@revoltchat/rehype-katex
rehype plugin to transform inline and block math with KaTeX
@kwangkim/rehype-katex
KaTeX transform plugin for rehype
rehype-katex-notranslate
Add the attribute translate="no" to the katex formula generated by rehype-katex to prevent the formulas from being recognized and translated by webpage translation tools.
npm install rehype-katex
Typescript
Module System
Node Version
NPM Version
97.4
Supply Chain
96.4
Quality
80.6
Maintenance
100
Vulnerability
99.6
License
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
32,634,732
Last Day
33,194
Last Week
528,982
Last Month
2,257,329
Last Year
18,062,461
MIT License
443 Stars
288 Commits
65 Forks
9 Watchers
1 Branches
30 Contributors
Updated on Jul 03, 2025
Minified
Minified + Gzipped
Latest Version
7.0.1
Package Id
rehype-katex@7.0.1
Unpacked Size
15.66 kB
Size
5.73 kB
File Count
8
NPM Version
10.8.2
Node Version
22.0.0
Published on
Aug 19, 2024
Cumulative downloads
Total Downloads
Last Day
-3.9%
33,194
Compared to previous day
Last Week
-10.4%
528,982
Compared to previous week
Last Month
9.3%
2,257,329
Compared to previous month
Last Year
69.1%
18,062,461
Compared to previous year
rehype plugin to render elements with a language-math
class with
KaTeX.
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 KaTeX at compile time, which means that there is no client side JavaScript needed.
A different plugin, rehype-mathjax
, does the same but with
MathJax.
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install rehype-katex
In Deno with esm.sh
:
1import rehypeKatex from 'https://esm.sh/rehype-katex@7'
In browsers with esm.sh
:
1<script type="module"> 2 import rehypeKatex from 'https://esm.sh/rehype-katex@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 rehypeDocument from 'rehype-document' 2import rehypeKatex from 'rehype-katex' 3import rehypeParse from 'rehype-parse' 4import rehypeStringify from 'rehype-stringify' 5import {read, write} from 'to-vfile' 6import {unified} from 'unified' 7 8const file = await unified() 9 .use(rehypeParse, {fragment: true}) 10 .use(rehypeDocument, { 11 // Get the latest one from: <https://katex.org/docs/browser>. 12 css: 'https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css' 13 }) 14 .use(rehypeKatex) 15 .use(rehypeStringify) 16 .process(await read('input.html')) 17 18file.basename = 'output.html' 19await write(file)
…then running node example.js
creates an output.html
with:
1<!doctype html> 2<html lang="en"> 3<head> 4<meta charset="utf-8"> 5<title>input</title> 6<meta content="width=device-width, initial-scale=1" name="viewport"> 7<link href="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css" rel="stylesheet"> 8</head> 9<body> 10<p> 11 Lift(<span class="katex"><!--…--></span>) can be determined by Lift Coefficient 12 (<span class="katex"><!--…--></span>) like the following equation. 13</p> 14<span class="katex-display"><!--…--></span> 15</body> 16</html>
…open output.html
in a browser to see the rendered math.
This package exports no identifiers.
The default export is rehypeKatex
.
unified().use(rehypeKatex[, options])
Render elements with a language-math
(or math-display
, math-inline
)
class with KaTeX.
options
(Options
)
— configurationTransform (Transformer
).
Options
Configuration (TypeScript type).
1import {KatexOptions} from 'katex' 2 3type Options = Omit<KatexOptions, 'displayMode' | 'throwOnError'>
See Options on katex.org
for more info.
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 KaTeX 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 KaTeX requires CSS to render correctly.
You should use katex.css
somewhere on the page where the math is shown to
style it properly.
At the time of writing, the last version is:
1<!-- Get the latest one from: https://katex.org/docs/browser --> 2<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css">
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-katex@^7
,
compatible with Node.js 16.
This plugin works with unified version 6+ and rehype version 4+.
Assuming you trust KaTeX, using rehype-katex
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 KaTeX, run rehype-katex
after rehype-sanitize
:
1import rehypeKatex from 'rehype-katex' 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(rehypeKatex) 22 .use(rehypeStringify) 23 .process('$C$') 24 25console.log(String(file))
rehype-mathjax
— same but with MathJaxrehype-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
0 existing vulnerabilities detected
Reason
license file detected
Details
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
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
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-23
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