I am currently trying to experiment with using VSCode at the moment, and i cannot figure out how to properly define macros and bind them to specific keybinds.
I am used to using Sublime text, and i have defined a few macros that help me type much quicker and make less mistakes
The macros that i would like to get are the following:
\(\)
and set the cursor in the middle (between the first (
and the second \
).\[\]
and set the cursor in the middle (between the first [
and the second \
). Additionally, if it is possible, i would like it to also toggle a math preview function using latex-workshop.toggleMathPreviewPanel
.\begin{align*}
\item
\end{align*}
The \item
is preceded by a tab
, and it sets the cursor after the \item
I have managed to get the first macro by doing as follows
settings.json
:"macros": {
"latex_inline_math": [
{
"command": "type",
"args": {
"text": "\\(\\)"
}
},
"cursorLeft",
"cursorLeft"
],
}
keybindings.json
like this:{ // to get \(\)
"key": "alt+shift+q",
"command": "macros.latex_inline_math"
},
But i cannot figure out how to get the macros 2. and 3.
Also, if there is a better way to write the macro that i wrote, please let me know
You can define the following 3 keybindings
{
"key": "shift+alt+q",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": { "snippet": "\\($0\\)" }
},
{
"key": "shift+alt+s",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": { "snippet": "\\[$0\\]" }
},
{
"key": "shift+alt+a",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": { "snippet": "\\begin{align*}\n\t\\item$0\n\\end{align*}" }
}
If you also want a preview you can use the extension multi-command
Define this key binding
{
"key": "shift+alt+s",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"latex-workshop.toggleMathPreviewPanel",
{ "command": "editor.action.insertSnippet", "args": { "snippet": "\\[$0\\]" } }
]
}
}