2

I am currently writing in latex in Sublime 3; I am using the LaTeXTools package. In one of the first lines of my file I have redefined the square brackets as follows.

\makeatletter
\AtBeginDocument{%
\let\[\@undefined
\DeclareRobustCommand{\[}{\begin{equation}}
\let\]\@undefined
\DeclareRobustCommand{\]}{\end{equation}}
}
\makeatother

Sublime in some way understands that this is an equation left open, and thus that the rest of my file is written in mathmode. This is annoying, not only because all my text is now yellow, but because autocompletions work poorly.

How could I solve this?

2

One way that solves your particular problem but doesn't solve the underlying issue could be to extract that part of the code to another tex or sty file and input that file. Tht way sublime won't see it and won't mess up the syntax coloring.

2

I can't see what Sublime Text does; but your approach is wrong: if you want equation you should use it.

Anyway, you can do

\AtBeginDocument{%
  \expandafter\let\csname[\endcsname\relax
  \expandafter\let\csname]\endcsname\relax
  \expandafter\DeclareRobustCommand\csname[\expandafter\endcsname\expandafter{%
    \csname begin\endcsname{equation}%
  }%
  \expandafter\DeclareRobustCommand\csname]\expandafter\endcsname\expandafter{%
    \csname end\endcsname{equation}%
  }%
}

so the Sublime Text parser won't see any among \[, \], \begin{equation} and \end{equation}.

0

In addition to all other solutions you can also edit the syntax definition. I have created a PR to fix it in a later Sublime Text build, see sublimehq#1010. To do this you can install PackageResourceViewer and edit the file LaTeX/LaTeX.sublime-syntax and change the context math-content by adding behind line 488 (You can also see it in the PR):

    - match: (?=\})
      pop: true

This just pops every math context on a unmatched closing brace/}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.