Nahi Pata Mujhe!

# npm

Have ideas to improve npm?Join in the discussion! »

## math-ml-now

2.0.3 • Public • Published

# MathMLNow - MathML with scriptless fallback

"Mathematical Markup Language (MathML) is a dialect of XML for describing mathematical notation and capturing both its structure and content." - MDN

In browsers that support it, MathML allows for the display of maths equations in a simple way that never pixilates, can be copied and pasted, and can be read by screen readers.

But because most browsers do not support MathML, fallback content is necessary. Traditionally, this has been done with the JavaScript library MathJax, but MathJax suffers from the same problem any JavaScript library has - it is a large download that slows down the users browsing; and doesn't work when JavaScript is turned off (or more likely, broken by another script on the page).

MathMLNow is a Node package that produces a series of HTML tags that show MathML if available, gracefully degrading to an SVG image, and then to a PNG image if even SVG is not supported.

To see an example of this technique in action, visit this example page.

## Getting started

MathMLNow provides a function in the file ./app.js.

The file provided is called MathMLNow. To generate the MathMLNow used in the example file, the following commands were used:

If you wish to support browsers that do not support SVG graphics (about 2.5% of the world at the time of writing), you need to pass the location to your website's image folder to the imageFolder config option. In addition, add the following to your website's CSS:

(Thanks to CSS-Tricks for sharing this nugget of wisdom.)

If you wish to replace inline math instances in a large file (say, a HTML page), then you can pipe it as a vinyl stream:

This will replace any instance of Math inbetween two "$$" strings, with font-size, vertical margin percent, horizontal margin percent, and font-color all settable in optional paramaters (in that order) provided after the math string with "||" seperators. For example, if you wanted the Euler's identity result from up above, you would place$$e^{i\pi}+1=0||30$$(math string = "e^{i\pi}+1=0", font-size = 30) wherever you wanted that math to appear. The Integral of the secant function from up above would be expressed as$$\int_0^{\pi/6}\sec\left(y\right)\operatorname dy=\ln\left(\sqrt3i^{64}\right)||16||20

(math string = "\int_0^{\pi/6}\sec\left(y\right)\operatorname dy=\ln\left(\sqrt3i^{64}\right)", font-size = 16, vertical margin percent = 20).

## Using with MathJax

If you want to use this as a fallback and MathJax when possible, add this script to your page after where you included the MathJax script (IE9 and up):

## Documentation

MathMLNow takes two paramaters - a string representing the maths equation to render (in the same formats MathJax-node accepts, as that is what is used internally), and a MathMLNowOptions object.

## Keywords

### Install

npm i math-ml-now

15

2.0.3

MIT

366 kB

10

### Homepage

github.com/Sora2455/MathMlNow/

### Repository

github.com/Sora2455/MathMlNow