title: MathJax-node to generate SVG output for inline TeX
body: <p>Trying to convert simple inline equation into SVG isn't working and stops execution at the first occurrence of $.</p>
  
  <p>Inline equation: </p>
  
  <pre><code>When $a \ne 0$, there are two solutions to $(ax^2 + bx + c = 0)$ and they are $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
  </code></pre>
  
  <p>Code to convert the above inline-TeX to SVG:</p>
  
  <pre><code>var mjAPI = require("MathJax-node/lib/mj-single.js");
  var fs = require('fs');
  
  mjAPI.config({
      MathJax : {
          SVG : {
              scale: 120,
              font : "STIX-Web",
              linebreaks: { automatic: true },
              tex2jax: { inlineMath: [['$','$'], ['\\(','\\)']] }
          }
      },
      displayErrors : true,
      displayMessages : false
  });
  
  mjAPI.start();
  
  fs.readFile(process.argv[2], 'utf8', function (err, formula) {
      if (err) {
          return console.log(err);
      }
  
      mjAPI.typeset({
          math : formula,
          format : "inline-TeX",
          svg : true,
          width: 1,
          linebreaks: true
      }, function (results) {
          if (!results.errors) {
              console.log(results.svg)
          }
      });
  });
  </code></pre>
  
  <p>Output:</p>
  
  <p>Just prints <em>When</em> in svg.</p>
  
  <p>Edited...</p>
  
  <p>With Help of Peter Krautzberger (see his comments below), I was able to get the SVG export to work. Here is the code.</p>
  
  <pre><code>var mjAPI = require("mathjax-node/lib/mj-page.js");
  var jsdom = require("jsdom").jsdom;
  
  var document = jsdom("When $a \\ne 0$, there are two solutions to $(ax^2 + bx + c = 0)$ and they are $x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$");
  
  mjAPI.start();
  
  mjAPI.typeset({
    html: document.body.innerHTML,
    renderer: "SVG",
    inputs: ["TeX"]
  }, function(result) {
    "use strict";
    document.body.innerHTML = result.html;
    var HTML = document.documentElement.outerHTML.replace(/^(\n|\s)*/, "");
    console.log(result.html);
  });
  </code></pre>