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