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

Adding Support for Macros

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 is a few examples from `latex.el'.

(TeX-add-style-hook "latex"
 (function
  (lambda ()
     (TeX-add-symbols
     '("arabic" TeX-argument-counter-hook)
     '("label" TeX-argument-define-label-hook)
     '("ref" TeX-argument-label-hook)
     '("newcommand" TeX-argument-define-macro-hook [ "Number of arguments" ] t)
     '("newtheorem" TeX-argument-define-environment-hook
       [ TeX-argument-environment-hook "Numbered like" ]
       t [ TeX-argument-counter-hook "Within counter" ])))))

Function: TeX-add-symbols symbol ...

Add each symbol to the list of known symbols.

Each argument to TeX-add-symbols is a list describing one symbol. The head of list is the name if 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 to the TeX macro. What is done depend on the argument type.

If a macro is defined multiple times, AUC TeX will chose the one with the longest definition (i.e.\ the one with most arguments).

Thus, to overwrite

        '("tref" 1) ; one argument

you can specify

        '("tref" TeX-argument-label-hook ignore) ; two arguments

ignore is a functions that does not do anything, so when you insert a `tref' you will be prompted for a label and no more.

string
Use the string as a prompt to prompt for the argument.
number
Insert that many braces, leave point inside the first.
nil
Insert empty braces.
t
Insert empty braces, leave point between the braces.
other symbols
Call the symbol as a function. You can define your own hook, or use one of the predefined argument hooks.
list
If the car is a string, insert it as a prompt and the next element as initial input. Otherwise, call the car of the list with the remaining elements as arguments.
vector
Optional argument. If it has more than one element, parse it as a list, otherwise parse the only element as above. Use square brackets instead of curly braces, and is not inserted on empty user input.

A lot of argument hooks has already been defined. The first argument to all hooks are 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-argument-conditional-hook
Implement if EXPR THEN ELSE. If EXPR evaluate to true, parse THEN as an argument list, else parse ELSE as an argument list.
TeX-argument-literal-hook
Insert its arguments into the buffer. Used for specifying extra syntax for a macro.
TeX-argument-free-hook
Parse its arguments but use no braces when they are inserted.
TeX-argument-eval-hook
Evaluate arguments and insert the result in the buffer.
TeX-argument-file-hook
Prompt for a tex or sty filename, and use it without the extension. Run the file hooks defined for it.
TeX-argument-label-hook
Prompt for a label completing with known labels.
TeX-argument-macro-hook
Prompt for a TeX macro with completion.
TeX-argument-environment-hook
Prompt for a LaTeX environment with completion.
TeX-argument-cite-hook
Prompt for a BibTeX citation.
TeX-argument-counter-hook
Prompt for a LaTeX counter.
TeX-argument-savebox-hook
Prompt for a LaTeX savebox.
TeX-argument-file-hook
Prompt for a filename in the current directory, and use it without the extension.
TeX-argument-input-file-hook
Prompt for a filename in the current directory, and use it without the extension. Run the style hooks for the file.
TeX-argument-define-label-hook
Prompt for a label completing with known labels. Add label to list of defined labels.
TeX-argument-define-macro-hook
Prompt for a TeX macro with completion. Add macro to list of defined macros.
TeX-argument-define-environment-hook
Prompt for a LaTeX environment with completion. Add environment to list of defined environments.
TeX-argument-define-cite-hook
Prompt for a BibTeX citation.
TeX-argument-define-counter-hook
Prompt for a LaTeX counter.
TeX-argument-define-savebox-hook
Prompt for a LaTeX savebox.
TeX-argument-corner-hook
Prompt for a LaTeX side or corner position with completion.
TeX-argument-lr-hook
Prompt for a LaTeX side with completion.
TeX-argument-tb-hook
Prompt for a LaTeX side with completion.
TeX-argument-pagestyle-hook
Prompt for a LaTeX pagestyle with completion.
TeX-argument-verb-hook
Prompt for delimiter and text.
TeX-argument-pair-hook
Insert a pair of number, use arguments for prompt. The numbers are surrounded by parenthesizes and separated with a comma.
TeX-argument-size-hook
Insert width and height as a pair. No arguments.
TeX-argument-coordinate-hook
Insert x and y coordinate as a pair. No arguments.

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 set it.


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