Search code examples
mathjax

MathJax download cannot load in a local web page


I downloaded the latest copy of MathJax through Git, installed it somewhere, and wrote the following document:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Notes - Wenke's Patterns in Prehistory</title>
    <script id="MathJax-script" async src="../../../../MathJax/e5/tex-chtml.js">
    </script>
  </head>
  <body>
    $ e^i $
  </body>
</html>

When I try to run it in a browser the console prints the message Loading failed for the <script> with source “file:///home/username/underconstruction/MathJax/e5/tex-chtml.js”..

I believe the README.md file that comes with the download indicated that tex-chtml.js was supposed to be the file to link in the HTML document. I've seen elsewhere reference to a MathJax.js file but that was not included in my download.


Solution

  • You specify the location ("../..") of the file "tex-chtml.js" relative to the location of the HTML-page containing $e^i$. The file is likely not there as the warning message indicates. If you specify a path relative to the current HTML-page be also sure that the relative path is the same on your localhost and on the server.

    A simple method for using MathJax is given on https://www.mathjax.org. You do not need to download MathJax from anywhere. Just include the following lines in your HTML-file:

    <head>    
      <script>
        MathJax = {tex: {inlineMath: [['$', '$'], ['\\(', '\\)']]}};
      </script> 
      <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
      <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    </head>