[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.6.3 Adding Support for Environments

Adding support for environments is very much like adding support for TeX macros, except that each environment normally only takes one argument, an environment hook. The example is again a short version of ‘latex.el’.

 (lambda ()
    '("document" LaTeX-env-document)
    '("enumerate" LaTeX-env-item)
    '("itemize" LaTeX-env-item)
    '("list" LaTeX-env-list))))

It is completely up to the environment hook to insert the environment, but the function LaTeX-insert-environment may be of some help. The hook will be called with the name of the environment as its first argument, and extra arguments can be provided by adding them to a list after the hook.

For simple environments with arguments, for example defined with ‘\newenvironment’, you can make AUCTeX prompt for the arguments by giving the prompt strings in the call to LaTeX-add-environments. The fact that an argument is optional can be indicated by wrapping the prompt string in a vector.

For example, if you have defined a loop environment with the three arguments from, to, and step, you can add support for them in a style file.

%% loop.sty

;; loop.el

 (lambda ()
    '("loop" "From" "To" "Step"))))

If an environment is defined multiple times, AUCTeX will choose the one with the longest definition. Thus, if you have an enumerate style file, and want it to replace the standard LaTeX enumerate hook above, you could define an ‘enumerate.el’ file as follows, and place it in the appropriate style directory.

 (lambda ()
    '("enumerate" LaTeX-env-enumerate foo))))

(defun LaTeX-env-enumerate (environment &optional ignore) ...)

The symbol foo will be passed to LaTeX-env-enumerate as the second argument, but since we only added it to overwrite the definition in ‘latex.el’ it is just ignored.

Function: LaTeX-add-environments env

Add each env to list of loaded environments.

Function: LaTeX-insert-environment env [ extra ]

Insert environment of type env, with optional argument extra.

Following is a list of available hooks for LaTeX-add-environments:


Insert the given environment and the first item.


Insert the given figure-like environment with a caption and a label.


Insert the given array-like environment with position and column specifications.


Insert the given environment with a label.


Insert the given list-like environment, a specifier for the label and the first item.


Insert the given minipage-like environment with position and width specifications.


Insert the given tabular*-like environment with width, position and column specifications.


Insert the given environment with width and height specifications.


Insert the given environment with a label for a bibitem.


Insert the given environment with a filename as its argument.


Insert the given environment with arguments. You can use this as a hook in case you want to specify multiple complex arguments just like in elements of TeX-add-symbols. This is most useful if the specification of arguments to be prompted for with strings and strings wrapped in a vector as described above is too limited.

Here is an example from ‘listings.el’ which calls a function with one argument in order to prompt for a key=value list to be inserted as an optional argument of the ‘lstlisting’ environment:

 '("lstlisting" LaTeX-env-args
   [TeX-arg-key-val LaTeX-listings-key-val-options]))

Some packages provide environments that are rarely useful to non-expert users. Those should be marked as expert environments using LaTeX-declare-expert-environments.

Function: LaTeX-declare-expert-environments style ENVIRONMENTS...

Declare ENVIRONMENTS as expert environments of STYLE.

Expert environments are completed depending on ‘TeX-complete-expert-commands’.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Mosè Giordano on October 29, 2014 using texi2html 1.82.