Giter Club home page Giter Club logo

mathjax-node's Introduction

MathJax

Beautiful math in all browsers

GitHub release version GitHub release version (v2) NPM version powered by NumFOCUS
jsdelivr rank jsDelivr hits (npm) npm monthly downloads (full) npm total downloads

MathJax is an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in all modern browsers. It was designed with the goal of consolidating the recent advances in web technologies into a single, definitive, math-on-the-web platform supporting the major browsers and operating systems. It requires no setup on the part of the user (no plugins to download or software to install), so the page author can write web documents that include mathematics and be confident that users will be able to view it naturally and easily. Simply include MathJax and some mathematics in a web page, and MathJax does the rest.

Some of the main features of MathJax include:

  • High-quality display of LaTeX, MathML, and AsciiMath notation in HTML pages

  • Supported in most browsers with no plug-ins, extra fonts, or special setup for the reader

  • Easy for authors, flexible for publishers, extensible for developers

  • Supports math accessibility, cut-and-paste interoperability, and other advanced functionality

  • Powerful API for integration with other web applications

See http://www.mathjax.org/ for additional details about MathJax, and https://docs.mathjax.org for the MathJax documentation.

MathJax Components

MathJax version 3 uses files called components that contain the various MathJax modules that you can include in your web pages or access on a server through NodeJS. Some components combine all the pieces you need to run MathJax with one or more input formats and a particular output format, while other components are pieces that can be loaded on demand when needed, or by a configuration that specifies the pieces you want to combine in a custom way. For usage instructions, see the MathJax documentation.

Components provide a convenient packaging of MathJax's modules, but it is possible for you to form your own custom components, or to use MathJax's modules directly in a node application on a server. There are web examples showing how to use MathJax in web pages and how to build your own components, and node examples illustrating how to use components in node applications or call MathJax modules directly.

What's in this Repository

This repository contains only the component files for MathJax, not the source code for MathJax (which are available in a separate MathJax source repository). These component files are the ones served by the CDNs that offer MathJax to the web. In version 2, the files used on the web were also the source files for MathJax, but in version 3, the source files are no longer on the CDN, as they are not what are run in the browser.

The components are stored in the es5 directory, and are in ES5 format for the widest possible compatibility. In the future, we may make an es6 directory containing ES6 versions of the components.

Installation and Use

Using MathJax components from a CDN on the web

If you are loading MathJax from a CDN into a web page, there is no need to install anything. Simply use a script tag that loads MathJax from the CDN. E.g.,

<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

See the MathJax documentation, the MathJax Web Demos, and the MathJax Component Repository for more information.

Hosting your own copy of the MathJax Components

If you want to host MathJax from your own server, you can do so by installing the mathjax package using npm and moving the es5 directory to an appropriate location on your server:

npm install mathjax@3
mv node_modules/mathjax/es5 <path-to-server-location>/mathjax

Note that we are still making updates to version 2, so include @3 when you install, since the latest chronological version may not be version 3.

Alternatively, you can get the files via GitHub:

git clone https://github.com/mathjax/MathJax.git mj-tmp
mv mj-tmp/es5 <path-to-server-location>/mathjax
rm -rf mj-tmp

Then (in either case) you can use a script tag like the following:

<script id="MathJax-script" async src="<url-to-your-site>/mathjax/tex-chtml.js"></script>

where <url-to-your-site> is replaced by the URL to the location where you moved the MathJax files above.

See the documentation for details.

Using MathJax components in a node application

To use MathJax components in a node application, install the mathjax package:

npm install mathjax@3

(we are still making updates to version 2, so you should include @3 since the latest chronological version may not be version 3).

Then require mathjax within your application:

require('mathjax').init({ ... }).then((MathJax) => { ... });

where the first { ... } is a MathJax configuration, and the second { ... } is the code to run after MathJax has been loaded. E.g.

