@aidalinfo/office-to-markdown
Version:
Modern TypeScript library for converting Office documents (DOCX) to Markdown format, optimized for Bun runtime with enhanced table support and math equation conversion.
53 lines • 2.11 kB
TypeScript
/**
* Office Math Markup Language (OMML) to LaTeX Processor
*
* This module provides functionality to convert Microsoft Office's OMML (Office Math Markup Language)
* format to LaTeX. OMML is used in DOCX files to represent mathematical equations and expressions.
*
* **Conversion Strategy:**
* - Uses regex-based pattern matching for reliability and performance
* - Handles common math elements: fractions, superscripts, subscripts, roots
* - Converts Unicode mathematical symbols to LaTeX equivalents
* - Provides fallback to plain text for unsupported elements
*
* **Supported OMML Elements:**
* - `<f>` (fractions) → `\frac{}{}`
* - `<sSup>` (superscripts) → `^{}`
* - `<sSub>` (subscripts) → `_{}`
* - `<rad>` (roots) → `\sqrt{}` or `\sqrt[]{}`
* - Unicode symbols → LaTeX commands
*
* @module OmmlProcessor
*/
/**
* Convert OMML XML string to LaTeX using regex-based pattern matching.
*
* This is the main conversion function that processes OMML XML content through
* a series of transformations to produce clean LaTeX output.
*
* **Processing Steps:**
* 1. Remove XML namespace prefixes for cleaner processing
* 2. Apply all OMML conversion patterns in sequence
* 3. Clean up remaining XML tags
* 4. Convert Unicode symbols to LaTeX equivalents
* 5. Normalize whitespace and return result
*
* **Error Handling:**
* - Catches any processing errors and logs warnings
* - Falls back to plain text extraction if conversion fails
* - Never throws exceptions to avoid breaking the conversion pipeline
*
* @param ommlXml - The OMML XML content to convert
* @returns Clean LaTeX string representation of the math expression
*
* @example
* ```typescript
* const omml = '<m:f><m:num>1</m:num><m:den>2</m:den></m:f>';
* const latex = convertOmmlStringToLatex(omml); // Returns '\frac{1}{2}'
*
* const complex = '<m:sSup><m:e>x</m:e><m:sup>2</m:sup></m:sSup>';
* const result = convertOmmlStringToLatex(complex); // Returns 'x^{2}'
* ```
*/
export declare function convertOmmlStringToLatex(ommlXml: string): string;
//# sourceMappingURL=omml-processor.d.ts.map