Search code examples
htmlmathjax

Backup Mathjax Source


I recently downloaded a copy of MathJax because I like math and programming (and I sometimes program offline).

The MathJax website (mathjax.com) says you can either use their copy of MathJax or download a local copy. My question is, is there a way to use the copy of MathJax at mathjax.com, and if that is not available, use my local copy? For example, if other people want to see the webpage and they don't have a local copy of MathJax, the HTML file can direct them to the copy of MathJax at mathjax.com, and if I am working without Internet, the HTML file can use my local copy.

As something related, the HTML/CSS font property can have a backup font; if a particular font is not available, it can drop to the next font available, and so on.

Here is my code:

<!DOCTYPE html>
<html>
    <head>
        <title>Math Template</title>
        <meta charset=UTF-8>
        <script type="text/x-mathjax-config">
            MathJax.Hub.Config({
                extensions: ["tex2jax.js"],
                jax: ["input/TeX","output/HTML-CSS"],
                tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
            });
        </script>
        <script type="text/javascript"  src="C:/MathJax/MathJax.js?config=TeX-MML-AM_CHTML></script>
    </head>
    <body>
    <p>$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$</p>
    </body>
</html>

If there is any bad practices in the code, please tell me.

Thanks,

The Turtle 🐢


Solution

  • This snippet from the MathJax docs Wiki might help you.

    A simple script to fallback to a local copy of MathJax if the CDN is offline (e.g., when you don't have a network connection).

    <!-- MathJax: Fall back to local if CDN offline -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script>
    <script>window.MathJax || document.write('<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS":{imageFont:null}});<\/script><script src="<<PATH_TO_YOUR_LOCAL_MATHJAX>>MathJax.js?config=TeX-AMS_HTML-full"><\/script>')</script>
    

    For convenience, the configuration for the fallback deactivates image fonts support (imageFont:null). This allows you to host a slim local copy by deleting the PNG fonts.