Coverage for src / rtflite / text_conversion / __init__.py: 100%
9 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-28 05:09 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-28 05:09 +0000
1"""
2Text conversion module for LaTeX to Unicode conversion.
4This module provides functionality to convert LaTeX mathematical symbols
5and commands to their Unicode equivalents, matching the behavior of the
6r2rtf package.
8The main entry point is the `convert_text` function which handles the
9text_convert parameter found throughout RTF components.
10"""
12from ..text_convert import text_convert # For backward compatibility
13from .converter import TextConverter
14from .symbols import LaTeXSymbolMapper
17# Main public interface
18def convert_text(text: str | None, enable_conversion: bool = True) -> str | None:
19 """
20 Convert LaTeX symbols in text to Unicode characters.
22 This function provides the main text conversion interface used throughout
23 the RTF encoding pipeline. It respects the enable_conversion flag to
24 allow selective enabling/disabling of conversion.
26 Args:
27 text: Input text that may contain LaTeX commands
28 enable_conversion: Whether to perform LaTeX to Unicode conversion
30 Returns:
31 Text with LaTeX commands converted to Unicode (if enabled)
33 Examples:
34 >>> convert_text("Area: \\pm 0.05", True)
35 "Area: +/- 0.05"
37 >>> convert_text("\\alpha + \\beta", False)
38 "\\alpha + \\beta"
39 """
40 if not enable_conversion or not text:
41 return text
43 converter = TextConverter()
44 return converter.convert_latex_to_unicode(text)
47__all__ = [
48 "convert_text",
49 "TextConverter",
50 "LaTeXSymbolMapper",
51 "text_convert", # backward compatibility
52]