require('mathjax').init({
  loader: {load: ['input/tex', 'output/svg']}
}).then((MathJax) => {
  const svg = MathJax.tex2svg('\\frac{1}{x^2-1}', {display: true});
  console.log(MathJax.startup.adaptor.outerHTML(svg));
}).catch((err) => console.log(err.message));

Note: this technique is for node-based application only, not for browser applications. This method sets up an alternative DOM implementation, which you don't need in the browser, and tells MathJax to use node's require() command to load external modules. This setup will not work properly in the browser, even if you webpack it or bundle it in other ways.

See the documentation and the MathJax Node Repository for more details.

Reducing the Size of the Components Directory

Since the es5 directory contains all the component files, so if you are only planning one use one configuration, you can reduce the size of the MathJax directory by removing unused components. For example, if you are using the tex-chtml.js component, then you can remove the tex-mml-chtml.js, tex-svg.js, tex-mml-svg.js, tex-chtml-full.js, and tex-svg-full.js configurations, which will save considerable space. Indeed, you should be able to remove everything other than tex-chtml.js, and the input/tex/extensions, output/chtml/fonts/woff-v2, adaptors, a11y, and sre directories. If you are using the results only on the web, you can remove adaptors as well.

If you are not using A11Y support (e.g., speech generation, or semantic enrichment), then you can remove a11y and sre as well (though in this case you may need to disable the assistive tools in the MathJax contextual menu in order to avoid MathJax trying to load them when they aren't there).

If you are using SVG rather than CommonHTML output (e.g., tex-svg.js rather than tex-chtml.js), you can remove the output/chtml/fonts/woff-v2 directory. If you are using MathML input rather than TeX (e.g., mml-chtml.js rather than tex-chtml.js), then you can remove input/tex/extensions as well.

The Component Files and Pull Requests

The es5 directory is generated automatically from the contents of the MathJax source repository. You can rebuild the components using the command

npm run make-es5 --silent

Note that since the contents of this repository are generated automatically, you should not submit pull requests that modify the contents of the es5 directory. If you wish to submit a modification to MathJax, you should make a pull request in the MathJax source repository.

MathJax Community

The main MathJax website is http://www.mathjax.org, and it includes announcements and other important information. A MathJax user forum for asking questions and getting assistance is hosted at Google, and the MathJax bug tracker is hosted at GitHub.

Before reporting a bug, please check that it has not already been reported. Also, please use the bug tracker (rather than the help forum) for reporting bugs, and use the user's forum (rather than the bug tracker) for questions about how to use MathJax.

MathJax Resources

mathjax-node's People

Contributors

ambar avatar dependabot[bot] avatar dpvc avatar geyang avatar gjtorikian avatar jcayzac avatar onomojo avatar pauldraper avatar peterldowns avatar physikerwelt avatar pkra avatar pomax avatar sammarshallou avatar zorkow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mathjax-node's Issues

Bug: TeX `\liminf` procudes invalid SVG output / treatment of known-unkown chars

This is more of a MathJax-core issue but I wasn't sure how to file it so I wanted to discuss this here first.

Issue Summary

Converting \liminf leads to invalid SVG.

(Also, tex2svg does not produce output if unknown characters are reported.)

Steps to Reproduce

  • Converting TeX input \liminf to SVG will contain<text transform="scale(53.81925) matrix(1 0 0 -1 0 0)" stroke="none" font-weight="" font-style="" font-family="STIXGeneral,'Arial Unicode MS',serif"> </text> which is invalid since font-weight and font-style are empty.
  • Removing the empty attributes fixes this.

IIUC, the problem is that converting TeX input \liminf to MathML produces u+2006 which is not covered by the MathJax TeX fonts (at least according to the error message of the SVG output) but also (in the output) not converted into characters that are covered. In turn, this unknown characters is causing the text tag.

Generate HTML/CSS output?

My goal is to pass a Tex string to MathJax and receive HTML & CSS back.

It looks like this library only allows you to output the math as SVG, PNG or MML. Do you intend to add HTML?

SVG output and equations numbering

Since MathJax-node assumes a fixed page width, equation numbers can make small equations take up a large amount of space. That's in particular a problem on small viewport sizes. While overflow:auto or automatic scaling help to some degree, neither is very good.

Can we do something smart here? Such as fixing the padding between equation and label to a fixed amount?

SVG render issue

I'm working on improving MathJax support in GitBook 2.0.0 by inlining svg but I have some issues with MathJax -Node:

For example with:

\begin{multline*}
\frac{\partial\xi^{(k+1)}}{\partial\xi^{(k)}}=
I-\mathcal{D}_{22}^{-1}(\omega^{(k+1)},\xi^{(k)})
(\mathcal{D}_{21}(\omega^{(k+1)},\xi^{(k)})
\frac{\partial\omega^{(k+1)}}{\partial\xi^{(k)}}
+\mathcal{D}_{22}(\omega^{(k+1)},\xi^{(k)}))=\\
\mathcal{D}_{22}^{-1}(\omega^{(k+1)},\xi^{(k)})
(\mathcal{D}_{21}(\omega^{(k+1)},\xi^{(k)})
\frac{\partial\omega^{(k+1)}}{\partial\xi^{(k)}}
\end{multline*}

The output with the normal MathJax in a webpage (output SVG) is:

screen shot 2015-01-29 at 17 50 44

And with MathJax-node:

screen shot 2015-01-29 at 17 50 53

If I use the option linebreaks, I have the issue #62:

screen shot 2015-01-29 at 17 53 21

Autoloading of color extension not working

E.g.,

$ node bin/tex2svg --inline '\definecolor{red}{RGB}{255,0,0}\color{red}e^{i \pi} + 1 = 0'

returns with

TeX parse error: Undefined control sequence \definecolor

But

$ node bin/tex2svg --inline '\require{color}\definecolor{red}{RGB}{255,0,0}\color{red}e^{i \pi} + 1 = 0'

works fine.

Empty SVG files (but no errors)

When trying something like:

./bin/tex2svg 'P(E)= {n \choose k} p^k (1-p)^{ n-k}' > math.svg

I'm getting an empty (zero byte) file math.svg.

Any pointers on how to debug this??

Converting html with Tex and Mathml to SVG : Mathml doesn't get converted

Hi, at work we choose mathjax to convert Latex into human friendly mathematics. Since we need to convert our document in pdf and epub, i decided to give MathJax-node a try.
It's almost good, i just have one problem and that is the fact that currently when i convert a HTML page to SVG, the math ml doesn't get converted.
I'm wondering if i'm doing something wrong or if this is a bug ? Here is the code that seems relevant (so i excluded everything that has to do with file reading and template form sending/reading), the source HTML and the result of the conversion:

Relevant code

preview = true; 
speech = true; 
speechrules = "mathspeak"; 
speechstyle = "default"; 
linebreaks= false; 
nodollars=false;
nofontcache = true;
localcache = true;
format = "AsciiMath,TeX,MathML"; 
eqno = "none"; 
vimg = "";
font = "TeX"; 
ex = 6; 
width = 100; 

function processHTML(html, callback) {
    console.log("processoHtml = "+html)
    fs.unlink('upload/output.html');
    var document = jsdom(html,{features:{FetchExternalResources: false}});
    console.log("afterjsdom")
    var xmlns = getXMLNS(document);
    mjAPI.typeset({
        html: document.body.innerHTML,
        renderer: (vimg == "" ? "SVG" : "IMG"),
        inputs: format,
        equationNumbers: eqno,
        singleDollars: !nodollars,
        useFontCache: !nofontcache,
        useGlobalCache: !localcache,
        addPreview: preview,
        speakText: speech,
        speakRuleset: speechrules.replace(/^chromevox$/i,"default"),
        speakStyle: speechstyle,
        ex: ex,
        width: width,
        linebreaks: linebreaks,
        xmlns:xmlns
    }, function (result) {
        console.log("prcoessHTML 2")
        document.body.innerHTML = result.html;
        document.head.appendChild(document.body.firstChild);
        if (vimg !== "") {
            var img = document.getElementsByClassName("MathJax_SVG_IMG");
            for (var i = 0, m = img.length; i < m; i++) {
                var N = (i+1).toString(); while (N.length < 4) {N = "0"+N}
                var file = vimg+N+".svg";
                var svg = [
                    '<?xml version="1.0" standalone="no"?>',
                    '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',
                    new Buffer(img[i].src.replace(/^.*?,/,""),"base64").toString("utf-8")
                ].join("\n");
                fs.writeFileSync(file,svg);
                img[i].src = file;
            }
        }
        var HTML = "<!DOCTYPE html>\n"+document.documentElement.outerHTML.replace(/^(\n|\s)*/,"");
        callback(HTML);
    });
}

function getXMLNS(document) {
    console.log("get XMLNS")
    var html = document.head.parentNode;
    for (var i = 0, m = html.attributes.length; i < m; i++) {
        console.log("XMLNS iter = " + i);
        var attr = html.attributes[i];
        if (attr.nodeName.substr(0,6) === "xmlns:" &&
            attr.nodeValue === "http://www.w3.org/1998/Math/MathML")
        {return attr.nodeName.substr(6)}
    }
    return "mml";
}

the Source

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
  <head>

  </head>
  <body id="article-127" class="textes article">
//////////////////////////////////////////////////
<math xmlns="http://www.w3.org/1998/Math/MathML">
                      <mrow>
                        <mo lspace="1px" rspace="1px"></mo>
                        <mi>i</mi>
                        <mfrac>
                          <mo rspace="0px"></mo>
                          <mrow>
                            <mo rspace="0px"></mo>
                            <mi>t</mi>
                          </mrow>
                        </mfrac>
                        <msup>
                          <mi>Ψ</mi>
                          <mo></mo>
                        </msup>
                        <mo>=</mo>
                        <mo lspace="1px" rspace="1px"></mo>
                        <mfrac>
                          <msup>
                            <mo lspace="1px" rspace="1px"></mo>
                            <mn>2</mn>
                          </msup>
                          <mrow>
                            <mn>2</mn>
                            <mi>m</mi>
                          </mrow>
                        </mfrac>
                        <msup>
                          <mi>Ψ</mi>
                          <mo></mo>
                        </msup>
                      </mrow>
                    </math>
 /////////////////////////////////////////// 
  </body>
</html>

The Result

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"><head>

  <style id="MathJax_SVG_styles">.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%}
.MathJax_SVG .MJX-monospace {font-family: monospace}
.MathJax_SVG .MJX-sans-serif {font-family: sans-serif}
.MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0}
.MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none}
.mjx-svg-href {fill: blue; stroke: blue}
</style></head>
  <body id="article-127" class="textes article">
