{"id":2697,"library":"pylatexenc","title":"pylatexenc","description":"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.","status":"active","version":"2.10","language":"en","source_language":"en","source_url":"https://github.com/phfaist/pylatexenc","tags":["latex","parser","unicode","conversion","text processing"],"install":[{"cmd":"pip install pylatexenc","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"LatexNodes2Text","correct":"from pylatexenc.latex2text import LatexNodes2Text"},{"note":"`utf8tolatex` is deprecated since `pylatexenc` 2.0; use `unicode_to_latex` instead for new code.","wrong":"from pylatexenc.latexencode import utf8tolatex","symbol":"unicode_to_latex","correct":"from pylatexenc.latexencode import unicode_to_latex"},{"symbol":"LatexWalker","correct":"from pylatexenc.latexwalker import LatexWalker"}],"quickstart":{"code":"from pylatexenc.latex2text import LatexNodes2Text\nfrom pylatexenc.latexencode import unicode_to_latex\n\n# LaTeX to Unicode text conversion\nlatex_input = r\"\"\"\n\\textbf{Hi there!} Here is \\emph{an equation}:\n\\begin{equation}\n\\zeta = x + i y\n\\end{equation}\nwhere $i$ is the imaginary unit.\n\"\"\"\nconverter = LatexNodes2Text()\nunicode_output = converter.latex_to_text(latex_input)\nprint(f\"LaTeX to Unicode:\\n{unicode_output}\\n\")\n# Expected: LaTeX to Unicode:\n# Hi there! Here is an equation:\n# ζ = x + i y\n# where i is the imaginary unit.\n\n# Unicode text to LaTeX conversion\ntext_input = \"À votre santé! The length of samples #3 & #4 is 3μm\"\nlatex_encoded_output = unicode_to_latex(text_input)\nprint(f\"Unicode to LaTeX:\\n{latex_encoded_output}\")\n# Expected: Unicode to LaTeX:\n# \\`A votre sant\\'e! The length of samples \\#3 \\& \\#4 is 3\\ensuremath{\\mu}m","lang":"python","description":"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."},"warnings":[{"fix":"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'`.","message":"pylatexenc 2.0 introduced significant API changes from 1.x. Key changes include the deprecation of `keep_inline_math` in `LatexNodes2Text` in favor of `math_mode`, `macro_dict` in `LatexWalker` replaced by `latex_context`, and `pylatexenc.latexencode.utf8tolatex()` superseded by `unicode_to_latex()`.","severity":"breaking","affected_versions":"2.0+"},{"fix":"Understand that `pylatexenc` is for text processing and structural analysis, not for rendering. For full LaTeX compilation, use an actual TeX distribution.","message":"The `latexwalker` module, while powerful for parsing LaTeX structure, is not a full LaTeX engine. It focuses on syntactic parsing and node representation, not typesetting or full macro expansion, which can lead to unexpected results if treated as a complete renderer.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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`.","message":"Many internal classes and functions, especially within `pylatexenc.latexwalker` and node types, have been moved or renamed in preparation for `pylatexenc 3.0alpha`. For example, `len=` arguments were replaced by `pos_end=`, and node classes moved to the new `pylatexenc.latexnodes` module.","severity":"deprecated","affected_versions":"2.x (in anticipation of 3.0)"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}