Home Download Buy Blog Forum Support

incorrect behaviour of smart pairs of brackets in LaTeX

incorrect behaviour of smart pairs of brackets in LaTeX

Postby pierre on Fri Feb 01, 2013 4:22 pm

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
pierre
 
Posts: 28
Joined: Sat Mar 19, 2011 8:47 pm

Re: incorrect behaviour of smart pairs of brackets in LaTeX

Postby FichteFoll on Sat Feb 02, 2013 3:16 am

You need to modify (override) the key bindings.

This is the default binding:
Code: Select all
   { "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 }
      ]
   },


So, you want to add this to your user key bindings and probably modify the context with (no guarantee):
Code: Select all
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\$", "match_all": true },
{ "key": "selector", "operator": "equals", "operand": "text.tex.latex", "match_all": true }


Reference.
FichteFoll
 
Posts: 405
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: incorrect behaviour of smart pairs of brackets in LaTeX

Postby pierre on Sat Feb 02, 2013 7:46 pm

Thanks, it works indeed.
Piero
pierre
 
Posts: 28
Joined: Sat Mar 19, 2011 8:47 pm


Return to Technical Support

Who is online

Users browsing this forum: Yahoo [Bot] and 39 guests