tknuth / latex-snippets

LaTeX snippets for Sublime Text.
MIT License
11 stars 11 forks source link

switch between numbered and unnumbered equation #3

Closed chengchou closed 7 years ago

chengchou commented 7 years ago

Suppose I have written an unnumbered equation

\[
  Y = X.
\]

It is not unusual that I need to change this unnumbered equation to be a numbered one.

\begin{equation}
  Y = X.
\end{equation}

I wrote two snippets to do the above conversion. The first one is to convert the selected unnumbered equation to be a numbered one.

<snippet>
    <content><![CDATA[
${SELECTION/(?:(\\\[)?)(?:(\\\])?)/(?1:\\begin\{equation\})(?2:\\end\{equation\})/g}
]]></content>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>text.tex.latex</scope>
    <description>Change the unnumber equation to numbered equation</description>
</snippet>

The next one to do the inverse, converting the numbered one to unnumbered one.

<snippet>
    <content><![CDATA[
${SELECTION/(?:(\\begin\{equation\})?)(?:(\\end\{equation\})?)/(?1:\\\[)(?2:\\\])/g}
]]></content>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>text.tex.latex</scope>
    <description>Change the numbered equation to unnumbered equation</description>
</snippet>

Saving these two snippets, one define key bindings to implement them. For example, let Packages/User/My Snippets/LaTeX/turn_on_number.sublime-snippet be path of the first snippet. One can define cmd + 1 (in Mac) as the short cut for "turning the equation number on".

{
    "keys": ["super+1"],
    "command": "insert_snippet", 
    "args": { "name": "Packages/User/My Snippets/LaTeX/turn_on_number.sublime-snippet"}
},

The two snippet files are attached.

equation_snippets.zip

tknuth commented 7 years ago

Nice work! I switched to Vim, so I no longer develop this project. However, would you like to send a pull request so that I can merge your changes? Did you test the snippets yourself?

chengchou commented 7 years ago

I have initialised a pull request. Yes, I have tested the snippets on my Mac computer.

tknuth commented 7 years ago

Wonderful! Thank you for your contribution.