//////////////////////////////////////////////////
<span style="font-size: 100%; display: inline-block;" class="MathJax_SVG" id="MathJax-Element-1-Frame" role="math" aria-readonly="true"></span><script type="math/mml" id="MathJax-Element-1"><math xmlns="http://www.w3.org/1998/Math/MathML">
                      <mrow>
                        <mo lspace="1px" rspace="1px"></mo>
                        <mi>i</mi>
                        <mfrac>
                          <mo rspace="0px"></mo>
                          <mrow>
                            <mo rspace="0px"></mo>
                            <mi>t</mi>
                          </mrow>
                        </mfrac>
                        <msup>
                          <mi>Ψ</mi>
                          <mo></mo>
                        </msup>
                        <mo>=</mo>
                        <mo lspace="1px" rspace="1px"></mo>
                        <mfrac>
                          <msup>
                            <mo lspace="1px" rspace="1px"></mo>
                            <mn>2</mn>
                          </msup>
                          <mrow>
                            <mn>2</mn>
                            <mi>m</mi>
                          </mrow>
                        </mfrac>
                        <msup>
                          <mi>Ψ</mi>
                          <mo></mo>
                        </msup>
                      </mrow>
                    </math></script>
 /////////////////////////////////////////// 


</body></html>

Getting started

