Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
remark-math
Advanced tools
The remark-math package is a plugin for the remark markdown processor that allows you to parse and render mathematical expressions written in LaTeX. It supports both inline and block math expressions, making it useful for documents that require mathematical notation.
Inline Math
This feature allows you to include inline mathematical expressions within your markdown text. The example demonstrates how to use the remark-math plugin to parse and render an inline math expression.
const remark = require('remark');
const remarkMath = require('remark-math');
const html = require('remark-html');
remark()
.use(remarkMath)
.use(html)
.process('Here is some inline math: $E=mc^2$', function (err, file) {
if (err) throw err;
console.log(String(file));
});
Block Math
This feature allows you to include block mathematical expressions in your markdown text. The example demonstrates how to use the remark-math plugin to parse and render a block math expression.
const remark = require('remark');
const remarkMath = require('remark-math');
const html = require('remark-html');
remark()
.use(remarkMath)
.use(html)
.process('$$\int_0^\infty e^{-x} \, dx = 1$$', function (err, file) {
if (err) throw err;
console.log(String(file));
});
markdown-it-math is a plugin for the markdown-it parser that allows you to include LaTeX math expressions in your markdown documents. It supports both inline and block math, similar to remark-math, but is designed to work with the markdown-it ecosystem.
KaTeX is a fast, easy-to-use JavaScript library for TeX math rendering on the web. While it is not a markdown plugin itself, it can be used in conjunction with markdown parsers to render math expressions. It is known for its speed and reliability.
MathJax is a JavaScript display engine for mathematics that works in all browsers. It supports a wide range of LaTeX and MathML expressions. Like KaTeX, it is not a markdown plugin but can be integrated with markdown parsers to render math expressions.
remark plugin to support math ($C_L$
).
This package is a unified (remark) plugin to add support for math. You can use this to add support for parsing and serializing this syntax extension.
unified is a project that transforms content with abstract syntax trees (ASTs). remark adds support for markdown to unified. mdast is the markdown AST that remark uses. micromark is the markdown parser we use. This is a remark plugin that adds support for the math syntax and AST to remark.
This project is useful when you want to support math in markdown. Extending markdown with a syntax extension makes the markdown less portable. LaTeX equations are also quite hard. But this mechanism works well when you want authors, that have some LaTeX experience, to be able to embed rich diagrams of math in scientific text.
This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:
npm install remark-math
In Deno with Skypack:
import remarkMath from 'https://cdn.skypack.dev/remark-math@5?dts'
In browsers with Skypack:
<script type="module">
import remarkMath from 'https://cdn.skypack.dev/remark-math@5?min'
</script>
Say we have the following file example.md
:
Lift($L$) can be determined by Lift Coefficient ($C_L$) like the following
equation.
$$
L = \frac{1}{2} \rho v^2 S C_L
$$
And our module example.js
looks as follows:
import {read} from 'to-vfile'
import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkMath from 'remark-math'
import remarkRehype from 'remark-rehype'
import rehypeKatex from 'rehype-katex'
import rehypeStringify from 'rehype-stringify'
main()
async function main() {
const file = await unified()
.use(remarkParse)
.use(remarkMath)
.use(remarkRehype)
.use(rehypeKatex)
.use(rehypeStringify)
.process(await read('example.md'))
console.log(String(file))
}
Now running node example.js
yields:
<p>Lift(<span class="math math-inline"><span class="katex">…</span></span>) can be determined by Lift Coefficient (<span class="math math-inline"><span class="katex">…</span></span>) like the following equation.</p>
<div class="math math-display"><span class="katex-display">…</span></div>
This package exports no identifiers.
The default export is remarkMath
.
unified().use(remarkMath[, options])
Plugin to support math.
options
Configuration (optional).
options.singleDollarTextMath
Whether to support math (text) with a single dollar (boolean
, default:
true
).
Single dollars work in Pandoc and many other places, but often interfere with
“normal” dollars in text.
This plugin applies a micromark extensions to parse the syntax. See its readme for parse details:
👉 Note:
$math$
works similar to`code`
. That means escapes don’t work inside math but you can use more dollars around the math instead:$$\raisebox{0.25em}{$\frac a b$}$$
This plugin integrates with remark-rehype
.
When mdast (markdown AST) is turned into hast (the HTML AST) the math nodes
are turned into <span class=math-inline>
and <div class=math-block>
elements.
This plugin applies one mdast utility to build and serialize the AST. See its readme for the node types supported in the tree:
This package is fully typed with TypeScript.
It exports an extra Options
type which models the interface of the accepted
options.
If you’re working with the syntax tree, make sure to import this plugin somewhere in your types, as that registers the new node types in the tree.
/** @typedef {import('remark-math')} */
import {visit} from 'unist-util-visit'
/** @type {import('unified').Plugin<[], import('mdast').Root>} */
export default function myRemarkPlugin() => {
return (tree) => {
visit(tree, (node) => {
// `node` can now be one of the nodes for math.
})
}
}
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 remark version 14+. The previous major (version 4) worked with remark 13.
Use of remark-math
itself does not open you up to cross-site scripting
(XSS) attacks.
Always be wary of user input and use rehype-sanitize
.
remark-gfm
— support GFM (autolink literals, footnotes, strikethrough, tables,
tasklists)remark-frontmatter
— support frontmatter (YAML, TOML, and more)remark-directive
— support directivesSee 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.
FAQs
remark plugin to parse and stringify math
The npm package remark-math receives a total of 336,475 weekly downloads. As such, remark-math popularity was classified as popular.
We found that remark-math demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.