Go to the first, previous, next, last section, table of contents.

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"
 (function
  (lambda ()
    (LaTeX-add-environments
     '("document" LaTeX-env-document)
     '("enumerate" LaTeX-env-item)
     '("itemize" LaTeX-env-item)
     '("list" LaTeX-env-list)))))

The only hook that is generally useful is LaTeX-env-item, which is used for environments that contain items. 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 AUC TeX prompt for the arguments by giving the prompt strings in the call to LaTeX-add-environments. 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"
 (function
  (lambda ()
    (LaTeX-add-environments
     '("loop" "From" "To" "Step")))))

If an environment is defined multiple times, AUC TeX will chose 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"
 (function
  (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.


Go to the first, previous, next, last section, table of contents.