Hi. I'm trying to get started with MathJax-node and be able to run some simple examples. I want to be able to author files with both SVG and math content, and use MathJax-node to turn them into pure SVG.

I'm running on Windows.

After installing node.js, npm and python 2.7, I was able to run the npm install which completes with just a couple of warnings. Seeing that there were recently some issues resolved with running on Windows, I used git to checkout the 'develop' branch.

However, I'm new to this whole environment and could use a few hints. How do I convert math to SVG? Should I be able to run something like
node tex2svg test-files/sample-tex.html > test.svg

Please could you post at least one command that I should be able to run if set up correctly to generate an output file. This will help me figure out whether I am getting the installation steps right. Thanks.

width input option

I want to convert a math to png/svg with linebreak option, width of the math should be 600px . I don't know how to achieve this.
If I want reduce/increase the font size where I've to mention it?
If you could explain all the options in the README file which helps a lot for all.

Commands and output

  1. node bin/mml2png --linebreaks --width=6000 -- ex=2 '<math></math>' > width600_ex2.png
  2. node bin/mml2png --linebreaks --width=6000 -- ex=20 '<math></math>' > width600_ex20.png
  3. node bin/mml2png --linebreaks --width=1000 -- ex=2 '<math></math>' > width100_ex2.png
  4. node bin/mml2pbg --linebreaks --width=1000 -- ex=20 '<math></math>' > width600_ex20.png

