Closed JacobEFO closed 4 years ago
I think the easiest way to archive this is to create a snippet and bind a keybinding towards it
Preferences > Browse Packages...
, this will open the file explorer at the ST packages locationUser
folder (if it does not exists create it)my_table.sublime-snippet
) and open it with Sublime Text (or any other editor)<snippet>
<content><![CDATA[
\begin{table}[htbp]
\centering
\caption{${1:PLACEHOLDER}}
\begin{tabular}{}
\dtoprule
\hline
\dbottomrule$0
\end{tabular}
\end{table}
]]></content>
<!-- <tabTrigger>mytable</tabTrigger> -->
<scope>text.tex.latex</scope>
</snippet>
{
"keys": ["ctrl+l", "ctrl+t"],
"command": "insert_snippet",
"args": { "name": "Packages/User/my_table.sublime-snippet" },
"context": [
{ "key": "selector", "operator": "equal", "operand": "text.tex.latex" }
],
},
Hey r-stein,
Thank you very much. It works like a charm!
Definitely a much better approach than I had initially. Where do you get to know about the "${1:PLACEHOLDER}" and "\dbottomrule$0" as well as the definitions of the scope?
Seems like $1 places the cursor at the mark and scope checks to see if it is in the text part of a latex document (seen similarly for math environment checks). But what does $0 do?
The scope of the snippet is not relevant if you don't use the tab trigger, but you can see the current scope by pressing ctrl+alt+shift+p
.
The fields $1
, $2
, ... can be used to insert text at the corresponding and jump to the next field with tab
. The exit position is marked with $0
.
You can use placeholders and even create fields based on transformations on other fields, e.g. auto remove special characters for labels:
<snippet>
<content><![CDATA[
\begin{table}[htbp]
\centering
\caption{${1:PLACEHOLDER}}
\label{${1/(\w)|(\W+)/\L\1(?2:_:)/g}}
\begin{tabular}{}
\dtoprule
\hline
\dbottomrule$0
\end{tabular}
\end{table}
]]></content>
<!-- <tabTrigger>mytable</tabTrigger> -->
<scope>text.tex.latex</scope>
</snippet>
Ah, excellent with the tab completion markers $1/$0. Makes good sense to have such functionality.
I can see, that LaTeXTools already utilize a few .sublime.snippet. Could have just looked there, doh.
ST3 and LaTeXTools is such a strong combination, I am ashamed I didn't find this combination all those years ago. Thanks for keeping it up to date.
@JacobEFO I did forgot to link the snippets documentation: https://sublime-text-unofficial-documentation.readthedocs.io/en/latest/extensibility/snippets.html
Hey LatexTools enthusiasts.
I have become quite familiar with most of the default kebinding, however now I wish to create a custom keybinding for creating my default tables. Say my tables look like this:
And I wish to use "super+l","t" for this. I have tried to use the "command":"latexenv" for this, where I assume it somehow calls "latexEnvironment.py" with some default argument, but I have had no luck in passing any arguments to "latexenv".
Is there anyone here, who can point me towards the way of doing this or how to properly understand the JSON syntax and keys to the functions.
Best regards
Edit: Somehow I cannot figure out how to properly format my latex code here and pastebin doesn't allow me more code snips for today. Sorry guys.