const TEX_SYMBOLS = Object.freeze({ "\\rightarrow": "→", "\\to": "→", "\\leftarrow": "←", "\\leftrightarrow": "↔", "\\Rightarrow": "⇒", "\\Leftarrow": "⇐", "\\Leftrightarrow": "⇔", "\\times": "×", "\\cdot": "·", "\\pm": "±", "\\neq": "≠", "\\ne": "≠", "\\leq": "≤", "\\le": "≤", "\\geq": "≥", "\\ge": "≥", "\\ldots": "…", "\\dots": "…", "\\bullet": "•", }); function cleanText(value) { let text = String(value ?? ""); // The models commonly wrap ordinary words in TeX text commands, sometimes // inside math delimiters. Convert the presentation intent, not the math language. text = text.replace(/\$\\textbf\{([^{}]*)\}\$/g, "**$1**"); text = text.replace(/\$\\(?:textit|emph)\{([^{}]*)\}\$/g, "//$1//"); text = text.replace(/\$\\text\{([^{}]*)\}\$/g, "$1"); text = text.replace(/\\textbf\{([^{}]*)\}/g, "**$1**"); text = text.replace(/\\(?:textit|emph)\{([^{}]*)\}/g, "//$1//"); text = text.replace(/\\text\{([^{}]*)\}/g, "$1"); // Unwrap a TeX math span only when a known presentation command was actually // converted. Unknown TeX remains visible rather than being guessed at. text = text.replace(/\$([^$\n]+)\$/g, (whole, inner) => { const converted = replaceKnownTexSymbols(inner); return converted !== inner && !/\\[A-Za-z]+/.test(converted) ? converted : whole; }); text = replaceKnownTexSymbols(text); // Normalize common Markdown emphasis into the tiny inline dialect used by // Cumorah renderers. Existing Cumorah **bold** and //italic// pass through. text = text.replace(/__([^_\n]+)__/g, "**$1**"); text = text.replace(/(?