w1k_ex2
w1k_ex20
w6k_ex2
w6k_ex20

`\qquad` and mspace problem

Something like

$$\qquad 1 $$

Produces

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mspace width="2em">
  <mn>1</mn>
</mspace></math>

-- which is invalid.

It doesn't seem a general MathJax problem where I get

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mspace width="2em" />
  <mn>1</mn>
</math>

Cannot restart mathjax between typesets

tl;dr: typeset(), then start(), then typeset() yields the error, "Can't make callback from given data".

Here's a self-contained reproduction.

#! /usr/bin/env node

var fs = require('fs');
var path = require('path');
var jsdom = require('jsdom').jsdom;
var mjAPI = require("../lib/mj-page.js");

var html = "<html><body><div>$x$</div></body></html>";

mjAPI.config({MathJax: {SVG: {font: "TeX"}}});

mjAPI.start();

typeset(html, function(result) {
  console.log("Once!");

  setImmediate(function() {

    // without this line, it works fine, but if we wanted to change the configuration
    // between typesets, we'd need this.
    mjAPI.start();


    typeset(html, function(result) {
      console.log("Twice!");
    })
  })
})


function typeset(html,callback) {
  var document = jsdom(html,null,{features:{FetchExternalResources: false}});
  mjAPI.typeset({
    html: document.body.innerHTML,
    renderer: "SVG",
    inputs: ["AsciiMath", "TeX", "MathML"],
    equationNumbers: "none",
    singleDollars: true,
    useFontCache: false,
    useGlobalCache: false,
    svgPreview: true,
    imgSVG: false,
    speakText: true,
    ex: 6, width: 100,
    linebreaks: true,
    xmlns:'mml'
  }, callback);
}

Feature request: `mjfragment`

It would be nice to have an API for processing content fragments.

Some potential features

Besides keeping the page itself cleaner, this allows for more efficient delivery, especially when processing multiple files (e.g., a statically re-generated site, ebooks) and also improves processing of non-HTML such as markdown files (in particular with YAML front matter).

bug when switching data options

This bug does not appear when only one rendering opption is used. It happens only when we turn off the imgSVG or the imgPNG option.

suppose we set:

data.imgSVG = true

then render. Everything renders fine.

Then if we switch to

data.imgSVG = false

The resetGlyph method gives an error message:

file:///Users/project/node_modules/MathJax-node/mathjax/unpacked/jax/output/SVG/jax.js?rev=2.4-beta-2:388
          GLYPH.defs.innerHTML = "";
                               ^
