Spaces:
Sleeping
Sleeping
File size: 1,334 Bytes
e66cfb4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | // assets/mathjax-plotly.js
(function () {
function attachListeners() {
function typeset(target) {
try {
if (window.MathJax) {
// v3
if (typeof window.MathJax.typesetPromise === "function") {
return window.MathJax.typesetPromise([target || document.body]);
}
// v2
if (window.MathJax.Hub && typeof window.MathJax.Hub.Queue === "function") {
window.MathJax.Hub.Queue(["Typeset", window.MathJax.Hub, target || document.body]);
}
}
} catch (e) {
console.warn("MathJax typeset failed:", e);
}
}
document.addEventListener("plotly_afterplot", function (e) { typeset(e.target); });
document.addEventListener("plotly_relayout", function (e) { typeset(e.target); });
document.addEventListener("plotly_redraw", function (e) { typeset(e.target); });
window.addEventListener("load", function () { typeset(document.body); });
}
// 如果已經有 MathJax,就只掛事件
if (window.MathJax) { attachListeners(); return; }
// 推薦載 v3(tex-svg 渲染器);載完再掛事件
var s = document.createElement("script");
s.src = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js";
s.defer = true;
s.onload = attachListeners;
document.head.appendChild(s);
})();
|