phfaist / pylatexenc

Simple LaTeX parser providing latex-to-unicode and unicode-to-latex conversion
https://pylatexenc.readthedocs.io
MIT License
283 stars 35 forks source link

adapt LatexWalker context while walking #87

Open nschloe opened 2 years ago

nschloe commented 2 years ago

One can adapt the LaTeX contet (how to parse macros, environments etc.) with

w = LatexWalker(self.string, latex_context=latex_context)

This, however is not how LaTeX works. Macro names can take different meaning throughout the document, depending on what \[re]newcommands appear. I would hence suggest to add a mechanism to adapt the walker context while walking through it. This implies that the walker only ever decodes the next keyword, not the whole document at once.

(Perhaps there already is a way to handle this and I've missed it.)

phfaist commented 1 year ago

There is an undocumented way to handle state changes in pylatexenc 2, and there will be an official way of doing that in the upcoming pylatexenc 3.