TypeError: Cannot set property 'innerHTML' of null
    at SVG.Augment.resetGlyphs (file:///Users/project/node_modules/MathJax-node/mathjax/unpacked/jax/output/SVG/jax.js?rev=2.4-beta-2:388:32)
    at StartQueue (/Users/projects/node_modules/MathJax-node/lib/mj-page.js:654:7)
    at Object.exports.typeset (/Users/project/node_modules/MathJax-node/lib/mj-page.js:709:35)
    at /Users/projects/server/mailer/mailerCtrl.js:201:38
    at fn (/Users/project/node_modules/async/lib/async.js:641:34)
    at Object._onImmediate (/Users/project/node_modules/async/lib/async.js:557:34)
    at processImmediate [as _immediateCallback] (timers.js:330:15)

This bug is relatively easy to understand. Might come back to this later.

Cannot get MathJax-node to work in Windows

I successfully got the npm install to work in Windows 7 (which was a nightmare and a half already), but the MathJax-node binaries don't work for me. Using mingw bash (also tested with windows command prompt just in case that helped, but it has the same result).

I run:

$ bin/tex2svg 'x_2'

The result is nothing - i.e. it pauses for about 1-2 seconds then exits and shows the $ prompt again, with no output.

Originally I was using node.js v0.10.something. I've since updated to the latest v0.12.0 (and did a rebuild and update) but with same result.

I tried adding console.log calls in various places in the script (bin/tex2svg). As a result I can confirm that it runs the script from start to finish, but does not run the callback that is supposed to happen when typesetting finishes.

I also have a Linux VM where I also installed MathJax-node the same way and this does work fine, returning SVG code.

Basically wondering if this is just my setup, or if it's known to not work in Windows for some reason. Our production servers are Linux but for development it is sometimes convenient if we can run stuff on Windows also.

/bin/tex2svg execute error

Is the first line, #! /usr/bin/env node --, could be #! /usr/bin/env node?
I'm not familiar with nodejs, and I'm not sure that, but when i delete --, i can get things ok.

Escaping < & in annotation-xml

I wasn't sure if this is an upstream bug but I suspect it is.

Something like

 $ tex2mml --semantics '\begin{align} a < b &  c > d  \end{align}'

will have

 <annotation encoding="application/x-tex">\begin{align} a < b &  c > d  \end{align}</annotation>

That is, &, <, and > are not escaped.

(This leads to validation problems, in particular in XML environments.)

SVG path for SPACE (u0020) is missing attribute `d`

Example:

$ bin/tex2svg "\text{ }"

produces

...
<path stroke-width="10" id="E1-MJMAIN-20"></path>
...

or more precisely

    <?xml version="1.0" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    <svg xmlns:xlink="http://www.w3.org/1999/xlink" style="vertical-align: -0.167ex; margin-left: 0ex; margin-right: 0ex; margin: 1px 0px;" width="0.667ex" height="0.167ex" viewBox="0 -23.9 255 47.9" xmlns="http://www.w3.org/2000/svg">
    <defs>
    <path stroke-width="10" id="E1-MJMAIN-20"></path>
    </defs>
    <g stroke="black" fill="black" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">
    <use xlink:href="#E1-MJMAIN-20"></use>
    </g>
    </svg>

Adding empty attribute d="" should fix this.

This looks like an upstream bug in MathJax.

MathJax 2.5 related thread

Once MathJax v2.5 is finalized, we should

  • update the mathjax-node branch of MathJax core
  • increment MathJax-node version
  • publish MathJax-node to npm

async call to mjAPI results in TypeError crash

Hi,

I got the mjAPI.typset() to work. All is well until I started to run async tests against it.

It looks like if one does:

require('MathJax-node').typeset(data, callback)

if you run two renders at the same time, without the first one finish, you get an error message:

/node_modules/MathJax-node/lib/mj-page.js:442
  if (data.renderer === "None") {content.innerHTML = "<p></p>"}
          ^
TypeError: Cannot read property 'renderer' of null
    at TypesetDone (/node_modules/MathJax-node/lib/mj-page.js:442:11)
    at Function.CALLBACK.execute (file:///node_modules/MathJax-node/mathjax/unpacked/MathJax.js:236:26)
    at cb (file:///node_modules/MathJax-node/mathjax/unpacked/MathJax.js:218:59)
    at BASE.Object.Subclass.Process (file:///node_modules/MathJax-node/mathjax/unpacked/MathJax.js:488:38)
    at BASE.Object.Subclass.call (file:///node_modules/MathJax-node/mathjax/unpacked/MathJax.js:501:37)
    at Function.WAITEXECUTE (file:///node_modules/MathJax-node/mathjax/unpacked/MathJax.js:341:50)
    at cb (file:///node_modules/MathJax-node/mathjax/unpacked/MathJax.js:218:59)
    at BASE.Object.Subclass.Process (file:///node_modules/MathJax-node/mathjax/unpacked/MathJax.js:488:38)
    at BASE.Object.Subclass.call (file:///node_modules/MathJax-node/mathjax/unpacked/MathJax.js:501:37)
    at Function.WAITEXECUTE (file:///node_modules/MathJaxa-node/mathjax/unpacked/MathJax.js:341:50)
npm ERR! weird error 8
npm ERR! not ok code 0

Any thoughts on how to fix this?

Convert multiple inputs

I want to convert a set of file to some output
for example
file1.tex
file2.tex
fileN.tex

to

file1.svg
file1.png
file2.svg
file2.png
fileN.svg
fileN.png

Right now, i run this:
tex2svg 'file1.tex content' > file1.svg
tex2png 'file1.tex content' > file1.png
...
...

But it is not very efficient, because they are many inputs and MathJax is loaded into each execution

Is there any way to do it more efficient?

Rendering issue with `infix` notation

Sample via Benetech

<math xmlns:mml="http://www.w3.org/1998/Math/MathML" mode="display" overflow="scroll">
          <mml:mrow>
            <mml:mfrac>
              <mml:mrow>
                <mml:mi>d</mml:mi>

                <mml:mi>x</mml:mi>
              </mml:mrow>

              <mml:mrow>
                <mml:mi>d</mml:mi>

                <mml:mi>θ</mml:mi>
              </mml:mrow>
            </mml:mfrac>

            <mml:mo>=</mml:mo>

            <mml:mfrac>
              <mml:mi>β</mml:mi>

              <mml:mrow>
                <mml:msup>
                  <mml:mo form="prefix">cos</mml:mo>

                  <mml:mn>2</mml:mn>
                </mml:msup>

                <mml:mi>θ</mml:mi>
              </mml:mrow>
            </mml:mfrac>
          </mml:mrow>
        </mml:math>

Sample Rendering:

unnamed

Since this doesn't happen on in core MathJax, it seems like a mathjax-node bug.

output math as PNG image

Hi @dpvc , @pkra,

Thanks for this great library! What's the configuration to convert svg to png images? I followed the instruction and now have the batik library uncompressed inside the batik folder.

If I pass

data = {
    renderer: 'png',
    html: '<p>some html ....</p>'

MathJax-node gives me an error message:
file failed to load: file:///project_folder/node_modules/MathJax-node/mathjax/unpacked/jax/output/png/config.js

Thanks!

invalid XML output

For the input ${\displaystyle $math}$ rendered in inline-TeX mode (e.g.
curl -d 'type=inline-TeX&q=%7B%5Cdisplaystyle%20E%3Dmc%5E2%7D' localhost:10042
) the generated xml output is invalid because it contains a two times the same xml attribute display
We fixed that in mathoid in
https://gerrit.wikimedia.org/r/#/c/165946/1/mathoid-worker.js
but it would be great if that coud be fixed within mathjax-node as well.

Progress notification callback

For large documents with lots of math, this api appears distinctly slower than in the browser. (I haven't profiled, but I'm guessing it's due to jsdom...)

This probably isn't a big problem, since this api likely isn't being used to render math on a page while it's being read. However, I'd find it useful to get percentage-complete callbacks.

The approach described here would work, except that there isn't currently a way to touch MathJax.Hub from outside the API.

Would it make sense to add as a config option an onInitComplete() callback, which could be called at the end of AuthorInit()? This could serve as an analogue to the ability in the browser to have arbitrary mathjax configuration code.

Isolate speech output

Currently, speech output is part of the SVG generation but we need it in MathML and PNG output as well. We should keep it separated for re-use.

displaystyle mathml

We tried to merge
dpvc/MathJax@98e3f09
to support displaystyle mathml
however our example {\displaystyle {\text{geometric series:}}\quad {\begin{aligned}\sum _{{i=0}}^{\infty }2^{{-i}}=2\end{aligned}}} does not seem to work in normal TeX mode.
In case of interest our exactract post data submitted to the mathoid server:
type=tex&q=%7B%5Cdisplaystyle%20%7B%5Ctext%7Bgeometric%20series%3A%7D%7D%5Cquad%20%7B%5Cbegin%7Baligned%7D%5Csum%20_%7B%7Bi%3D0%7D%7D%5E%7B%5Cinfty%20%7D2%5E%7B%7B-i%7D%7D%3D2%5Cend%7Baligned%7D%7D%7D
Is there an example that is fixed by
dpvc/MathJax@98e3f09
so that we can test if we merged the fix successsful.

unset useFontCache by default ?

When I run

./bin/page2svg < test-files/sample-tex.html > test.html

The resulting file has no visible equations either on Firefox (31.0) or Chrome (36.0). After some tweaking, setting useFontCache to false fixes the issue.

Unless this is a local issue (thought i doubt it) which shoud be investigated, I think it would be sensible to set it to false by default.

singleton module prevents simultaneous multiple configurations

The problem: there's important module-scoped variables in mj-page, making it a singleton. This makes it awkward to have multiple configurations going in the same program. And actually, because of #36, there's no clear workaround. Conversely, changing this would basically remove the need for restarting MathJax, which is what 36 is about.

Two use cases for why it would be good to have the API be "instanceable":

  1. A prerender server that takes the output format as a query parameter. (I'm working on one now, in fact.)
  2. Testing: running the API (or something that depends on it) through multiple tests is currently problematic.

I'm advocating for something like:

var mathjaxnode = require('MathJax-node');

var api1 = mathjaxnode(config1);
var api2 = mathjaxnode(config2);

Where config1 and config2 are configuration objects in the form currently expected by config().

Happy to work up a PR for this if the maintainers are in support.

npm: mathjax dependency fails due to #node-package

npm install https://github.com/mathjax/MathJax-node/tarball/master gives me:

npm ERR! Failed resolving git HEAD (git://github.com/dpvc/MathJax.git) fatal: ambiguous argument 'node-package': unknown revision or path not in the working tree.
npm ERR! Failed resolving git HEAD (git://github.com/dpvc/MathJax.git) Use '--' to separate paths from revisions, like this:
npm ERR! Failed resolving git HEAD (git://github.com/dpvc/MathJax.git) 'git <command> [<revision>...] -- [<file>...]'
npm ERR! Failed resolving git HEAD (git://github.com/dpvc/MathJax.git) 
npm ERR! Darwin 13.4.0
npm ERR! argv "/Users/anand/.nvm/v0.11.14/bin/node" "/Users/anand/.nvm/v0.11.14/bin/npm" "install"
npm ERR! node v0.11.14
npm ERR! npm  v2.0.0
npm ERR! code 128

npm ERR! Command failed: git rev-list -n1 node-package
npm ERR! fatal: ambiguous argument 'node-package': unknown revision or path not in the working tree.
npm ERR! Use '--' to separate paths from revisions, like this:
npm ERR! 'git <command> [<revision>...] -- [<file>...]'

And I don't see a node-package tag or branch in dpvc/MathJax.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.