(latexCode, displayMode)
| 100 | } |
| 101 | |
| 102 | function convertWithKaTeX(latexCode, displayMode) { |
| 103 | try { |
| 104 | if (typeof katex !== 'undefined') { |
| 105 | const container = document.createElement('div'); |
| 106 | katex.render(latexCode, container, { |
| 107 | output: 'mathml', |
| 108 | throwOnError: false, |
| 109 | displayMode: displayMode |
| 110 | }); |
| 111 | const mathmlElement = container.querySelector('math'); |
| 112 | if (mathmlElement) { |
| 113 | return { success: true, mathml: mathmlElement.outerHTML }; |
| 114 | } |
| 115 | } |
| 116 | return { success: false, error: 'KaTeX not available', fallback: latexCode }; |
| 117 | } catch (error) { |
| 118 | return { success: false, error: error.message, fallback: latexCode }; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | async function convertLatexToMathML(latexCode, options = {}) { |
| 123 | const displayMode = options.displayMode !== false; |
no test coverage detected