Latex 我怎样才能把一个单词用$符号包装在升华文本3中

Latex 我怎样才能把一个单词用$符号包装在升华文本3中,latex,sublimetext3,Latex,Sublimetext3,我在升华文本3上使用乳胶;我想把$sign放在突出显示的文本周围。例如,我有一个角色说 X{d} 我想它做一个键盘快捷键,打印一个$符号之前和之后。当我按下alt-shift-w我得到 <p>X_{d}</p> X{d} 有办法拿到美元吗 像$X{d}$而不是一样,您可以通过向用户密钥绑定添加以下内容来实现这一点: { "keys": ["alt+shift+w"], "command": "insert_snippet", "args": { "contents":

我在升华文本3上使用乳胶;我想把$sign放在突出显示的文本周围。例如,我有一个角色说

X{d}

我想它做一个键盘快捷键,打印一个$符号之前和之后。当我按下
alt-shift-w
我得到

<p>X_{d}</p>
X{d}

有办法拿到美元吗


像$X{d}$而不是
一样,您可以通过向用户密钥绑定添加以下内容来实现这一点:

{ "keys": ["alt+shift+w"], "command": "insert_snippet", "args": { "contents": "\\$${1:$SELECTION}\\$" },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
    ]
},
{ "keys": ["alt+shift+w"], "command": "insert_snippet", "args": { "contents": "\\$${1:$SELECTION}\\$" },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
        { "key": "text_preceding_selection", "operator": "not_regex_contains", "operand": "\\$$" },
        { "key": "text_following_selection", "operator": "not_regex_contains", "operand": "^\\$" },
    ]
},
{ "keys": ["alt+shift+w"], "command": "trim_chars_around_selection", "args": { "chars_to_trim": 1 },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
        { "key": "text_preceding_selection", "operator": "regex_contains", "operand": "\\$$" },
        { "key": "text_following_selection", "operator": "regex_contains", "operand": "^\\$" },
    ]
},

要使其可逆,您需要编写一个Python插件,因为该功能不是内置于ST:

  • 工具菜单->开发者->新插件
  • 选择全部并替换为以下内容
  • 将ST建议(
    Packages/User/
    )作为
    text\u around\u sel.py
然后,使用以下键绑定:

{ "keys": ["alt+shift+w"], "command": "insert_snippet", "args": { "contents": "\\$${1:$SELECTION}\\$" },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
    ]
},
{ "keys": ["alt+shift+w"], "command": "insert_snippet", "args": { "contents": "\\$${1:$SELECTION}\\$" },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
        { "key": "text_preceding_selection", "operator": "not_regex_contains", "operand": "\\$$" },
        { "key": "text_following_selection", "operator": "not_regex_contains", "operand": "^\\$" },
    ]
},
{ "keys": ["alt+shift+w"], "command": "trim_chars_around_selection", "args": { "chars_to_trim": 1 },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
        { "key": "text_preceding_selection", "operator": "regex_contains", "operand": "\\$$" },
        { "key": "text_following_selection", "operator": "regex_contains", "operand": "^\\$" },
    ]
},

解释和推理:

  • ,无论文本选择插入符号位于何处,都不用于检测选择周围/外部的文本
  • (如果选择包括两端的美元,则可以使用
    text
    键和
    ^
    $
    锚定,而无需创建任何新的上下文侦听器。)
  • 因此,我们需要编写自己的上下文来正确地忽略选择。不幸的是,Sublime(Find)API的局限性意味着我们必须使用Python的
    re
    模块来实现这一点,这是一个功能要弱得多的正则表达式引擎——尽管就这个问题而言,这并不重要。(如果需要的话,可能会有一种“黑客”方法,将行的相关内容复制到临时隐藏视图(即输出面板)中,并在该视图上使用Sublime的find API以确保锚按预期工作等,但这超出了此任务的范围。)
  • 然后,
    trim\u chars\u around\u selection
    命令以相反的顺序遍历所有选择(因此,当插件修改文档时,从文档开始的选择偏移量不会改变),并从选择的任一端删除指定数量的字符

您可以通过向用户密钥绑定添加以下内容来实现这一点:

{ "keys": ["alt+shift+w"], "command": "insert_snippet", "args": { "contents": "\\$${1:$SELECTION}\\$" },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
    ]
},
{ "keys": ["alt+shift+w"], "command": "insert_snippet", "args": { "contents": "\\$${1:$SELECTION}\\$" },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
        { "key": "text_preceding_selection", "operator": "not_regex_contains", "operand": "\\$$" },
        { "key": "text_following_selection", "operator": "not_regex_contains", "operand": "^\\$" },
    ]
},
{ "keys": ["alt+shift+w"], "command": "trim_chars_around_selection", "args": { "chars_to_trim": 1 },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
        { "key": "text_preceding_selection", "operator": "regex_contains", "operand": "\\$$" },
        { "key": "text_following_selection", "operator": "regex_contains", "operand": "^\\$" },
    ]
},

