npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

remark-math-2

v5.1.2

Published

remark plugin to parse and stringify math

Downloads

1,098

Readme

remark-math

Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to support math ($C_L$).

Contents

What is this?

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.

When should I use this?

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.

Install

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 esm.sh:

import remarkMath from 'https://esm.sh/remark-math@5'

In browsers with esm.sh:

<script type="module">
  import remarkMath from 'https://esm.sh/remark-math@5?bundle'
</script>

Use

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'

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>

API

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.

If you turn this off, you can still use two or more dollars for text math.

Syntax

This plugin applies a micromark extensions to parse the syntax. The syntax basically follows how code works in markdown, except that dollars ($) are used instead of backticks (`) and that 2 or more dollars instead of 3 or more backticks is enough for blocks.

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

👉 Note: Like code, the difference between “inline” and “block”, is in the line endings:

$$inline$$

$$
block
$$

HTML

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.

Syntax tree

This plugin applies one mdast utility to build and serialize the AST. See its readme for the node types supported in the tree:

Types

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.
    })
  }
}

Compatibility

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.

Security

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.

Related

Contribute

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

License

MIT © Junyoung Choi