[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
See section 11. Automatic Customization, for a discussion about automatically generated global, private, and local style files. The hand generated style files are equivalent, except that they by default are found in `style' directories instead of `auto' directories.
12.1 A Simple Style File | ||
12.2 Adding Support for Macros | ||
12.3 Adding Support for Environments | ||
12.4 Adding Other Information | ||
12.5 Automatic Extraction of New Things |
If you write some useful support for a public TeX style file, please send it to us.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Here is a simple example of a style file.
;;; book.el - Special code for book style. (TeX-add-style-hook "book" (function (lambda () (setq LaTeX-largest-level (LaTeX-section-level ("chapter")))))) |
This file specifies that the largest kind of section in a LaTeX document
using the book document style is chapter. The interesting thing to
notice is that the style file defines an (anonymous) function, and adds it
to the list of loaded style hooks by calling TeX-add-style-hook
.
The first time the user indirectly tries to access some style specific information, such as the largest sectioning command available, the style hooks for all files directly or indirectly read by the current document is executed. The actual files will only be evaluated once, but the hooks will be called for each buffer using the style file.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The most common thing to define in a style hook is new symbols (TeX macros). Most likely along with a description of the arguments to the function, since the symbol itself can be defined automatically.
Here are a few examples from `latex.el'.
(TeX-add-style-hook "latex" (function (lambda () (TeX-add-symbols '("arabic" TeX-arg-counter) '("label" TeX-arg-define-label) '("ref" TeX-arg-label) '("newcommand" TeX-arg-define-macro [ "Number of arguments" ] t) '("newtheorem" TeX-arg-define-environment [ TeX-arg-environment "Numbered like" ] t [ TeX-arg-counter "Within counter" ]))))) |
Each argument to TeX-add-symbols
is a list describing one symbol.
The head of the list is the name of the symbol, the remaining elements
describe each argument.
If there are no additional elements, the symbol will be inserted with point inside braces. Otherwise, each argument of this function should match an argument of the TeX macro. What is done depends on the argument type.
If a macro is defined multiple times, AUCTeX will chose the one with the longest definition (i.e. the one with the most arguments).
Thus, to overwrite
'("tref" 1) ; one argument |
'("tref" TeX-arg-label ignore) ; two arguments |
ignore
is a function that does not do anything, so when you
insert a `tref' you will be prompted for a label and no more.
string
number
nil
t
other symbols
list
vector
A lot of argument hooks have already been defined. The first argument to all hooks is a flag indicating if it is an optional argument. It is up to the hook to determine what to do with the remaining arguments, if any. Typically the next argument is used to overwrite the default prompt.
TeX-arg-conditional
TeX-arg-literal
TeX-arg-free
TeX-arg-eval
TeX-arg-file
TeX-arg-label
TeX-arg-macro
TeX-arg-environment
TeX-arg-cite
TeX-arg-counter
TeX-arg-savebox
TeX-arg-file
TeX-arg-input-file
TeX-arg-define-label
TeX-arg-define-macro
TeX-arg-define-environment
TeX-arg-define-cite
TeX-arg-define-counter
TeX-arg-define-savebox
TeX-arg-corner
TeX-arg-lr
TeX-arg-tb
TeX-arg-pagestyle
TeX-arg-verb
TeX-arg-pair
TeX-arg-size
TeX-arg-coordinate
If you add new hooks, you can assume that point is placed directly after
the previous argument, or after the macro name if this is the first
argument. Please leave point located after the argument you are
inserting. If you want point to be located somewhere else after all
hooks have been processed, set the value of exit-mark
. It will
point nowhere, until the argument hook sets it.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 AUCTeX 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, AUCTeX 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.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You can also specify bibliographical databases and labels in the style file. This is probably of little use, since this information will usually be automatically generated from the TeX file anyway.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The automatic TeX information extractor works by searching for regular expressions in the TeX files, and storing the matched information. You can add support for new constructs to the parser, something that is needed when you add new commands to define symbols.
For example, in the file `macro.tex' I define the following macro.
\newcommand{\newmacro}[5]{% \def#1{#3\index{#4@#5~cite{#4}}\nocite{#4}}% \def#2{#5\index{#4@#5~cite{#4}}\nocite{#4}}% } |
AUCTeX will automatically figure out that `newmacro' is a macro that takes five arguments. However, it is not smart enough to automatically see that each time we use the macro, two new macros are defined. We can specify this information in a style hook file.
;;; macro.el - Special code for my own macro file. ;;; Code: (defvar TeX-newmacro-regexp '("\\\\newmacro{\\\\\\([a-zA-Z]+\\)}{\\\\\\([a-zA-Z]+\\)}" (1 2) TeX-auto-multi) "Matches \newmacro definitions.") (defvar TeX-auto-multi nil "Temporary for parsing \\newmacro definitions.") (defun TeX-macro-cleanup () ;; Move symbols from `TeX-auto-multi' to `TeX-auto-symbol'. (mapcar (function (lambda (list) (mapcar (function (lambda (symbol) (setq TeX-auto-symbol (cons symbol TeX-auto-symbol)))) list))) TeX-auto-multi)) (defun TeX-macro-prepare () ;; Clear `Tex-auto-multi' before use. (setq TeX-auto-multi nil)) (add-hook 'TeX-auto-prepare-hook 'TeX-macro-prepare) (add-hook 'TeX-auto-cleanup-hook 'TeX-macro-cleanup) (TeX-add-style-hook "macro" (function (lambda () (TeX-auto-add-regexp TeX-newmacro-regexp) (TeX-add-symbols '("newmacro" TeX-arg-macro (TeX-arg-macro "Capitalized macro: \\") t "BibTeX entry: " nil))))) ;;; macro.el ends here |
When this file is first loaded, it adds a new entry to
TeX-newmacro-regexp
, and defines a function to be called before
the parsing starts, and one to be called after the parsing is done. It
also declares a variable to contain the data collected during parsing.
Finally, it adds a style hook which describes the `newmacro' macro,
as we have seen it before.
So the general strategy is: Add a new entry to TeX-newmacro-regexp
.
Declare a variable to contain intermediate data during parsing. Add hook
to be called before and after parsing. In this case, the hook before
parsing just initializes the variable, and the hook after parsing
collects the data from the variable, and adds them to the list of symbols
found.
The list has the following format ((REGEXP MATCH TABLE) ...), that is, each entry is a list with three elements.
REGEXP. Regular expression matching the macro we want to parse.
MATCH. A number or list of numbers, each representing one parenthesized subexpression matched by REGEXP.
TABLE. The symbol table to store the data. This can be a function, in
which case the function is called with the argument MATCH. Use
TeX-match-buffer
to get match data. If it is not a function, it
is presumed to be the name of a variable containing a list of match
data. The matched data (a string if MATCH is a number, a list of
strings if MATCH is a list of numbers) is put in front of the table.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by XEmacs shared group account on December, 19 2009
using texi2html 1.65.