MCPcopy
hub / github.com/HKUDS/RAG-Anything / omml_to_latex

Function omml_to_latex

raganything/omml_extractor.py:336–357  ·  view source on GitHub ↗

Convert a single `` `` element (or any of its children) to LaTeX. The function is a small recursive descent transformer. For each known OMML construct it emits the canonical LaTeX form; unknown elements fall through to their concatenated text content so that callers always get *

(element: ET.Element)

Source from the content-addressed store, hash-verified

334
335
336def omml_to_latex(element: ET.Element) -> str:
337 """Convert a single ``<m:oMath>`` element (or any of its children) to LaTeX.
338
339 The function is a small recursive descent transformer. For each known OMML
340 construct it emits the canonical LaTeX form; unknown elements fall through
341 to their concatenated text content so that callers always get *some*
342 searchable representation.
343
344 Parameters
345 ----------
346 element:
347 An :class:`xml.etree.ElementTree.Element` from the OMML namespace.
348 Typically the root ``<m:oMath>`` returned by
349 :func:`extract_omml_equations`, but any descendant works too.
350
351 Returns
352 -------
353 str
354 A LaTeX string. The result is *not* wrapped in math delimiters
355 (``$ ... $`` or ``\\[ ... \\]``); the caller chooses the context.
356 """
357 return _convert(element)
358
359
360def _convert(element: Optional[ET.Element]) -> str:

Callers 15

test_simple_runMethod · 0.90
test_fractionMethod · 0.90
test_superscriptMethod · 0.90
test_subscriptMethod · 0.90
test_sub_superscriptMethod · 0.90
test_radical_simpleMethod · 0.90
test_known_functionMethod · 0.90

Calls 1

_convertFunction · 0.85

Tested by 15

test_simple_runMethod · 0.72
test_fractionMethod · 0.72
test_superscriptMethod · 0.72
test_subscriptMethod · 0.72
test_sub_superscriptMethod · 0.72
test_radical_simpleMethod · 0.72
test_known_functionMethod · 0.72