Tuesday, January 29, 2013

Sublime Snippet: LaTex template

Instruction

a very useful Sublime Text snippet to save your time inputing latex templates.

<snippet>
    <content><![CDATA[

\documentclass[]{article}
\usepackage[letterpaper, margin = ${1:1}.in]{geometry}
\begin{document}
\title{${2:Title}}
\author{${3:YourName}}
\date{Today}
\maketitle

${4:Content}

\end{document}
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- <tabTrigger>hello</tabTrigger> -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>

Instruction

Open sublime text 2. Tool -> New Snippet . Copy and paste the above codes, save it in the recommended path when you press Command + S , remember to add the suffix ".sublime-snippet"

I personally recommend : latex.sublime_snippet

To use it

In any new document, Command + Shift + P , type in : latex ( or any other name you saved your snippet file), and press tab.

Keep pressing tab to see magics.

On modifying

Feel free to modify the above code, for example add packages you use very often, for the very magical placeholder like, the format is

${#:Predefined value}

where # is the number of the placeholder, Predefined value is any string you would probably use.

Say I don't always use \Today, I prefer manually enter it, I change the corresponding line to this following one:

\date{${4:Today}}

And I will make the original "Content" placeholder into # 5, which is: #{5:Content} rather than 4.

Special Thanks to Web-design-Weekly

No comments:

Post a Comment