Snippets and shortcuts
Many snippets are available to help users enter LaTeX commands or symbols. Snippet View is also available from the TeX badge.
All commands are listed as ctrl+some key. If you're on Mac, don't worry we have written equivalents, so every time you see ctrl just imagine it's ⌘.
To have intellisense automatically triggered inside snippets, set editor.suggest.snippetsPreventQuickSuggestions
to false
. This is useful for instance if you want to enter \frac{x_{1}}{2}
using @/
+ x
+ __
+ 1
+ 2
using TAB to move from one tabstop to the next.
Environments
Some environments have a dedicated snippet in the form BXY
where XY
are the two first letters of the environment name. The starred versions use the prefix BSXY
.
Prefix | Environment name |
---|---|
BEQ |
equation |
BSEQ |
equation* |
BAL |
align |
BSAL |
align* |
BGA |
gather |
BSGA |
gather* |
BMU |
multline |
BSMU |
multline* |
BIT |
itemize |
BEN |
enumerate |
BSPL |
split |
BCAS |
cases |
BFR |
frame |
BFI |
figure |
BTA |
table |
Sectioning
Inserting a sectioning command
Sectioning commands can of course be inserted by just typing them as they are automatically completed by the intellisense mechanism. One can also use the following snippets.
Prefix | Sectioning level |
---|---|
SPA | part |
SCH | chapter |
SSE | section |
SSS | subsection |
SS2 | subsubsection |
SPG | paragraph |
SSP | subparagraph |
For instance, typing SSE
+ TAB
expands to \section{}
with the cursor inside the brackets.
Selecting a whole section
The current section along with all its subsections can be selected by calling the command latex-workshop.select-section
. Repeated calls end in expanding the selection in two ways:
- First, outer sections are selected
- If there is no outer section, the selection is expanded upwards by selecting the previous section.
Promoting/demoting sectioning levels
Adjusting sectioning levels can be done by calling one of the two commands latex-workshop.promote-sectioning
and latex-workshop.demote-sectioning
from the Command Palette.
These methods replace all sectioning commands with the sectioning command one level higher or lower. They apply either to the current line or to a selection.
Example
Applying latex-workshop.promote-sectioning
to the following selection,
\subsection{Demo}
\paragraph{Content}
yields
\section{Demo}
\subsubsection{Content}
To recursively promote/demote a section and all its subsections, first, call latex-workshop.select-section
to select the section and all its subsections and then call latex-workshop.promote-sectioning
or latex-workshop.demote-sectioning
.
Keybindings
This functionality has two keybindings
Method | Shortcut | Alternate |
---|---|---|
Promote Sectioning | ctrl+alt+[ | ctrl+l [ |
Demote Sectioning | ctrl+alt+] | ctrl+l ] |
To use the alternate shortcuts, set latex-workshop.bind.altKeymap.enabled
to true
.
Handy mathematical snippets
Some common mathematical symbols or commands have a dedicated snippet.
Prefix | Command |
---|---|
__ |
_{$1} |
** |
^{$1} |
... |
\dots |
Font commands and snippets
The following shortcuts are toggle commands. When some text is selected, it gets surrounded by the font command. When no text is actually selected, either the cursor is already inside the font command in which case the font command is removed or the command is inserted at the cursor position. The shortcuts work with multi-selections and multi-cursors.
Prefix | Shortcut | Command |
---|---|---|
fontsize |
Opens font size select | |
FNO |
ctrl+l, ctrl+n | \textnormal{${1}} |
FRM |
ctrl+l, ctrl+r | \textrm{${1}} |
FEM |
ctrl+l, ctrl+e | \emph{${1}} |
FSF |
\textsf{${1}} |
|
FTT |
ctrl+l, ctrl+t | \texttt{${1}} |
FIT |
ctrl+l, ctrl+i | \textit{${1}} |
FSL |
ctrl+l, ctrl+s | \textsl{${1}} |
FSC |
ctrl+l, ctrl+c | \textsc{${1}} |
FUL |
ctrl+l, ctrl+u | \underline{${1}} |
FUC |
\uppercase{${1}} |
|
FLC |
\lowercase{${1}} |
|
FBF |
ctrl+l, ctrl+b | \textbf{${1}} |
FSS |
ctrl+l, ctrl+6 | \textsuperscript{${1}} |
FBS |
ctrl+l, ctrl+minus | \textsubscript{${1}} |
Mathematical font commands and snippets
The following shortcuts are toggle commands. When some text is selected, it gets surrounded by the font command. When no text is actually selected, either the cursor is already inside the font command in which case the font command is removed or the command is inserted at the cursor position. The shortcuts work with multi-selections and multi-cursors.
Prefix | Shortcut | Command |
---|---|---|
MRM |
ctrl+m, ctrl+r | \mathrm{${1}} |
MSF |
ctrl+m, ctrl+s | \mathsf{${1}} |
MBF |
ctrl+m, ctrl+b | \mathbf{${1}} |
MBB |
ctrl+m, ctrl+shift+b | \mathbb{${1}} |
MCA |
ctrl+m, ctrl+c | \mathcal{${1}} |
MIT |
ctrl+m, ctrl+i | \mathit{${1}} |
MTT |
ctrl+m, ctrl+t | \mathtt{${1}} |
Miscellaneous Actions
Shortcut | Action |
---|---|
ctrl+l, ctrl+Enter | Insert newline + \item |
Surrounding text
With a command
To surround text with a command, just select some text and use ctrl+l, ctrl+w (⌘+l, ⌘+w on Mac) or call Surround selection with LaTeX command from the Command Palette (command latex-workshop.surround
). A new menu pops up to select the command. This works with multi selections.
Alternatively, you can just select the text and enter the command using autocompletion
With an environment
To surround some selected text with an environment, call LaTeX Workshop: Surround/wrap selection with \begin{}...\end{} from the Command Palette (command latex-workshop.wrap-env
). A multi-cursor is added inside the braces, to insert the environment name.