1//===============================================================================
  2//
  3// load-mathjax.js
  4//
  5// Script for configuring and loading MathJax in my web pages.  See instructions
  6// for "Configuring and Loading in One Script",
  7//
  8//     https://docs.mathjax.org/en/latest/web/configuration.html
  9//
 10// and for hosting your own copy of MathJax on your server, 
 11//
 12//     https://docs.mathjax.org/en/latest/web/hosting.html
 13//
 14// Put this command in the <head> section of your html before loading the style sheet:
 15//
 16//     <script src="../Scripts/load-mathjax.js" async></script>
 17//
 18//===============================================================================
 19
 20// The variable "window" is the current web page URL, including the #section location.
 21
 22// Configure MathJax before you load it.  
 23// The documented settings are described in
 24//     https://docs.mathjax.org/en/stable/options/HTML-CSS.html
 25window.MathJax =
 26{
 27  // Set both the default math delimiters \(...\) and the ones I prefer:  $ and $$.
 28  tex: 
 29  {
 30    inlineMath: [['$', '$'], ['\\(', '\\)']]
 31  },
 32
 33  // Make the font larger.  This did not work for me, so I hacked a solution in my StyleSheet.css.
 34  "HTML-CSS":
 35  {
 36      scale: 400,
 37      minScaleAdjust: 200,
 38  },
 39
 40  svg: 
 41  {
 42    fontCache: 'global'
 43  },
 44} ;
 45
 46// Next, load MathJax.
 47// See the configuration documeent,
 48//     https://docs.mathjax.org/en/latest/web/configuration.html
 49// -On my development machines and on my web server, load a local copy of MathJax.
 50// -Otherwise load from the MathJax CDN server.
 51(function()  // Define a function and call it immediately.
 52{
 53    // Create a <script>...</script> html object.
 54    var script = document.createElement( 'script' ) ;
 55
 56    // The file:/// protocol says the web site is hosted on the current machine's file system.
 57    if (window.location.protocol.match( /file:/ ))
 58    {
 59        // Hosted on my macOS development computer.
 60        if (window.location.pathname.match( /Users\/seanoconnor/ ))
 61        {
 62            // Use a local copy of MathJax.  I downloaded MathJax as follows:
 63            //     cd WebSite
 64            //     git clone https://github.com/mathjax/MathJax.git mathjax
 65            //     cd mathjax
 66            //     git fetch --all --tag --prune
 67            //     git remote -vv
 68            //         origin	https://github.com/mathjax/MathJax.git (fetch)
 69            //         origin	https://github.com/mathjax/MathJax.git (push)
 70            //
 71            // You should be in the master branch by default,
 72            //     git branch
 73            //         * master
 74            //
 75            // Pull to get the latest updates
 76            //     git pull
 77            //
 78            // You can see which tags are available using
 79            //     git tag
 80            //        ...
 81            //        3.1.4
 82            //        3.2.0
 83            //
 84            // For local testing of MathJax versions, you can fetch a particular version,
 85            //     git checkout tags/3.2.0 -b v3.2.0
 86            //     git branch
 87            //         master
 88            //         v3.1.4
 89            //       * v3.2.0
 90            //
 91            // NOTE:
 92            // If you want to host MathJax files on your own server, you only need to upload the mathjax/es5 directory.  
 93            //
 94            script.src="/Users/seanoconnor/Desktop/Sean/WebSite/mathjax/es5/tex-chtml.js";
 95
 96            // To see this message in Firefox, open Tools->Browser Tools -> Web Developer Tools then select Console and Logs.
 97            console.log( "Mac OS:  Prepare to load MathJax from local directory location " + script.src ) ;
 98        }
 99        // Hosted on my Ubuntu Linux development computer.
100        else if (window.location.pathname.match( /home\/seanoconnor/ ))
101        {
102            script.src="/home/seanoconnor/Desktop/Sean/WebSite/mathjax/es5/tex-chtml.js";
103
104            // In Firefox, open Tools->Web Developer->Web Console to see this message:
105            console.log( "Ubuntu Linux:  Prepare to load MathJax from local directory location " + script.src ) ;
106        }
107        // Can't figure it out?  Load from CDN MathJax server.
108        else
109        {
110            // This recommended URL will load the latest version 3.x.x from the default CDN MathJax server.
111            script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js' ;
112            console.log( "Unknown Computer:  Prepare to load MathJax from CDN server location " + script.src ) ;
113        }
114    }
115    // Hosted on my web server.
116    else if (window.location.hostname.match( /seanerikoconnor.freeservers.com/ ))
117    {
118        // Load from a local copy of MathJax on my web server.
119        script.src="/mathjax/es5/tex-chtml.js";
120        console.log( "Freeservers Web Host:  Prepare to load MathJax from local directory location " + script.src ) ;
121    }
122    // Hosted on some other web server.
123    else
124    {
125        // This recommended URL will load the latest version 3.x.x from the default CDN MathJax server.
126        script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js' ;
127        console.log( "Unknown Web Host:  Prepare to load MathJax from CDN server location " + script.src ) ;
128    }
129
130    script.async = true ;
131  
132    // Place the generated MathJax configuration and loading script into the html 
133    // file in the <head>...</head> section.
134    document.head.appendChild( script ) ;
135    console.log( "Loading MathJax into HTML document inside newly created <script> ... </script>" ) ;
136
137})();