( ce: ReturnType<typeof createEngine>, e: Entry, node: unknown )
| 213 | } |
| 214 | |
| 215 | function mathjsonToLatex( |
| 216 | ce: ReturnType<typeof createEngine>, |
| 217 | e: Entry, |
| 218 | node: unknown |
| 219 | ): string | null { |
| 220 | try { |
| 221 | const latex = withEntryScope(ce, e, () => |
| 222 | ce.expr(rewriteUpperHalfPlane(node) as any, { canonical: false }).latex |
| 223 | ); |
| 224 | // The serializer emits literal newlines after `\\` row separators inside |
| 225 | // matrix environments (e.g. `pmatrix`). A `$$…$$` (or inline `$…$`) block |
| 226 | // must stay on a single physical line, otherwise the markdown/KaTeX |
| 227 | // renderer splits the math span and the tail renders as raw LaTeX. Collapse |
| 228 | // any embedded newline to a space — whitespace is token-equivalent in LaTeX, |
| 229 | // so `\\ ` renders identically to `\\\n`. |
| 230 | return latex.replace(/\s*\r?\n\s*/g, ' '); |
| 231 | } catch { |
| 232 | return null; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | /** Render the engine-usage sentence ("simplification", "expansion", "solving"). */ |
| 237 | function usageSentence(u: Usage | undefined): string { |
no test coverage detected