alvinwan / TexSoup

fault-tolerant Python3 package for searching, navigating, and modifying LaTeX documents
https://texsoup.alvinwan.com
BSD 2-Clause "Simplified" License
290 stars 43 forks source link

Fix parsing of environments inside special commands #148

Open JCGoran opened 1 year ago

JCGoran commented 1 year ago

Fixes #135. When using "special" commands (like \newcommand), it's possible to define only one part of an environment (like a singular \begin{equation}), which caused errors when parsing. This commit implements a "special" mode, which is entered every time a "special" command is encountered (for now, \newcommand, \renewcommand, and \providecommand), which disables the matching of \begin{...} with an associated \end{...} until the command considered is fully processed, after which it goes back to normal (non-math) mode. Note that this has the disadvantage that any whole environment defined inside of the special command will not be parsed as an environment, but rather as a series of TeX commands (I think it should be possible to reconstruct a complete env by parsing the content of the \newcommand, but I haven't tried it).

dpantele commented 11 months ago

Would it make sense to activate this 'special' mode in preamble/when inside {}?