// 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); })();