ashthespy / Atom-LaTeX

The only LaTeX package you need for typesetting with Atom.
https://atom.io/packages/atom-latex
MIT License
22 stars 9 forks source link

Grammar gets distracted by custom environments #251

Open PhilippImhof opened 4 years ago

PhilippImhof commented 4 years ago

Consider the following minimal document:

\documentclass{article}

\usepackage{tikz}
\newenvironment{foo}{\begin{tikzpicture}}{\end{tikzpicture}}

\begin{document}

\begin{foo}
  \draw(0,0) circle (1cm);
\end{foo}

\end{document}

This compiles without any errors. However, with the current grammar, every line after \newenvironment is in scope meta.function.environment.latex.tikz and meta.group.braces.tex which is not correct.

ashthespy commented 4 years ago

The current syntax highlighting is accomplished using a set of regex rules and doesn't really parse the TeX. It thus never finds the second argument of /end{tikzpicture} to newenvironment. It might be possible to add a rule for newenvironment, but to be honest IIRC these grammars were just converted from the TextMate bundle, so I am not sure..

PhilippImhof commented 4 years ago

Yes, I saw that. It might however be worth making a change, e.g. reacting on \newenvironment and thus not taking into account the \begin{tikzpicture}, because it does not open an environment.

orichardson commented 3 years ago

I have an important and quite complicated custom environment that includes an unmatched $, which means the entire document is highlighted as though it is in math mode; the only reasonable way to edit it is to put this specific environment in a separate file and use \input.

I understand why fixing this properly is so hard (TeX is Turing complete), but it would be sufficient to have the ability to mark (via comments) sections that we do not want the grammar to parse.