MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / mathjsonToLatex

Function mathjsonToLatex

scripts/fungrim/gen-reference-doc.ts:215–234  ·  view source on GitHub ↗
(
  ce: ReturnType<typeof createEngine>,
  e: Entry,
  node: unknown
)

Source from the content-addressed store, hash-verified

213}
214
215function 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"). */
237function usageSentence(u: Usage | undefined): string {

Callers 1

renderEntryFunction · 0.85

Calls 4

withEntryScopeFunction · 0.90
rewriteUpperHalfPlaneFunction · 0.85
exprMethod · 0.65
replaceMethod · 0.65

Tested by

no test coverage detected