Sublime Forum

Incorrect behaviour of smart pairs of brackets in LaTeX

#1

Hi
the following situation is rather common when
typing in LaTeX:

  1. in order to insert a formula, I type $ which
    produces a couple $$ with cursor in the middle
  2. then I start typing the formula. At some point
    I need an open-end bracket like {}, so I type {
    but the smart pairing in ST2 only produces { since
    immediately to the right of the cursor is the
    closing $

For a contrast, in TextMate the behaviour of smart brackets
is correct: if I type { immediately to the left of a closing $,
the pair {} is correctly inserted.

Which is the right way to modify this behaviour? can it be done
by adding some preference inside my User folder? alternatively,
would it be reasonable to modify the LaTeX package to address
this?

Thanks
Piero

0 Likes

#2

You need to modify (override) the key bindings.

This is the default binding:

[code] { “keys”: “{”], “command”: “insert_snippet”, “args”: {“contents”: “{$0}”}, “context”:

		{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|$)", "match_all": true }
	]
},[/code]

So, you want to add this to your user key bindings and probably modify the context with (no guarantee):

{ "key": "following_text", "operator": "regex_contains", "operand": "^\\$", "match_all": true }, { "key": "selector", "operator": "equals", "operand": "text.tex.latex", "match_all": true }

Reference.

0 Likes

#3

Thanks, it works indeed.
Piero

0 Likes