JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1108555
  • Score
    100M100P100Q201932F
  • License MIT

micromark extension to support math (`$C_L$`)

Package Exports

  • micromark-extension-math

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (micromark-extension-math) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

micromark-extension-math

Build Coverage Downloads Size Sponsors Backers Chat

micromark extension to support math ($C_L$).

As there is no spec for math in markdown, this extension stays as close to code in text and fenced code in flow in CommonMark, but using dollar signs.

This package provides the low-level modules for integrating with the micromark tokenizer and the micromark HTML compiler.

You probably shouldn’t use the HTML parts of this package directly, but instead use mdast-util-math with mdast.

Math (text) can start with one or more dollar signs, so long as they match:
With one: $\alpha$, two: $$\beta$$, or three: $$$\gamma$$$.

This is useful, because like code, typical markdown escapes don’t work.
For dollars inside math, use more dollars around it: $$\raisebox{0.25em}{$\frac
a b$}$$.

If the math starts and ends with a space (or EOL), those are removed: $$ \$ $$.

Math (flow) starts at two or more dollars:

$$
\Delta
$$

You can hide some stuff in the meta of the opening fence (but no dollars):

$$hidden information
$$

Math which doesn’t have a closing fence, still works, like fenced code:

> $$
> this is
> all math

…but at the end of their container (block quote, list item, or document), they
are closed.

Install

npm:

npm install micromark-extension-math

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 script, example.js, looks as follows:

var fs = require('fs')
var micromark = require('micromark')
var math = require('micromark-extension-math')
var mathHtml = require('micromark-extension-math/html')

var doc = fs.readFileSync('example.md')

var result = micromark(doc, {
  extensions: [math],
  htmlExtensions: [mathHtml()]
})

console.log(result)

Now, running node example yields (abbreviated):

<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 class="katex"></span></span></div>

API

html(options?)

syntax

Note: syntax is the default export of this module, html is available at micromark-extension-math/html.

Support math. The export of syntax is an extension for the micromark parser (to tokenize math in text and flow; can be passed in extensions). The export of html is a function that can be called with options and returns an extension for the default HTML compiler (to compile math with KaTeX; can be passed in htmlExtensions).

options

Passed to katex.renderToString. displayMode is overwritten by this plugin, to false for math in text, and true for math in flow.

Contribute

See contributing.md in micromark/.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 © Titus Wormer