Sublime Text 2中的“智能引号”与LaTeXTools

时间:2013-05-24 12:47:30

标签: latex sublimetext2

我最近将我的LaTeX创作从TeXWorks迁移到Sublime Text 2,而我真正缺少的一个功能是能够输入“常规引号”,(使用 shift + < kbd> 2 在我的瑞典语键盘上,产生"quoted text")并让编辑器自动将它们转换为LaTeX中正确的引用方式,在我输入时为``quoted text''

我试图在ST2中寻找一种方法来做到这一点,但我发现的大部分内容都与字符串中的引号自动转义有关,这不是我所追求的。

有没有办法在ST2中获得此功能?

3 个答案:

答案 0 :(得分:10)

你可能能够让Sublime Text 2一次性完成编写引号,但由于这可能涉及编写一个复杂的插件,为什么不重新映射"键来插入正确的而不是字符?

可以添加模仿默认自动"配对的自定义键绑定,但在适当的位置插入LaTeX引号。将这些行(来自Preferences -> Key Bindings – Default,第272-293行)添加到您的Preferences -> Key Bindings – User文件中:

{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "``$0''"}, "context":
    [
        { "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 },
        { "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
        { "key": "preceding_text", "operator": "not_regex_contains", "operand": "[\"a-zA-Z0-9_]$", "match_all": true },
        { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double", "match_all": true }
    ]
},

{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "``${0:$SELECTION}''"}, "context":
    [
        { "key": "selector", "operator": "equal", "operand": "text.tex.latex"},
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
    ]
},

{ "keys": ["\""], "command": "move", "args": {"by": "words", "forward": true}, "context":
    [
        { "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 },
        { "key": "following_text", "operator": "regex_contains", "operand": "^''", "match_all": true }
    ]
},

第一块代码会覆盖Sublime Text的默认引用配对,并将其调整为LaTeX样式的引号。当您在LaTeX文件中键入"时,只要它位于通常会插入一组双引号的位置,您就会得到:

``|''

第二部分取代了使用引号自动封闭所选文本的默认功能。在LaTeX文件中,选择文本然后按"将导致:

``This is the text you selected|''

当插入符号与插入符号相邻时,按''时,最终的重新绑定会跳过结尾引号(")。也就是说,当您在此处按"时:

``Sublime Text is the best!|''

插入符将移出引号之外,如下所示:

``Sublime Text is the best!''|

答案 1 :(得分:1)

安装Latexing package它不会将其列为一项功能,但会自动将"转换为``|'',并在中心准备好插入文本的插入符号。按"将使插入符号移过结束``''|

答案 2 :(得分:0)

我看到的最短路径是使用代码段。这个会起作用 -

<snippet>
    <content><![CDATA[
``${1:this}''
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>lq</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>text.tex.latex</scope>
</snippet>

将此latex-quote.sublime-snippet保存在ST2目录下的Packages > User中。然后在任何时候你想要使用引号,只需写lq(我从LaTeX引用中命名)并按 Tab