2

我最近将我的 LaTeX 创作从 TeXWorks 迁移到了 Sublime Text 2,我真正缺少的一个功能是能够输入“正则引号”(在我的瑞典语键盘上使用shift+ ,yield )并自动拥有编辑器将它们转换为在 LaTeX 中引用的正确方式,这是在我打字的时候。2"quoted text"``quoted text''

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

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

4

3 回答 3

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 文件中键入 a 时",只要它位于通常会插入一组双引号的位置,您就会得到:

``|''

第二部分替换了使用引号自动将所选文本括起来的默认功能。在 LaTeX 文件中,选择文本然后按下"将导致:

``This is the text you selected|''

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

``Sublime Text is the best!|''

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

``Sublime Text is the best!''|
于 2013-05-25T19:40:08.010 回答
1

安装Latexing 包,它没有将此列为功能,但它会自动转换"``|''中心的插入符号,为您引用的文本做好准备。然后按下"会将插入符号移过关闭``''|

于 2015-06-04T04:40:40.917 回答
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-snippetPackages > UserST2 的目录下。然后在任何时候你想使用引号,只需写lq(我从 LaTeX 引号中命名)并按Tab

于 2013-05-24T13:09:25.153 回答