"""Plain-text UI labels (tabs, accordions) — patch W_g to subscript via client JS.""" from __future__ import annotations # Gradio Tab labels are plain text (no LaTeX). Short label — full $W_{g}$ math is in tab body. WG_TAB_LABEL = "Constant" # Patches tab buttons / accordion summaries that cannot use kc_markdown LaTeX. UI_MATH_LABEL_JS = r""" () => { const patchMath = (root) => { root.querySelectorAll("button, summary").forEach((el) => { if (el.dataset.kcMathPatched === "1") return; const text = el.textContent || ""; if (text.includes("WgConstant") || text.includes("Wg Constant")) { el.innerHTML = el.innerHTML.replace(/Wg\s*Constant/g, 'Wg Constant'); el.dataset.kcMathPatched = "1"; return; } if (!text.includes("W_g")) return; el.innerHTML = el.innerHTML.replace(/W_g\s*/g, 'Wg '); el.dataset.kcMathPatched = "1"; }); }; const patchNobleBanners = (root) => { root.querySelectorAll("details.kc-obs-noble-banner[data-kc-noble-z]").forEach((el) => { if (el.dataset.kcNobleInit === "1") return; const z = el.dataset.kcNobleZ; const key = "kc-noble-banner-" + z; if (localStorage.getItem(key)) el.removeAttribute("open"); el.addEventListener("toggle", () => { if (!el.open) localStorage.setItem(key, "1"); }); el.dataset.kcNobleInit = "1"; }); }; const patchInvestigationLabels = (root) => { root.querySelectorAll("button, summary, .label-wrap").forEach((el) => { if (el.dataset.kcInvPatched === "1") return; const text = (el.textContent || "").trim(); const match = text.match(/^(Investigation \d+:)(.*)$/); if (!match) return; el.innerHTML = '' + match[1] + '' + '' + match[2] + ''; el.dataset.kcInvPatched = "1"; }); }; const patch = (root) => { patchMath(root); patchNobleBanners(root); patchInvestigationLabels(root); }; patch(document); const obs = new MutationObserver(() => patch(document)); obs.observe(document.body, { childList: true, subtree: true }); return []; } """