Skip to content

Environments

Jerome Lelong edited this page Aug 30, 2023 · 21 revisions

Playing with environments and LaTeX syntax tree

Inserting an environment

  • To start a new environment, you can type \begin and use intellisense. See Intellisense for Environments for a detailed explanation of the different mechanisms.
  • Most environments can also be started by simply typing \ followed by the environment name. For instance, to start en equation environment, type \equation and choose the \begin{equation}...\end{equation} snippet. See Intellisense for Environments
  • Some common environments have specific snippets of the form B + the first two or three letters of the environment name, see the full list.
  • 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.

Itemize like environments

When the current line starts with \item or \item[], hitting Enter automatically adds a newline starting in the same way. For a better handling of the last item, hitting Enter on a line only containing \item or \item[] actually deletes the content of the line. The alt+Enter key is bind to the standard newline command.

This automatic insertion of \item can be deactivated by setting latex-workshop.bind.enter.key to false.

auto \item demo

In any case, you can use the shortcut ctrl+l, ctrl+Enter to insert a newline and \item. On Mac, ctrl is replaced by .

Navigating and selecting

  • To navigate from \begin/\end to the corresponding \end/\begin, while on the begin or end keywords, call LaTeX Workshop: Navigate to matching begin/end from the Command Palette (command latex-workshop.navigate-envpair). This function considers blocks surrounded by \[...\], $$...$$, \(...\) or $...$ as environments.
  • To select the inner content of an environment, excluding the opening and closing statements, call LaTeX Workshop: Select the current environment content from the Command Palette (command latex-workshop.select-envcontent). This function considers blocks surrounded by \[...\], $$...$$, \(...\) or $...$ as environments. Repeated calls result in selecting the outer environments.
  • To select the whole environment, including the opening and closing statements, call LaTeX Workshop: Select the current environment from the Command Palette (command latex-workshop.select-env). This function considers blocks surrounded by \[...\], $$...$$, \(...\) or $...$ as environments. Repeated calls result in selecting the outer environments.
  • To select the current environment name, call LaTeX Workshop: Select the current environment name from the Command Palette (command latex-workshop.select-envname). For this command to work, the cursor must be strictly between \begin{...} and \end{...}. If the current environment is \[...\], this function will automatically convert it into \begin{equation*}...\end{equation*}. Repeated calls result in selecting the outer environments. Note: this function does not work with the Vim extension.
  • To add a multi-cursor to the current environment name, call LaTeX Workshop: Add a multi-cursor to the current environment name from the Command Palette (command latex-workshop.multicursor-envname). If the current environment is \[...\], this function will automatically convert it into \begin{}...\end{}. For this command to work, the cursor must be strictly between \begin{...} and \end{...}. Repeated calls result in selecting the outer environments.

These three functions are directly available from the TeX badge.

Changing between \[...\] and \begin{}...\end{}

  • The commands latex-workshop.select-envname and latex-workshop.multicursor-envname described above, allow one to change a pair of \[...\] into any other math environment (e.g. equation or align).
  • To go backwards, call LaTeX Workshop: Toggle between \[...\] and \begin{}...\end{} from the Command Palette (command latex-workshop.toggle-equation-envname). This command changes \[...\] to \begin{equation*}...\end{equation*} (without moving the cursor) and it changes the following environments to \[...\]: equation, align, flalign, alignat, gather, multline, eqnarray (and their starred variants).

Closing the current environment

  • To auto close LaTeX environments, call LaTeX Workshop: Close current environment from the Command Palette (command function latex-workshop.close-env).

Surrounding selection 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.

Surround with environment demo

Alternatively, you can select the text and insert the environment using either the \envname command or the \beginend snippet but not the \begin snippet.

Surround with environment demo Surround with environment demo

latex-workshop.bind.enter.key

Enable the automatic insertion of \item on a newline when pressing Enter in a line starting in \item.

type default value
boolean true

latex-workshop.selection.smart.latex.enabled

Enable AST based smart selection. Command ids are editor.action.smartSelect.expand and editor.action.smartSelect.shrink.

type default value
boolean true

Table of Contents

Clone this wiki locally