Skip to main content

2.4 Inserting Environment Templates

A large apparatus is available that supports insertions of environments, that is ‘\begin{}’ — ‘\end{}’ pairs.

AUCTeX is aware of most of the actual environments available in a specific document. This is achieved by examining your ‘\documentclass’ command, and consulting a precompiled list of environments available in a large number of styles.

Most of these are described further in the following sections, and you may easily specify more. See Customizing Environments.

You insert an environment with C-c C-e, and select an environment type. Depending on the environment, AUCTeX may ask more questions about the optional parts of the selected environment type. With C-u C-c C-e you will change the current environment.

command LaTeX-environment* arg*

(C-c C-e) AUCTeX will prompt you for an environment to insert. At this prompt, you may press ﹤TAB﹥ or ﹤SPC﹥ to complete a partially written name, and/or to get a list of available environments. After selection of a specific environment AUCTeX may prompt you for further specifications.

If the optional argument arg is not-nil (i.e. you have given a prefix argument), the current environment is modified and no new environment is inserted.

AUCTeX helps you adding labels to environments which use them, such as ‘equation’, ‘figure’, ‘table’, etc… When you insert one of the supported environments with C-c C-e, you will be automatically prompted for a label. You can select the prefix to be used for such environments with the LaTeX-label-alist variable.

user option LaTeX-label-alist

List the prefixes to be used for the label of each supported environment.

This is an alist whose car is the environment name, and the cdr either the prefix or a symbol referring to one.

If the name is not found, or if the cdr is nil, no label is automatically inserted for that environment.

If you want to automatically insert a label for a environment but with an empty prefix, use the empty string "" as the cdr of the corresponding entry.

As a default selection, AUCTeX will suggest the environment last inserted or, as the first choice the value of the variable LaTeX-default-environment.

user option LaTeX-default-environment

Default environment to insert when invoking ‘LaTeX-environment’ first time. When the current environment is ‘document’, it is overriden by LaTeX-default-document-environment.

variable LaTeX-default-document-environment

Default environment when invoking ‘LaTeX-environment’ and the current environment is ‘document’. It is intended to be used in LaTeX class style files. For example, in ‘beamer.el’ it is set to frame, in ‘letter.el’ to letter, and in ‘slides.el’ to slide.

If the document is empty, or the cursor is placed at the top of the document, AUCTeX will default to insert a ‘document’ environment prompting also for the insertion of ‘\documentclass’ and ‘\usepackage’ macros. You will be prompted for a new package until you enter nothing. If you do not want to insert any ‘\usepackage’ at all, just press ﹤RET﹥ at the first ‘Packages’ prompt.

AUCTeX distinguishes normal and expert environments. By default, it will offer completion only for normal environments. This behavior is controlled by the user option TeX-complete-expert-commands.

user option TeX-complete-expert-commands

Complete macros and environments marked as expert commands.

Possible values are nil, t, or a list of style names.

nil

Don’t complete expert commands (default).

t

Always complete expert commands.

(STYLES …)

Only complete expert commands of STYLES.

• Equations  
• Floats  
• Itemize-like  Itemize-like Environments
• Tabular-like  Tabular-like Environments
• Customizing Environments  

You can close the current environment with C-c ], but we suggest that you use C-c C-e to insert complete environments instead.

command LaTeX-close-environment

(C-c ]) Insert an ‘\end’ that matches the current environment.

AUCTeX offers keyboard shortcuts for moving point to the beginning and to the end of the current environment.

command LaTeX-find-matching-begin

(C-M-a) Move point to the ‘\begin’ of the current environment.

If this command is called inside a comment and LaTeX-syntactic-comments is enabled, try to find the environment in commented regions with the same comment prefix.

command LaTeX-find-matching-end

(C-M-e) Move point to the ‘\end’ of the current environment.

If this command is called inside a comment and LaTeX-syntactic-comments is enabled, try to find the environment in commented regions with the same comment prefix.