Coder Social home page Coder Social logo

mathjax-node's Introduction

mathjax-node Build Status

This repository contains a library that provides an API to call MathJax from Node.js programs. The API converts individual math expressions (in any of MathJax's input formats) into HTML (with CSS), SVG, or MathML code.

Use

npm install mathjax-node

to install mathjax-node and its dependencies.

Note: The current version of mathjax-node requires Node.js v6 or later, and uses jsdom version 11.

Getting started

mathjax-node provides a library, ./lib/main.js. Below is a very minimal example for using it - the tests and the examples mentioned above provide more advanced examples.

// a simple TeX-input example
var mjAPI = require("mathjax-node");
mjAPI.config({
  MathJax: {
    // traditional MathJax configuration
  }
});
mjAPI.start();

var yourMath = 'E = mc^2';

mjAPI.typeset({
  math: yourMath,
  format: "TeX", // or "inline-TeX", "MathML"
  mml:true,      // or svg:true, or html:true
}, function (data) {
  if (!data.errors) {console.log(data.mml)}
  // will produce:
  // <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  //   <mi>E</mi>
  //   <mo>=</mo>
  //   <mi>m</mi>
  //   <msup>
  //     <mi>c</mi>
  //     <mn>2</mn>
  //   </msup>
  // </math>
});

Documentation

mathjax-node exports three methods, config, start, typeset.

config(options)

The config method is used to set global configuration options. Its default options are

{
  displayMessages: false,    // determines whether Message.Set() calls are logged
  displayErrors:   true,     // determines whether error messages are shown on the console
  undefinedCharError: false, // determines whether "unknown characters" (i.e., no glyph in the configured fonts) are saved in the error array
  extensions: '',            // a convenience option to add MathJax extensions
  fontURL: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/fonts/HTML-CSS', // for webfont urls in the CSS for HTML output
  paths: {},                  // configures custom path variables (e.g., for third party extensions, cf. test/config-third-party-extensions.js)
  MathJax: { }               // standard MathJax configuration options, see https://docs.mathjax.org for more detail.
}

Note. Changes to these options require a restart of the API using the start() method (see below).

start()

The start method start (and restarts) mathjax-node. This allows reconfiguration.

Note. This is done automatically when typeset is first called (see below).

typeset(options[, callback])

The typeset method is the main method of mathjax-node. It expects a configuration object options and optionally a callback.

If no callback is passed, it will return a Promise.

Once called, typeset can be called repeatedly and will optionally store information across calls (see state below).

The following are the default input options.

{
  ex: 6,                          // ex-size in pixels
  width: 100,                     // width of container (in ex) for linebreaking and tags
  useFontCache: true,             // use <defs> and <use> in svg output?
  useGlobalCache: false,          // use common <defs> for all equations?
  linebreaks: false,              // automatic linebreaking
  equationNumbers: "none",        // automatic equation numbering ("none", "AMS" or "all")
  cjkCharWidth: 13,               // width of CJK character

  math: "",                       // the math string to typeset
  format: "TeX",                  // the input format (TeX, inline-TeX, AsciiMath, or MathML)
  xmlns: "mml",                   // the namespace to use for MathML

  html: false,                    // generate HTML output
  htmlNode: false,                // generate HTML output as jsdom node
  css: false,                     // generate CSS for HTML output
  mml: false,                     // generate MathML output
  mmlNode: false,                 // generate MathML output as jsdom node
  svg: false,                     // generate SVG output
  svgNode: false,                 // generate SVG output as jsdom node

  speakText: true,                // add textual alternative (for TeX/asciimath the input string, for MathML a dummy string)

  state: {},                      // an object to store information from multiple calls (e.g., <defs> if useGlobalCache, counter for equation numbering if equationNumbers ar )
  timeout: 10 * 1000,             // 10 second timeout before restarting MathJax
}

Promise.resolve(result,options) / Promise.reject(errors) / callback(result, options)

mathjax-node returns two objects to Promise.resolve or callback: a result object and the original input options.

The result object will contain (at most) the following structure:

{
  errors:                     // an array of MathJax error messages if any errors occurred
  mml:                        // a string of MathML markup if requested
  mmlNode:                    // a jsdom node of MathML markup if requested
  html:                       // a string of HTML markup if requested
  htmlNode:                   // a jsdom node of HTML markup if requested
  css:                        // a string of CSS if HTML was requested
  svg:                        // a string of SVG markup if requested
  svgNode:                    // a jsdom node of SVG markup if requested
  style:                      // a string of CSS inline style if SVG requested
  height:                     // a string containing the height of the SVG output if SVG was requested
  width:                      // a string containing the width of the SVG output if SVG was requested
  speakText:                  // a string of speech text if requested

  state: {                    // the state object (if useGlobalCache or equationNumbers is set)
           glyphs:            // a collection of glyph data
           defs :             // a string containing SVG def elements
           AMS: {
                startNumber:  // the current starting equation number
                labels:       // the set of labels
                IDs:          // IDs used in previous equations
             }
         }
}

If the errors array is non-empty, the Promise will reject, and be passed the errors array.

The options contains the configuration object passed to typeset; this can be useful for passing other data along or for identifying which typeset() call is associated with this (callback) call (in case you use the same callback function for more than one typeset()).

Change History

Breaking Changes in v2.0:

mathjax-node v2.0 makes breaking changes as follows:

  • [CHANGED] mathjax-node now requires version 6 of Node.js (the minimum used to be Node.js version 4).
  • [CHANGED] mathjax-node now uses version 10 of jsdom. Since the jsdom API changed from 9 to 10, that means if you used jsdom in your code that calls mathjax-node, you may need to update how you call jsdom.

Breaking Changes in v1.0:

mathjax-node v1.0 makes breaking changes to the following features from the pre-releases.

  • [CHANGED] lib/mj-single.js has been renamed to lib/main.js (and set as main in package.json, i.e., require('mathjax-node') will load it.
  • [REMOVED] lib/mj-page.js (API for processing HTML-fragments) and related CLI tools
  • [REMOVED] speech-rule-engine integration
  • [REMOVED] PNG generation
  • [REMOVED] CLI tools in bin/

These features can easily be recreated in separate modules for greater flexibility. For examples, see


Be sure to also check out other projects on NPM that depend on mathjax-node.

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

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

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.

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

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?

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.

`\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>

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??

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.

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.

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!

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.

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

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.

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?

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.

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.

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

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>

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.

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

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.

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.

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?

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.

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?

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.

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

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.

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.