Coverage for src/rtflite/text_conversion/__init__.py: 100%
9 statements
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-14 16:35 +0000
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-14 16:35 +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 .converter import TextConverter
13from .symbols import LaTeXSymbolMapper
16# Main public interface
17def convert_text(text: str | None, enable_conversion: bool = True) -> str | None:
18 """
19 Convert LaTeX symbols in text to Unicode characters.
21 This function provides the main text conversion interface used throughout
22 the RTF encoding pipeline. It respects the enable_conversion flag to
23 allow selective enabling/disabling of conversion.
25 Args:
26 text: Input text that may contain LaTeX commands
27 enable_conversion: Whether to perform LaTeX to Unicode conversion
29 Returns:
30 Text with LaTeX commands converted to Unicode (if enabled)
32 Examples:
33 >>> convert_text("Area: \\pm 0.05", True)
34 "Area: +/- 0.05"
36 >>> convert_text("\\alpha + \\beta", False)
37 "\\alpha + \\beta"
38 """
39 if not enable_conversion or not text:
40 return text
42 converter = TextConverter()
43 return converter.convert_latex_to_unicode(text)
46# For backward compatibility with existing imports
47from ..text_convert import text_convert
49__all__ = [
50 "convert_text",
51 "TextConverter",
52 "LaTeXSymbolMapper",
53 "text_convert", # backward compatibility
54]