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)
| 334 | |
| 335 | |
| 336 | def 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 | |
| 360 | def _convert(element: Optional[ET.Element]) -> str: |