要使其可逆,您需要编写一个Python插件,因为该功能不是内置于ST:

  • 工具菜单->开发者->新插件
  • 选择全部并替换为以下内容
  • 将ST建议(
    Packages/User/
    )作为
    text\u around\u sel.py
然后,使用以下键绑定:

{ "keys": ["alt+shift+w"], "command": "insert_snippet", "args": { "contents": "\\$${1:$SELECTION}\\$" },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
    ]
},
{ "keys": ["alt+shift+w"], "command": "insert_snippet", "args": { "contents": "\\$${1:$SELECTION}\\$" },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
        { "key": "text_preceding_selection", "operator": "not_regex_contains", "operand": "\\$$" },
        { "key": "text_following_selection", "operator": "not_regex_contains", "operand": "^\\$" },
    ]
},
{ "keys": ["alt+shift+w"], "command": "trim_chars_around_selection", "args": { "chars_to_trim": 1 },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
        { "key": "text_preceding_selection", "operator": "regex_contains", "operand": "\\$$" },
        { "key": "text_following_selection", "operator": "regex_contains", "operand": "^\\$" },
    ]
},

解释和推理:

  • ,无论文本选择插入符号位于何处,都不用于检测选择周围/外部的文本
  • (如果选择包括两端的美元,则可以使用
    text
    键和
    ^
    $
    锚定,而无需创建任何新的上下文侦听器。)
  • 因此,我们需要编写自己的上下文来正确地忽略选择。不幸的是,Sublime(Find)API的局限性意味着我们必须使用Python的
    re
    模块来实现这一点,这是一个功能要弱得多的正则表达式引擎——尽管就这个问题而言,这并不重要。(如果需要的话,可能会有一种“黑客”方法,将行的相关内容复制到临时隐藏视图(即输出面板)中,并在该视图上使用Sublime的find API以确保锚按预期工作等,但这超出了此任务的范围。)
  • 然后,
    trim\u chars\u around\u selection
    命令以相反的顺序遍历所有选择(因此,当插件修改文档时,从文档开始的选择偏移量不会改变),并从选择的任一端删除指定数量的字符

可以进一步推广@Keith Hall给出的代码,以削减任何成本并增加任何价值。我将在这里指出这一点

假设您想用特定的R和T来包装一个latex文件,这是通过按字符组合来实现的,所选字符串say
Tamer
将是
RTamerT
,当再次按键绑定时,它将变为
Tamer

{ "keys": ["alt+shift+q"], "command": "insert_snippet", "args": { "contents": "R${1:$SELECTION}T", "scope": "text.tex.latex"},
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
        { "key": "text_preceding_selection", "operator": "not_regex_contains", "operand": "R" },
        { "key": "text_following_selection", "operator": "not_regex_contains", "operand": "^T" },
    ]
},

{ "keys": ["alt+shift+q"], "command": "trim_chars_around_selection", "args": { "chars_to_trim": 1, "scope": "text.tex.latex" },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
        { "key": "text_preceding_selection", "operator": "regex_contains", "operand": "R" },
        { "key": "text_following_selection", "operator": "regex_contains", "operand": "^T" },
    ]
},

我想分享,因为我想找到一种新的包装,概括基思的代码,但不知道如何在崇高的文本中进行编码。尝试和错误帮助我找到了我的方法,并想与您分享。

Keith Hall给出的代码可以进一步推广,以削减任何成本,增加任何价值。我将在这里指出这一点

假设您想用特定的R和T来包装一个latex文件,这是通过按字符组合来实现的,所选字符串say
Tamer
将是
RTamerT
,当再次按键绑定时,它将变为
Tamer

{ "keys": ["alt+shift+q"], "command": "insert_snippet", "args": { "contents": "R${1:$SELECTION}T", "scope": "text.tex.latex"},
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
        { "key": "text_preceding_selection", "operator": "not_regex_contains", "operand": "R" },
        { "key": "text_following_selection", "operator": "not_regex_contains", "operand": "^T" },
    ]
},

{ "keys": ["alt+shift+q"], "command": "trim_chars_around_selection", "args": { "chars_to_trim": 1, "scope": "text.tex.latex" },
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.tex" },
        { "key": "text_preceding_selection", "operator": "regex_contains", "operand": "R" },
        { "key": "text_following_selection", "operator": "regex_contains", "operand": "^T" },
    ]
},

我想分享,因为我想找到一种新的包装,概括基思的代码,但不知道如何在崇高的文本中进行编码。尝试和错误帮助我找到了我的方法,并想与您分享

非常感谢您的帮助。有没有可能通过添加这样的代码来对其进行编码:如果我再次按下键,它会再次删除$1?我现在更新了我的答案,使其可逆:)你太棒了,我如何在Sublime text 3上学习这些东西?有没有一本书或教程视频或其他我可以在这些技术细节方面做得同样好的东西?非常感谢。有没有可能通过添加这样的代码来对其进行编码:如果我再次按下键,它会再次删除$1?我现在更新了我的答案,使其可逆:)你太棒了,我如何在Sublime text 3上学习这些东西?是否有一本书或教程视频或其他我可以在这些技术细节方面做得同样好的东西?