Skip to main content

5.6.1 A Simple Style File

Here is a simple example of a style file.

;;; book.el - Special code for book style.  (TeX-add-style-hook  "book"  (lambda ()     (LaTeX-largest-level-set "chapter"))  LaTeX-dialect) 

The example is from the AUCTeX sources and is loaded for any LaTeX document using the book document class (or style before LaTeX2e). The file specifies that the largest kind of section in such a document 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 are executed. The actual files will only be evaluated once, but the hooks will be called for each buffer using the style file.

Note that the basename of the style file and the name of the style hook should usually be identical.

function TeX-add-style-hook* style hook \&optional dialect-expr*​

Add hook to the list of functions to run when we use the TeX file style and the current dialect is one in the set derived from dialect-expr. When dialect-expr is omitted, then hook is allowed to be run whatever the current dialect is.

dialect-expr may be one of:

  • A symbol indicating a singleton containing one basic TeX dialect, this symbol shall be selected among:

    :latex​

    For all files in LaTeX mode, or any mode derived thereof.

    :bibtex​

    For all files in BibTeX mode, or any mode derived thereof.

    :texinfo​

    For all files in Texinfo mode.

    :plain-tex​

    For all files in plain-TeX mode, or any mode derived thereof.

    :context​

    For all files in ConTeXt mode.

    :classopt​

    For class options of LaTeX document. This is provided as pseudo-dialect for style hooks associated with class options.

  • A logical expression like:

    (or dialect-expression1 … dialect-expression_n)​

    For union of the sets of dialects corresponding to dialect-expression1 through dialect-expression_n

    (and dialect-expression1 … dialect-expression_n)​

    For intersection of the sets of dialects corresponding to dialect-expression1 through dialect-expression_n

    (nor dialect-expression1 … dialect-expression_n)​

    For complement of the union sets of dialects corresponding to dialect-expression1 through dialect-expression_n relatively to the set of all supported dialects

    (not dialect-expr)​

    For complement set of dialect corresponding to dialect-expr relatively to the set of all supported dialects

In case of adding a style hook for LaTeX, when calling function TeX-add-style-hook it is thought more futureproof for argument dialect-expr to pass constant LaTeX-dialect currently defined to :latex, rather than passing :latex directly.

constant LaTeX-dialect​

Default dialect for use with function TeX-add-style-hook for argument dialect-expr when the hook is to be run only on LaTeX file, or any mode derived thereof.