Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (23 sloc) 1 KB
import sublime, sublime_plugin
import re
# Insert LaTeX environment based on current word
# Position cursor inside environment
class latexenvCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
view = self.view
# Workaround: env* and friends trip ST2 up because * is a word boundary,
# so we search for a word boundary
# Code is similar to (should prbly factor out)
point = view.sel()[0].b
line = view.substr(sublime.Region(view.line(point).a, point))
line = line[::-1]
rex = re.compile(r"([^\s\{]*)\s?\{?")
expr = re.match(rex, line)
if expr:
environment =[::-1]
environment_region = sublime.Region(point-len(environment),point)
view.erase(edit, environment_region)
snippet = "\\\\begin{" + environment + "}\n$1\n\\\\end{" + environment + "}$0"
view.run_command("insert_snippet", {'contents' : snippet})
sublime.status_message("LATEXTOOLS INTERNAL ERROR: could not find environment to expand")
Jump to Line
Something went wrong with that request. Please try again.