1

我正在使用 Sublime 片段来创建 Latex 状态机模板。但是,它什么都不做(当我键入“stmach”并按 Tab 时,它会stmach消失,但不包括 Latex 代码)。我不明白为什么,因为我所有的其他片段都工作正常。

如果我删除片段中的一些行,它可以工作,但我需要整个块:/

<snippet>
<content><![CDATA[
    \begin{center}
        \begin{tikzpicture}[shorten >=1pt,node distance=4.5cm,on grid,auto]

        \tikzstyle{every state}=[draw=blue!50,very thick,fill=blue!20] % Node color

        \node[state,initial,initial text=reset, initial where=below] (configuration) {$conf$}; % Node name and position
        \node[state] (init) [below right=of configuration] {$init$};

        \path[->] % Arrow
        (configuration)
            edge  [bend left]                 node {finishConfiguration=1} (init)

        (init)
            edge  [bend left]                 node {} (configuration);

        \end{tikzpicture}
    \end{center}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>stmach</tabTrigger> 
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>text.tex</scope>

请注意,Latex 代码可以正常工作,不会出现任何错误或警告。

4

1 回答 1

2

$字符在 Sublime Text 片段中具有特殊含义,因此需要转义才能有效。

您可以使用前面的反斜杠转义它们,如文档所示

<snippet>
<content><![CDATA[
    \begin{center}
        \begin{tikzpicture}[shorten >=1pt,node distance=4.5cm,on grid,auto]

        \tikzstyle{every state}=[draw=blue!50,very thick,fill=blue!20] % Node color

        \node[state,initial,initial text=reset, initial where=below] (configuration) {\$conf\$}; % Node name and position
        \node[state] (init) [below right=of configuration] {\$init\$};

        \path[->] % Arrow
        (configuration)
            edge  [bend left]                 node {finishConfiguration=1} (init)

        (init)
            edge  [bend left]                 node {} (configuration);

        \end{tikzpicture}
    \end{center}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>stmach</tabTrigger> 
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>text.tex</scope>
</snippet>

使用来自https://github.com/sublimehq/Packages/pull/576的语法突出显示可以使问题更清晰,因为 ST 不幸地没有提供任何反馈,正如您所看到的: 无效的片段

逃脱时的样子: 有效片段

于 2016-11-08T07:37:04.973 回答