Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
547 views
in Technique[技术] by (71.8m points)

sublimetext3 - Latex Sublime snippet

I'm using a Sublime snippet to create a Latex state machine template. However, it does nothing (when I type "stmach" and press tab, stmach disappears but the Latex code isn't included). I don't understand why, as all my other snippets are working fine.

If I remove some lines in the snippet, it works, but I need the whole block :/

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

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

        
ode[state,initial,initial text=reset, initial where=below] (configuration) {$conf$}; % Node name and position
        
ode[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>

Note that the Latex code works without any error or warning.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The $ character has special meaning in Sublime Text snippets, and therefore needs to be escaped to be valid.

You can escape them with a preceding backslash, as the documentation shows:

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

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

        
ode[state,initial,initial text=reset, initial where=below] (configuration) {$conf$}; % Node name and position
        
ode[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>

Using the syntax highlighting from https://github.com/sublimehq/Packages/pull/576 makes the problem clearer, as ST unfortunately doesn't offer any feedback, as you have seen: invalid snippet

How it looks when escaped: valid snippet


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...