title: displaying latex math equations in web browser using mathjax and node.js
body: <p>I'm trying to download node.js Mathjax library and run example provide on GitHub page:  <a href="https://github.com/mathjax/MathJax-node" rel="nofollow noreferrer">https://github.com/mathjax/MathJax-node</a></p>
  <p>The steps I've followed:</p>
  <p><strong>Step 1:</strong> mkdir mydemo</p>
  <p><strong>Step 2:</strong> cd mydemo</p>
  <p><strong>Step 3:</strong> npm install mathjax-node</p>
  <p><strong>Step 4:</strong> Scrap example javascript code from GitHub website</p>
  <pre><code>// I place this in file &quot;.\lib\main.js
  // a simple TeX-input example
  var mjAPI = require(&quot;mathjax-node&quot;);
  mjAPI.config({
    MathJax: {
      // traditional MathJax configuration
    }
  });
  mjAPI.start();
  
  var yourMath = 'E = mc^2';
  
  mjAPI.typeset({
    math: yourMath,
    format: &quot;TeX&quot;, // or &quot;inline-TeX&quot;, &quot;MathML&quot;
    mml:true,      // or svg:true, or html:true
  }, function (data) {
    if (!data.errors) {console.log(data.mml)}
  });
  </code></pre>
  <p><strong>Step 5:</strong> I setup &quot;.\index.html&quot; to load Javascript demo code for mathjax.</p>
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script src=&quot;./lib/main.js&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;&lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p><strong>Step 6:</strong> I load index.html into chrome web browser.  nothing happens. :-(</p>
  <p>Granted, my knowledge of javascript and node.js kind of sucks.  But, what did I do wrong?  why cant I see mathjax typesetting of &quot;e=mc^2&quot; in web browser window?</p>
  <p><strong>UPDATE</strong></p>
  <p>Ok, I stand corrected.  It works from the command line as follows:</p>
  <pre><code>C:\mydemo&gt; node .\lib\main.js
  
  &lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot; alttext=&quot;E = mc^2&quot;&gt;
    &lt;mi&gt;E&lt;/mi&gt;
    &lt;mo&gt;=&lt;/mo&gt;
    &lt;mi&gt;m&lt;/mi&gt;
    &lt;msup&gt;
      &lt;mi&gt;c&lt;/mi&gt;
      &lt;mn&gt;2&lt;/mn&gt;
    &lt;/msup&gt;
  &lt;/math&gt;
  </code></pre>
  <p>My Question is how to get this javascript setup to display in a web browser as a web application that I can put on my website? instead of running it from Windows command line using &quot;node&quot; command?</p>
  <p>Then there's the other problem if I scrap the mathml code generated by the node script into an html document, it still doesn't use the correct type setting to display the &quot;e=mc^2&quot;.  example:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
      &lt;body&gt;
      
      &lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot; alttext=&quot;E = mc^2&quot;&gt;
    &lt;mi&gt;E&lt;/mi&gt;
    &lt;mo&gt;=&lt;/mo&gt;
    &lt;mi&gt;m&lt;/mi&gt;
    &lt;msup&gt;
      &lt;mi&gt;c&lt;/mi&gt;
      &lt;mn&gt;2&lt;/mn&gt;
    &lt;/msup&gt;
  &lt;/math&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/SD0TH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SD0TH.png" alt="enter image description here" /></a></p>
  <p>See the formatting is ugly... it didn't even turn the &quot;2&quot; into a superscript or other latex-nice typesetting...</p>