textmate / latex.tmbundle

TextMate support for LaTeX
97 stars 65 forks source link

Syntax issue in defining shortcuts for \begin or \end. #76

Open coccoinomane opened 10 years ago

coccoinomane commented 10 years ago

Dear all,

In my field of research (physics) many authors define the following shortcuts in their Latex files:

\newcommand{\be}{\begin{equation}} \newcommand{\ee}{\end{equation}}

From the point of view of Latex, these shortcuts are perfectly legit, but alas they break down Textmate syntax highlighting. In fact, any text written after the first line is parsed as if being in math mode. This happens because Textmate finds an opening of math mode (\begin{equation}) but it cannot parse the corresponding ending (\end{equation}).

Thank you for your attention. Cheers, Guido

ciandorr commented 7 years ago

A good fix for issues like this one, which I have also encountered, would be to change the LaTeX grammar so that many of the LaTeX additions to the basic TeX grammar are invoked only between the "\begin{document}" and "\end{document}" environments. In particular, the special significance of \begin and \end only applies within the "document" environment - any '\begin' and '\end' that occurs anywhere else will almost certainly be part of the definition of some command or environment, which means that it will be surrounded by braces as in {\begin{equation}}.