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 // Configure MathJax before you load it.  Set the default math delimiters \(...\)
 21 // and also the $ and $$ delimiters which I use.
 22 window.MathJax =
 23 {
 24   tex:
 25   {
 26     inlineMath: [['$', '$'], ['\\(', '\\)']]
 27   },
 28 
 29   svg:
 30   {
 31     fontCache: 'global'
 32   },
 33 } ;
 34 
 35 // Next, load MathJax.
 36 //     -On my development machines and on my web server, load a local copy of MathJax.
 37 //     -Otherwise load from the MathJax CDN server.
 38 (function()  // Define a function and call it immediately.
 39 {
 40     // Create a <script>...</script> html object.
 41     var script = document.createElement( 'script' ) ;
 42 
 43     // The file:/// protocol says the web site is hosted on the current machine's file system.
 44     if (window.location.protocol.match( /file:/ ))
 45     {
 46         // Hosted on my macOS development computer.
 47         if (window.location.pathname.match( /Users\/seanoconnor/ ))
 48         {
 49             // Use a local copy of MathJax.  I downloaded MathJax as follows:
 50             //     cd WebSite
 51             //     git clone https://github.com/mathjax/MathJax.git mathjax
 52             //     cd mathjax
 53             //     git fetch --all --tag --prune
 54             //     git remote -vv
 55             //         origin   https://github.com/mathjax/MathJax.git (fetch)
 56             //         origin   https://github.com/mathjax/MathJax.git (push)
 57             //
 58             // You should be in the master branch by default,
 59             //     git branch
 60             //         * master
 61             //
 62             // Pull to get the latest updates
 63             //     git pull
 64             //
 65             // You can see which tags are available using
 66             //     git tag
 67             //        ...
 68             //        3.1.4
 69             //        3.2.0
 70             //
 71             // For local testing of MathJax versions, you can fetch a particular version,
 72             //     git checkout tags/3.2.0 -b v3.2.0
 73             //     git branch
 74             //         master
 75             //         v3.1.4
 76             //       * v3.2.0
 77             //
 78             // NOTE:
 79             // If you want to host MathJax files on your own server, you only need to upload the mathjax/es5 directory.  
 80             //
 81             script.src="/Users/seanoconnor/Desktop/Sean/WebSite/mathjax/es5/tex-chtml.js";
 82 
 83             // In Firefox, open Tools->Web Developer->Web Console to see this message:
 84             console.log( "Mac OS:  Loading MathJax from local directory location " + script.src ) ;
 85         }
 86         // Hosted on my Ubuntu Linux development computer.
 87         else if (window.location.pathname.match( /home\/seanoconnor/ ))
 88         {
 89             script.src="/home/seanoconnor/Desktop/Sean/WebSite/mathjax/es5/tex-chtml.js";
 90 
 91             // In Firefox, open Tools->Web Developer->Web Console to see this message:
 92             console.log( "Ubuntu Linux:  Loading MathJax from local directory location " + script.src ) ;
 93         }
 94         // Can't figure it out?  Load from CDN MathJax server.
 95         else
 96         {
 97             // This recommended URL will load the latest version 3.x.x from the default CDN MathJax server.
 98             script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js' ;
 99             console.log( "Unknown Computer:  Loading MathJax from CDN server location " + script.src ) ;
100         }
101     }
102     // Hosted on my web server.
103     else if (window.location.hostname.match( /seanerikoconnor.freeservers.com/ ))
104     {
105         // Load from a local copy of MathJax on my web server.
106         script.src="/mathjax/es5/tex-chtml.js";
107         console.log( "Freeservers Web Host:  Loading MathJax from local directory location " + script.src ) ;
108     }
109     // Hosted on some other web server.
110     else
111     {
112         // This recommended URL will load the latest version 3.x.x from the default CDN MathJax server.
113         script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js' ;
114         console.log( "Unknown Web Host:  Loading MathJax from CDN server location " + script.src ) ;
115     }
116 
117     script.async = true ;
118 
119     // Place the generated MathJax configuration and loading script into the html 
120     // file in the <head>...</head> section.
121     document.head.appendChild( script ) ;
122 
123 })();