对于 Sublime 文本中使用的 LaTeXTools 包,如何定义相同的快捷方式以对两个不同的LaTeX
文档类进行不同的操作?
例如,假设您想在键盘映射中定义“control+enter”以便对 BEAMER 进行以下操作:
// new equation line (LHS + RHS)
{ "keys": ["control+enter"], "command": "insert_snippet", "args": {"contents": "\n\\uncover<+->{$1} & \\uncover<.->{=$2} \\\\\\\\$0"},
"context":
[
{"key": "selector", "operator": "equal", "operand": "text.tex.latex string.other.math, text.tex.latex meta.environment.math"},
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
]
},
但随后必须"control+enter"
按照以下方式对文章进行操作
// new equation line (LHS + RHS)
{ "keys": ["control+enter"], "command": "insert_snippet", "args": {"contents": "\n$1 & =$2 \\\\\\\\$0"},
"context":
[
{"key": "selector", "operator": "equal", "operand": "text.tex.latex string.other.math, text.tex.latex meta.environment.math"},
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
]
},
也就是说,"control+enter"
为 beamer 包裹了一个带有揭露覆盖的对齐环境,但对于 article 文档类则没有。
你会怎么做?
"operand"
在每种情况下您需要如何定义(或范围)?
答案1
您无法使用内置范围执行此操作,但需要上下文。我将添加下一个预发布(即st3-4.0.0-alpha.3
)通过LaTeX工具#1167。如果您有该预发行版,您只需添加键绑定:
{
"keys": ["ctrl+enter"], "command": "insert_snippet", "args": {"contents": "\n$1 & =$2 \\\\\\\\$0"},
"context":
[
{ "key": "selector", "operand": "text.tex.latex meta.environment.math" },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
]
},
{
"keys": ["ctrl+enter"], "command": "insert_snippet", "args": {"contents": "\n\\uncover<+->{$1} & \\uncover<.->{=$2} \\\\\\\\$0"},
"context":
[
{ "key": "selector", "operand": "text.tex.latex meta.environment.math" },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "latextools.documentclass", "operand": "beamer" }
]
},
在发布之前,您可以通过以下方式手动安装
- 下载文件这里
- 打开 LaTeXTools 文件夹:在菜单中选择首选项 > 浏览包...然后打开 LaTeXTools 文件夹
- 将下载的文件放在那里
要模拟代码片段,请安装“Chain Of Command”并创建以下键绑定:
{
"keys": ["tab"],
"command": "chain",
"args": {"commands": [
["delete_word", {"forward": false}],
["insert_snippet", {"contents": "\\mybox<..>"}],
]},
"context":
[
{ "key": "auto_complete_visible", "operand": false },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\bbox$", "match_all": true }, // <- change "box" here
{ "key": "selector", "operand": "text.tex.latex meta.environment.math" },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "latextools.documentclass", "operand": "beamer" },
]
},