SublimeText / LaTeXTools

LaTeX plugin for Sublime Text
https://latextools.readthedocs.io/
2k stars 364 forks source link

Do not insert two $$? #1462

Closed bensworth closed 4 years ago

bensworth commented 4 years ago

I recently started using LatexTools w/ Sublime, but I can't stand the default behavior to autocomplete math mode. When I type a single $, it automatically inserts $$. Is there any way to turn this off? I have tried toggling autocompletion options without luck and didn't see anything on this specific behavior in the documentation.

JacobEFO commented 4 years ago

Inside the keybindings you find

{ "keys": ["$"], "command": "insert_snippet", "args": {"contents": "\\$$0\\$"},
"context":  
    [
        { "key": "setting.command_mode", "operator": "equal", "operand": false },
        { "key": "selector", "operator": "equal", "operand": "text.tex.latex" },
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        // do not insert this if it is escaped
        { "key": "preceding_text", "operator": "not_regex_contains", "operand": "(?:\\\\\\\\)*(?:\\\\|\\$)$", "match_all": true },
        // don't insert, it inside math environments
        { "key": "selector", "operator": "not_equal", "operand": "meta.environment.math, string.other.math", "match_all": true },
        // don't insert, if there is an open dollar math environment at the end of the line
        { "key": "eol_selector", "operator": "not_equal", 
          "operand": "meta.environment.math.inline.dollar - punctuation.definition.string.end, string.other.math - punctuation.definition.string.end",
          "match_all": true }
    ] 
},

If you insert this to the latextool user keybindings and alter the first line to:

{ "keys": ["$"], "command": "insert_snippet", "args": {"contents": "\$"},

You at least achieve the possibility to only write single '$'.

bensworth commented 4 years ago

Perfect, thank you!