| 2 | |
| 3 | /** Balanced-brace check — skip typesetting while latex attribute is still streaming */ |
| 4 | export function isLatexReady(latex: string): boolean { |
| 5 | if (!latex.trim()) return false; |
| 6 | |
| 7 | let depth = 0; |
| 8 | for (const ch of latex) { |
| 9 | if (ch === "{") depth++; |
| 10 | else if (ch === "}") { |
| 11 | depth--; |
| 12 | if (depth < 0) return false; |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | return depth === 0; |
| 17 | } |
| 18 | |
| 19 | /** Typeset [data-latex] elements; incomplete formulas keep a stable placeholder. */ |
| 20 | export function renderMath(root: HTMLElement, streaming = false): void { |