sicklybeans
sicklybeans

Reputation: 309

How can I expand Sublime's language syntax understanding to incorporate custom syntax?

I know that sounds vague. Basically I just want Sublime to highlight custom syntax (color the text), just like it does with native syntax.

I am using Sublime to write LaTeX code. For those that don't know, LaTeX equations are typically enclosed by \[ \], e.g.

\[ E = m c^2 \]

Sublime understands that syntax and colors the enclosing code appropriately.

However, I use my custom defined command, \eq{ ... }, which wraps the \[ \] functionality (so I can globally change some settings by just redefining the \eq definition). e.g.

\eq{ E = m c^2 }

I don't know anything about Sublime under the hood beyond basic key bindings. I want to expand Sublime's understanding of syntax to incorporate my custom command without wasting a ton of time digging through tutorials and such.

Upvotes: 0

Views: 71

Answers (1)

r-stein
r-stein

Reputation: 4847

Since you are mainly interested in the result and not in the reasoning, I will try to be as straight forward as I can.

The LaTeX syntax of Sublime Text will change in release 3119 and I would recommend to use that, if you want to change something. Just download it from https://github.com/sublimehq/Packages and put the LaTeX folder into the folder, which opens when you select Preferences >> Browse Packages... in the Sublime Text menu. Afterwards open the file LaTeX.sublime-syntax and search for ensuremath (LaTeX.sublime-syntax#L498). Duplicate that part (everything with a higher indent) and change the command to the command you wish, e.g. in your example this would be - match: '((\\)eq)(\{)'.

Aside the new syntax removes the highlighting of math environments as strings, because this has lead to several problems. I made a small entry in the LaTeXTools wiki to explain, how you restore the highlight.

Upvotes: 1

Related Questions