New features in pylatexenc 2
mainVersion 2 of pylatexenc introduces significant improvements to the LaTeX parser, text conversion, and encoding modules:
LaTeX Parser (pylatexenc.latexwalker)
- Enhanced Context Management: A more versatile way to provide a "latex context" (macros, environment definitions, and "latex specials") using the
pylatexenc.macrospecmodule. - Latex Specials Support: Support for arbitrary character sequences with special LaTeX meanings (e.g.,
&,#,``) via theLatexSpecialsNodetype. - Custom Macro Parsing: Support for arbitrary macro arguments and formats (e.g.,
\verb+...+constructs). - Math Mode Improvements: Better parsing of math mode, including support for display math modes.
- Verbatim Representation:
LatexNodeobjects now retain information about their original string position, allowing for reconstruction of their verbatim LaTeX representation.
LaTeX to Text Conversion (pylatexenc.latex2text)
- Text Filling: Ability to fill text chunks at a specific column width using the
fill_textflag. - Whitespace Handling: The
strict_latex_spacesflag now defaults to'macros'. - Macro Specification: Renamed classes (e.g.,
MacroDefis nowMacroTextSpec) and added support for "latex specials". - Math Mode Conversion: A new
math_mode=flag replaceskeep_inline_math=for specifying how math mode converts to text.
Unicode to LaTeX Encoding (pylatexenc.latexencode)
- New Interface: Introduced
UnicodeToLatexEncoderand theunicode_to_latex()function, allowing for custom conversion rules and behavior for unknown characters. - Expanded Character Set: Added escapes from the W3C
unicode.xmlfile to the default set. - Renaming:
utf8tolatex()is deprecated in favor ofunicode_to_latex()(though the old function is kept for backward compatibility).
Command Line Interface
- The modules
latex2text,latexencode, andlatexwalkercan now be used directly from the command line. Use--helpto view available options.