Search code examples
javascripthtmlhttpmathjax

MathJax and Server


Is it really necessary to serve my html through a HTTP server for mathjax to work?

I used these:

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=config=TeX-AMS-MML_HTMLorMML"></script>
...
...
...
...<div>\( A \over B^3 \)
...
...

There are no errors on the console, but I cannot seem to render the above equation.

Do I need to serve the HTML through an HTTP Server?


Solution

  • You are not using proper link to the latest version of the library:

    <!DOCTYPE html>
    <html>
    <head>
    <title>MathJax TeX Test Page</title>
    <script type="text/javascript"
      src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>
    </head>
    <body>
    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}.$$
    </body>
    </html>

    Use HTTPS

    In this example, you can see that I am using HTTPS URL: https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML while you were using https://cdn.mathjax.org/....

    The reason why you should prefer HTTPS is because MathJax is using some script to convert your Latex into SVG, it is just safer to download these scripts from a reliable source. Also, Javascript REPLs like JSFiddle, will not let you reference libraries through HTTP!