5.6.2 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 are a few examples from βlatex.el
β.
(TeX-add-style-hook "latex" (lambda () (TeX-add-symbols '("arabic" TeX-arg-counter) '("label" TeX-arg-define-label) '("ref" TeX-arg-ref) '("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" ]))))
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 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 choose the one with the longest definition (i.e. the one with the most arguments).
Thus, to overwrite
'("tref" 1) ; one argument
you can specify
'("tref" TeX-arg-ref 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.
You can use the following types of specifiers for arguments:
string
β
Use the string as a prompt to prompt for the argument.
number
β
Insert that many braces, leave point inside the first. 0 and -1 are special. 0 means that no braces are inserted. -1 means that braces are inserted around the macro and an active region (e.g. β{\tiny foo}
β). If there is no active region, no braces are inserted.
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 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
β
Implements if EXPR THEN ELSE. If EXPR evaluates to true, parse THEN as an argument list, else parse ELSE as an argument list.
TeX-arg-literal
β
Insert its arguments into the buffer. Used for specifying extra syntax for a macro.
TeX-arg-free
β
Parse its arguments but use no braces when they are inserted.
TeX-arg-eval
β
Evaluate arguments and insert the result in the buffer.
TeX-arg-label
β
Prompt for a label completing with known labels. If RefTeX is active, prompt for the reference format.
TeX-arg-ref
β
Prompt for a label completing with known labels. If RefTeX is active, do not prompt for the reference format. Usually, reference macros should use this function instead of TeX-arg-label
.
TeX-arg-index-tag
β
Prompt for an index tag. This is the name of an index, not the entry.
TeX-arg-index
β
Prompt for an index entry completing with known entries.
TeX-arg-length
β
Prompt for a LaTeX length completing with known lengths.
TeX-arg-macro
β
Prompt for a TeX macro with completion.
TeX-arg-date
β
Prompt for a date, defaulting to the current date. The format of the date is specified by the TeX-date-format
option. If you want to change the format when the βbabel
β package is loaded with a specific language, set TeX-date-format
inside the appropriate language hook, for details see European.
TeX-arg-version
β
Prompt for the version of a file, using as initial input the current date.
TeX-arg-environment
β
Prompt for a LaTeX environment with completion.
TeX-arg-cite
β
Prompt for a BibTeX citation. If the variable TeX-arg-cite-note-p
is non-nil, ask also for optional note in citations.
TeX-arg-counter
β
Prompt for a LaTeX counter completing with known counters.
TeX-arg-savebox
β
Prompt for a LaTeX savebox completing with known saveboxes.
TeX-arg-file
β
Prompt for a filename in the current directory, and use it with the extension.
TeX-arg-file-name
β
Prompt for a filename and use as initial input the name of the file being visited in the current buffer, with extension.
TeX-arg-file-name-sans-extension
β
Prompt for a filename and use as initial input the name of the file being visited in the current buffer, without extension.
TeX-arg-input-file
β
Prompt for the name of an input file in TeXβs search path, and use it without the extension. Run the style hooks for the file. (Note that the behavior (type of prompt and inserted file name) of the function can be controlled by the variable TeX-arg-input-file-search
.)
TeX-arg-define-label
β
Prompt for a label completing with known labels. Add label to list of defined labels.
TeX-arg-define-length
β
Prompt for a LaTeX length completing with known lengths. Add length to list of defined lengths.
TeX-arg-define-macro
β
Prompt for a TeX macro with completion. Add macro to list of defined macros.
TeX-arg-define-environment
β
Prompt for a LaTeX environment with completion. Add environment to list of defined environments.
TeX-arg-define-cite
β
Prompt for a BibTeX citation.
TeX-arg-define-counter
β
Prompt for a LaTeX counter.
TeX-arg-define-savebox
β
Prompt for a LaTeX savebox.
TeX-arg-document
β
Prompt for a LaTeX document class, using LaTeX-default-style
as default value and LaTeX-default-options
as default list of options. If the variable TeX-arg-input-file-search
is t, you will be able to complete with all LaTeX classes available on your system, otherwise classes listed in the variable LaTeX-style-list
will be used for completion. It is also provided completion for options of many common classes.
LaTeX-arg-usepackage
β
Prompt for LaTeX packages. If the variable TeX-arg-input-file-search
is t, you will be able to complete with all LaTeX packages available on your system. It is also provided completion for options of many common packages.
TeX-arg-bibstyle
β
Prompt for a BibTeX style file completing with all style available on your system.
TeX-arg-bibliography
β
Prompt for BibTeX database files completing with all databases available on your system.
TeX-arg-corner
β
Prompt for a LaTeX side or corner position with completion.
TeX-arg-lr
β
Prompt for a LaTeX side with completion.
TeX-arg-tb
β
Prompt for a LaTeX side with completion.
TeX-arg-pagestyle
β
Prompt for a LaTeX pagestyle with completion.
TeX-arg-verb
β
Prompt for delimiter and text.
TeX-arg-verb-delim-or-brace
β
Prompt for delimiter and text. This function is similar to TeX-arg-verb
, but is intended for macros which take their argument enclosed in delimiters or in braces.
TeX-arg-pair
β
Insert a pair of numbers, use arguments for prompt. The numbers are surrounded by parentheses and separated with a comma.
TeX-arg-size
β
Insert width and height as a pair. No arguments.
TeX-arg-coordinate
β
Insert x and y coordinates as a pair. No arguments.
LaTeX-arg-author
β
Prompt for document author, using LaTeX-default-author
as initial input.
TeX-read-key-val
β
Prompt for a key=value list of options and return them.
TeX-arg-key-val
β
Prompt for a key=value list of options and insert it as a TeX macro argument.
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.
Some packages provide macros that are rarely useful to non-expert users. Those should be marked as expert macros using TeX-declare-expert-macros
.
function
TeX-declare-expert-macros* style
macros
...*β
Declare MACROS as expert macros of STYLE.
Expert macros are completed depending on βTeX-complete-expert-commandsβ.