{"version":3,"file":"latexToMathML-A1X1Vkn8.cjs","names":[],"sources":["../src/exporterHelpers/latexToMathML.ts"],"sourcesContent":["import katex from \"katex\";\n\n// Converts LaTeX to MathML (via KaTeX). The DOCX exporter mapping converts\n// it further to OMML, the ODT mapping embeds it directly as a formula\n// object. Invalid LaTeX is expected (the source is user input), so it's\n// returned as a typed error - with a message safe to show to readers -\n// rather than thrown.\nexport function latexToMathML(\n  latex: string,\n  inline: boolean,\n): { error?: undefined; mathML: string } | { error: string } {\n  let katexOutput: string;\n  try {\n    katexOutput = katex.renderToString(latex, {\n      displayMode: !inline,\n      output: \"mathml\",\n      throwOnError: true,\n    });\n  } catch (error) {\n    // The boundary that converts KaTeX's parse throw into the typed result.\n    // Only `ParseError`s are expected (invalid user LaTeX) - their messages\n    // are safe to show to readers. Anything else is a bug and propagates.\n    // `ParseError` is read off the same `katex` object whose\n    // `renderToString` just ran, so unlike a separate class import it can't\n    // diverge under bundler interop.\n    if (!(error instanceof katex.ParseError)) {\n      throw error;\n    }\n    return { error: error.message };\n  }\n\n  // KaTeX wraps the MathML in a `span`; callers only need the `math`\n  // element itself.\n  const mathML = katexOutput.match(/<math[\\s\\S]*<\\/math>/)?.[0];\n  if (!mathML) {\n    throw new Error(\"No MathML found in KaTeX output\");\n  }\n\n  return { mathML };\n}\n"],"mappings":"+EAOA,SAAgB,EACd,EACA,EAC2D,CAC3D,IAAI,EACJ,GAAI,CACF,EAAc,EAAA,QAAM,eAAe,EAAO,CACxC,YAAa,CAAC,EACd,OAAQ,SACR,aAAc,EAChB,CAAC,CACH,OAAS,EAAO,CAOd,GAAI,EAAE,aAAiB,EAAA,QAAM,YAC3B,MAAM,EAER,MAAO,CAAE,MAAO,EAAM,OAAQ,CAChC,CAIA,IAAM,EAAS,EAAY,MAAM,sBAAsB,CAAC,GAAG,GAC3D,GAAI,CAAC,EACH,MAAU,MAAM,iCAAiC,EAGnD,MAAO,CAAE,QAAO,CAClB"}