pylatexenc is a simple Python library for parsing LaTeX code and converting between LaTeX and Unicode text. It's currently at version 2.10 and receives regular updates, mostly focusing on bug fixes and minor enhancements to its parsing and conversion capabilities.
pip install pylatexencVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core functionality of pylatexenc: converting a LaTeX string to plain Unicode text and converting a Unicode string back into LaTeX escape sequences.
Review the 'New features in pylatexenc 2' documentation for detailed migration paths. Update method signatures and class instantiations to use the new API. For instance, replace `keep_inline_math=True` with `math_mode='verbatim'`.
Understand that `pylatexenc` is for text processing and structural analysis, not for rendering. For full LaTeX compilation, use an actual TeX distribution.
While these changes are primarily in `3.0alpha` and later, be aware that relying on direct module paths or specific argument names from `2.x` for these internal components may lead to breakage when upgrading to `3.x`.
Install the library using pip: `pip install pylatexenc`
Ensure the LaTeX input is well-formed according to `pylatexenc`'s capabilities. For robustness, initialize `LatexWalker` or `LatexNodes2Text` with `tolerant_parsing=True` (e.g., `LatexWalker(latex_string, tolerant_parsing=True)`) to allow the parser to attempt to ignore syntax errors.
Either set `fail_bad_chars=False` (or `unknown_char_policy='keep'` or `'replace'`) to handle unknown characters gracefully, or define a custom conversion rule for the specific Unicode character using a `UnicodeToLatexConversionRule` with `UnicodeToLatexEncoder`.
Ensure your LaTeX document preamble includes `\usepackage[utf8]{inputenc}` (for older LaTeX engines) or that you are using a modern LaTeX engine (like XeLaTeX or LuaLaTeX) that natively supports UTF-8, and ensure `pylatexenc` is converting non-ASCII characters to appropriate LaTeX escapes, or configure `pylatexenc.latexencode` to replace or ignore problematic characters.No dependency data recorded yet.