gpt4 book ai didi

latex - 带有 LaTeXTools 的 Sublime Text 2 中的 "Smart quotes"

转载 作者:行者123 更新时间:2023-12-02 06:03:08 24 4
gpt4 key购买 nike

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

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

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

最佳答案

您也许可以让 Sublime Text 2 给引号一次,您已经完成了它们的编写,但由于这可能涉及编写一个复杂的插件,为什么不将 " 键重新映射到改为插入正确的字符?

可以添加模仿默认自动 " 配对的自定义键绑定(bind),而是在适当的地方插入 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|''

当您按下 " 而插入符号与它们相邻时,最终的重新绑定(bind)将跳过结束引号 ('')。也就是说,当您按下 " 这里:

``Sublime Text is the best!|''

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

``Sublime Text is the best!''|

关于latex - 带有 LaTeXTools 的 Sublime Text 2 中的 "Smart quotes",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16735332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com