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