phfaist / pylatexenc

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

Add verbatim parsing of lstlisting environments #66

Closed j-moeller closed 3 years ago

j-moeller commented 3 years ago

The pull request fixes the parsing of the lstlisting environment which should be similar to the verbatim environment. Since I am not deeply familiar with the code base, most diff is basically copy-pasted from the verbatim environment (without the additional parameterization for the macro).

I added a test case which contains source code with a single opening curly bracket. If the lstlisting environment is not parsed verbatim, this corrupts the parse tree (every node after the lstlisting environment becomes a child of the environment).

phfaist commented 3 years ago

Hi @j-moeller, thanks for your pull request! Supporting lstlisting environments is a great idea. Here are a couple thoughts:

Concretely, what I suggest would be:

Thanks again for contributing and let me know if I'm missing anything!