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

markdown-it-mathjax-node

v0.4.1

Published

Markdown-it plugin to include math in your document

Downloads

7

Readme

This is a markdown-it-mathjax-node

Call Mathjax-node to render math formula in markdown-it. Used deasync to bypass the markdown-it async only rule.

var md = require('markdown-it')()
            .use(require('markdown-it-mathjax-node'));

let res = md.render('$a_i e^2$。')
console.log(res)
// <p>\[x &amp;  (-x) = 1000_{(2)} = 8_{(10)}\] 。</p>

check test.js for more


npm Build Status

Note: This is a general markdown-it math plugin. It was originally designed to render MathML. If you intend to use MathJax, markdown-it-mathjax might be a better choise.

markdown-it-math

Pythagoran theorem is $$a^2 + b^2 = c^2$$.

Bayes theorem:

$$$
P(A | B) = (P(B | A)P(A)) / P(B)
$$$
<p>Pythagoran theorem is <math><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup><mo>=</mo><msup><mi>c</mi><mn>2</mn></msup></math>.</p>
<p>Bayes theorem:</p>
<math display="block"><mi>P</mi><mfenced open="(" close=")"><mrow><mi>A</mi><mo stretchy="true" lspace="veryverythickmathspace" rspace="veryverythickmathspace">|</mo><mi>B</mi></mrow></mfenced><mo>=</mo><mfrac><mrow><mi>P</mi><mfenced open="(" close=")"><mrow><mi>B</mi><mo stretchy="true" lspace="veryverythickmathspace" rspace="veryverythickmathspace">|</mo><mi>A</mi></mrow></mfenced><mi>P</mi><mfenced open="(" close=")"><mi>A</mi></mfenced></mrow><mrow><mi>P</mi><mfenced open="(" close=")"><mi>B</mi></mfenced></mrow></mfrac></math>

Installation

npm install markdown-it-math --save

Usage

var md = require('markdown-it')()
        .use(require('markdown-it-math') [, options]);

where options can be (with defaults)

var options = {
    inlineOpen: '$$',
    inlineClose: '$$',
    blockOpen: '$$$',
    blockClose: '$$$',
    renderingOptions: {},
    inlineRenderer: require('ascii2mathml')(this.rendererOptions),
    blockRenderer: require('ascii2mathml')(Object.assign({ display: 'block' },
                                                         this.renderingOptions))
}

(See ascii2mathml for reference about the default renderer).

Examples

Using comma as a decimal mark

var md = require('markdown-it')()
        .use(require('markdown-it-math'), {
            renderingOptions: { decimalMark: ',' }
        });

md.render("$$40,2$$");
// <p><math><mn>40,2</mn></math></p>

Using TeXZilla as renderer

var texzilla = require('texzilla');
var md = require('markdown-it')()
        .use(require('markdown-it-math'), {
            inlineRenderer: function(str) {
                return texzilla.toMathMLString(str);
            },
            blockRenderer: function(str) {
                return texzilla.toMathMLString(str, true);
            }
        });

md.render("$$\\sin(2\\pi)$$");
// <p><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mn>2</mn><mi>π</mi><mo stretchy="false">)</mo></mrow><annotation encoding="TeX">\sin(2\pi)</annotation></semantics></math></p>

Using LaTeX style delimiters

var md = require('markdown-it')()
        .use(require('markdown-it-math'), {
            inlineOpen: '\\(',
            inlineClose: '\\)',
            blockOpen: '\\[',
            blockClose: '\\]'
        })

Note there are restrictions on what inline delimiters you can use, based on optimization for the markdown-it parser see here for details. And block level math must be on its own lines with newlines separating the math from the delimiters.

Some text with inline math \(a^2 + b^2 = c^2\)

And block math

\[
e = sum_(n=0)^oo 1/n!
\]