On Fri Apr 18, Kai von Fintel wrote:
The minimal test case below shows that something in the parsing of the newenvironment command is throwing off the syntax coloring by the LaTeX bundle, at least on my system (TM 1.5.7 1464 on Leopard). The text in the document is incorrectly parsed as being in a math environment.
\documentclass{article}
\usepackage{amsmath}
\newenvironment{choice} {\left\lbrace\begin{gathered}} {\end{gathered}\right\rbrace}
\begin{document}
Text incorrectly parsed as being in a math environment.
\end{document}
Any ideas of how to fix the parsing?
Hi Kai -- This isn't exactly the correct fix, but if you go to Bundles-
Bundle Editor->Edit Languages... and pick the LaTeX->LaTeX syntax
definition, down about 1/3rd of the way down, you'll find the place where it is looking for these mathy environments:
align|equation|eqnarray | multline|aligned|alignat | split|gather|gathered
soon below that, you'll find
end = '(?x) (?:\s*) # Optional whitespace
If you change the (?:\s*) to (?:.*?) then you can get a sort of approximation of the correct syntax coloring.
I really don't quite understand why it works, but the idea was essentially to allow the { that precedes the \end{gathered} to be ignored (it wouldn't have counted as whitespace). In the original formulation, TextMate couldn't find the \end{gathered}, and so just assumes that the environment ends when the document does.
This isn't actually the right solution, but it at least keeps you from having the entire body of your document math-colored. The symptom of why this isn't the right solution is that everything following \begin{gathered} (including the closing brace of the first argument to \newenvironment, as well as anything from then on until just before the line containing \end{gathered}) is math colored.
Ideally, the LaTeX bundle would be able to handle (re)newenvironment specially, since each of the two arguments to these commands will almost always contain a lone \begin or \end, and scope of any mathification should presumably be restricted to the argument itself. But I haven't got a clue how to approach this the "right" way.
-Paul