Sublime Forum

LaTeX math mode content aware snippets that trigger automatically

#1

I use sublime text to for latex documents. Snippets are very useful for this. However, I would like to have some ‘snippets’ that do not require tab to be used as a trigger.

For example, currently I have snippets so that if I type

infty
then tab, it expands to
\infty
It would be very handy if this could be done without need for the tab trigger.

Moreover, it would be useful if these could be made content aware in the following sense: infty should only expand to \infty if it is within a math mode environment, i.e., $ infty $, $$infty$$, ( infty), [ infty ]

0 Likes

#2

I am not sure there is an elegant and systematic way to do this without a plugin. Below I attempt to do it for infty only by changing the default key bindings. Give it a try.

		{ "keys": ["y"], "command": "chain", "args": { "commands": [
				["delete_word", {"forward": false}],
				["insert", {"characters": "\\infty"} ],
			] }, "context":
			[
				{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\binft$", "match_all": true },
				{ "key": "selector", "operator": "equal", "operand": "text.tex.latex meta.environment.math"},
			]
		},
0 Likes