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
β.
(TeX-add-style-hook "latex" (lambda () (LaTeX-add-environments '("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 \newenvironment{loop}[3]{...}{...}
;; loop.el (TeX-add-style-hook "loop" (lambda () (LaTeX-add-environments '("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.
(TeX-add-style-hook "latex" (lambda () (LaTeX-add-environments '("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
:
LaTeX-env-item
β
Insert the given environment and the first item.
LaTeX-env-figure
β
Insert the given figure-like environment with a caption and a label.
LaTeX-env-array
β
Insert the given array-like environment with position and column specifications.
LaTeX-env-label
β
Insert the given environment with a label.
LaTeX-env-list
β
Insert the given list-like environment, a specifier for the label and the first item.
LaTeX-env-minipage
β
Insert the given minipage-like environment with position and width specifications.
LaTeX-env-tabular*
β
Insert the given tabular*-like environment with width, position and column specifications.
LaTeX-env-picture
β
Insert the given environment with width and height specifications.
LaTeX-env-bib
β
Insert the given environment with a label for a bibitem.
LaTeX-env-contents
β
Insert the given environment with a filename as its argument.
LaTeX-env-args
β
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:
(LaTeX-add-environments '("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β.