|
50 | 50 | if (window.MathJax && window.MathJax.tex) return; |
51 | 51 | window.MathJax = { |
52 | 52 | tex: { |
53 | | - inlineMath: [['$','$'], ['\\(','\\)']], |
54 | | - displayMath: [['$$','$$'], ['\\[','\\]']], |
| 53 | + inlineMath: [ |
| 54 | + ["$", "$"], |
| 55 | + ["\\(", "\\)"], |
| 56 | + ], |
| 57 | + displayMath: [ |
| 58 | + ["$$", "$$"], |
| 59 | + ["\\[", "\\]"], |
| 60 | + ], |
55 | 61 | processEscapes: true, |
56 | | - processEnvironments: true |
| 62 | + processEnvironments: true, |
57 | 63 | }, |
58 | 64 | options: { |
59 | 65 | // avoid processing inside <pre> / <code> etc. |
60 | | - skipHtmlTags: ['script','noscript','style','textarea','pre'] |
61 | | - } |
| 66 | + skipHtmlTags: ["script", "noscript", "style", "textarea", "pre"], |
| 67 | + }, |
62 | 68 | }; |
63 | 69 | } catch (e) { |
64 | 70 | /* ignore */ |
|
69 | 75 | function loadMathJax() { |
70 | 76 | try { |
71 | 77 | // If MathJax v3 already present, typeset now |
72 | | - if (window.MathJax && typeof window.MathJax.typesetPromise === 'function') { |
73 | | - window.MathJax.typesetPromise().catch(function(){/*ignore*/}); |
| 78 | + if ( |
| 79 | + window.MathJax && |
| 80 | + typeof window.MathJax.typesetPromise === "function" |
| 81 | + ) { |
| 82 | + window.MathJax.typesetPromise().catch(function () { |
| 83 | + /*ignore*/ |
| 84 | + }); |
74 | 85 | // ensure math rendered (fallback if needed) |
75 | 86 | ensureMathRendered(); |
76 | 87 | return; |
77 | 88 | } |
78 | 89 | // If MathJax v2 present, request a typeset using v2 API and return |
79 | | - if (window.MathJax && window.MathJax.Hub && typeof window.MathJax.Hub.Queue === 'function') { |
| 90 | + if ( |
| 91 | + window.MathJax && |
| 92 | + window.MathJax.Hub && |
| 93 | + typeof window.MathJax.Hub.Queue === "function" |
| 94 | + ) { |
80 | 95 | window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub]); |
81 | 96 | // ensure math rendered (fallback if needed) |
82 | 97 | ensureMathRendered(); |
|
90 | 105 |
|
91 | 106 | function onLoad() { |
92 | 107 | try { |
93 | | - if (window.MathJax && typeof window.MathJax.typesetPromise === "function") { |
94 | | - window.MathJax.typesetPromise().catch(function(){/*ignore*/}).then(function(){ ensureMathRendered(); }); |
95 | | - } else if (window.MathJax && window.MathJax.Hub && typeof window.MathJax.Hub.Queue === "function") { |
| 108 | + if ( |
| 109 | + window.MathJax && |
| 110 | + typeof window.MathJax.typesetPromise === "function" |
| 111 | + ) { |
| 112 | + window.MathJax.typesetPromise() |
| 113 | + .catch(function () { |
| 114 | + /*ignore*/ |
| 115 | + }) |
| 116 | + .then(function () { |
| 117 | + ensureMathRendered(); |
| 118 | + }); |
| 119 | + } else if ( |
| 120 | + window.MathJax && |
| 121 | + window.MathJax.Hub && |
| 122 | + typeof window.MathJax.Hub.Queue === "function" |
| 123 | + ) { |
96 | 124 | window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub]); |
97 | 125 | // small delay then check |
98 | 126 | setTimeout(ensureMathRendered, 50); |
99 | 127 | } else { |
100 | 128 | // in case MathJax not available, still try fallback after short delay |
101 | 129 | setTimeout(ensureMathRendered, 50); |
102 | 130 | } |
103 | | - } catch (_) { /* ignore */ } |
| 131 | + } catch (_) { |
| 132 | + /* ignore */ |
| 133 | + } |
104 | 134 | } |
105 | 135 |
|
106 | 136 | // Try CDN first (avoids file:/// resolution of sub-resources), fall back to local if CDN fails. |
107 | | - createAndAppendScript(cdn, { crossorigin: "anonymous" }, onLoad, function () { |
108 | | - // CDN failed -> try local copy |
109 | | - createAndAppendScript(local, null, onLoad); |
110 | | - }); |
| 137 | + createAndAppendScript( |
| 138 | + cdn, |
| 139 | + { crossorigin: "anonymous" }, |
| 140 | + onLoad, |
| 141 | + function () { |
| 142 | + // CDN failed -> try local copy |
| 143 | + createAndAppendScript(local, null, onLoad); |
| 144 | + }, |
| 145 | + ); |
111 | 146 | } catch (e) { |
112 | 147 | /* ignore */ |
113 | 148 | } |
|
118 | 153 | function ensureMathRendered() { |
119 | 154 | try { |
120 | 155 | // If MathJax v3 present, typeset now and return |
121 | | - if (window.MathJax && typeof window.MathJax.typesetPromise === "function") { |
| 156 | + if ( |
| 157 | + window.MathJax && |
| 158 | + typeof window.MathJax.typesetPromise === "function" |
| 159 | + ) { |
122 | 160 | // typesetPromise will render math in the page; call it anyway |
123 | | - window.MathJax.typesetPromise().catch(function(){/*ignore*/}); |
| 161 | + window.MathJax.typesetPromise().catch(function () { |
| 162 | + /*ignore*/ |
| 163 | + }); |
124 | 164 | return; |
125 | 165 | } |
126 | 166 | // If MathJax v2 present, queue a typeset |
127 | | - if (window.MathJax && window.MathJax.Hub && typeof window.MathJax.Hub.Queue === "function") { |
| 167 | + if ( |
| 168 | + window.MathJax && |
| 169 | + window.MathJax.Hub && |
| 170 | + typeof window.MathJax.Hub.Queue === "function" |
| 171 | + ) { |
128 | 172 | window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub]); |
129 | 173 | return; |
130 | 174 | } |
131 | 175 |
|
132 | 176 | // No MathJax available yet: still attempt to convert <script type="math/tex"> to $$...$$ |
133 | | - var scripts = Array.prototype.slice.call(document.querySelectorAll('script[type^="math/tex"]')); |
| 177 | + var scripts = Array.prototype.slice.call( |
| 178 | + document.querySelectorAll('script[type^="math/tex"]'), |
| 179 | + ); |
134 | 180 | if (!scripts || scripts.length === 0) return; |
135 | 181 | var replaced = false; |
136 | 182 | scripts.forEach(function (s) { |
137 | 183 | try { |
138 | 184 | // skip if already replaced |
139 | | - if (s.getAttribute && s.getAttribute("data-math-processed") === "1") return; |
| 185 | + if (s.getAttribute && s.getAttribute("data-math-processed") === "1") |
| 186 | + return; |
140 | 187 | var tex = s.textContent || s.innerText || ""; |
141 | 188 | if (!tex) return; |
142 | 189 | var span = document.createElement("span"); |
143 | 190 | // display-mode math: use $$...$$ |
144 | 191 | span.textContent = "$$" + tex + "$$"; |
145 | 192 | s.parentNode.replaceChild(span, s); |
146 | 193 | replaced = true; |
147 | | - } catch (_) { /* ignore */ } |
| 194 | + } catch (_) { |
| 195 | + /* ignore */ |
| 196 | + } |
148 | 197 | }); |
149 | 198 | // If we replaced content and MathJax loads later it will find $$...$$; try to typeset now too |
150 | | - if (replaced && window.MathJax && typeof window.MathJax.typesetPromise === "function") { |
151 | | - window.MathJax.typesetPromise().catch(function(){/*ignore*/}); |
| 199 | + if ( |
| 200 | + replaced && |
| 201 | + window.MathJax && |
| 202 | + typeof window.MathJax.typesetPromise === "function" |
| 203 | + ) { |
| 204 | + window.MathJax.typesetPromise().catch(function () { |
| 205 | + /*ignore*/ |
| 206 | + }); |
152 | 207 | } |
153 | | - } catch (_) { /* ignore */ } |
| 208 | + } catch (_) { |
| 209 | + /* ignore */ |
| 210 | + } |
154 | 211 | } |
155 | 212 |
|
156 | 213 | // Try to load local highlight.js, fallback to CDN. When loaded, run highlight and also attach DOMContentLoaded safeguard. |
|
379 | 436 | loadHighlightJS(); |
380 | 437 | } catch (_) {} |
381 | 438 |
|
382 | | -// End IIFE |
| 439 | + // End IIFE |
383 | 440 | })(); |
0 commit comments