3.1.1 Fontification of macros
Highlighting of macros can be customized by adapting keyword lists which can be found in the customization group font-latex-keywords
.
Three types of macros can be handled differently with respect to fontification:
- Commands of the form β
\foo[bar]{baz}
β which consist of the macro itself, optional arguments in square brackets and mandatory arguments in curly braces. For the command itself the facefont-lock-keyword-face
will be used and for the optional arguments the facefont-lock-variable-name-face
. The face applied to the mandatory argument depends on the macro class represented by the respective built-in variables. - Declaration macros of the form β
{\foo text}
β which consist of the macro which may be enclosed in a TeX group together with text to be affected by the macro. In case a TeX group is present, the macro will get the facefont-lock-keyword-face
and the text will get the face configured for the respective macro class. If no TeX group is present, the latter face will be applied to the macro itself. - Simple macros of the form β
\foo
β which do not have any arguments or groupings. The respective face will be applied to the macro itself.
Customization variables for β\foo[bar]{baz}
β type macros allow both the macro name and the sequence of arguments to be specified. The latter is done with a string which can contain the characters
β*
β
indicating the existence of a starred variant for the macro,
β[
ββ
for optional arguments in brackets,
β{
ββ
for mandatory arguments in braces,
β\
ββ
for mandatory arguments consisting of a single macro and
β|
ββ
as a prefix indicating that two alternatives are following.
For example the specifier for β\documentclass
β would be β[{
β because the macro has one optional followed by one mandatory argument. The specifier for β\newcommand
β would be β*|{\[[{
β because there is a starred variant, the mandatory argument following the macro name can be a macro or a TeX group which can be followed by two optional arguments and the last token is a mandatory argument in braces.
Customization variables for the β{\foo text}
β and β\foo
β types are simple lists of strings where each entry is a macro name (without the leading backslash).
General macro classesβ
font-latex provides keyword lists for different macro classes which are described in the following table:
font-latex-match-function-keywords
β
Keywords for macros defining or related to functions, like β\newcommand
β.\
Type: β\macro[...]{...}
β\
Face: font-lock-function-name-face
font-latex-match-reference-keywords
β
Keywords for macros defining or related to references, like β\ref
β.\
Type: β\macro[...]{...}
β\
Face: font-lock-constant-face
font-latex-match-textual-keywords
β
Keywords for macros specifying textual content, like β\caption
β.\
Type: β\macro[...]{...}
β\
Face: font-lock-type-face
font-latex-match-variable-keywords
β
Keywords for macros defining or related to variables, like β\setlength
β.\
Type: β\macro[...]{...}
β\
Face: font-lock-variable-name-face
font-latex-match-warning-keywords
β
Keywords for important macros, e.g. affecting line or page break, like β\clearpage
β.\
Type: β\macro
β\
Face: font-latex-warning-face
Sectioning commandsβ
Sectioning commands are macros like β\chapter
β or β\section
β. For these commands there are two fontification schemes which may be selected by customizing the variable font-latex-fontify-sectioning
.
user option
font-latex-fontify-sectioningβ
Per default sectioning commands will be shown in a larger, proportional font, which corresponds to a number for this variable. The font size varies with the sectioning level, e.g. β\part
β (font-latex-sectioning-0-face
) has a larger font than β\paragraph
β (font-latex-sectioning-5-face
). Typically, values from 1.05 to 1.3 for font-latex-fontify-sectioning
give best results, depending on your font setup. If you rather like to use the base font and a different color, set the variable to the symbol βcolor
β. In this case the face font-lock-type-face
will be used to fontify the argument of the sectioning commands.
You can make font-latex aware of your own sectioning commands be adding them to the keyword lists: font-latex-match-sectioning-0-keywords
(font-latex-sectioning-0-face
) β¦ font-latex-match-sectioning-5-keywords
(font-latex-sectioning-5-face
).
Related to sectioning there is special support for slide titles which may be fontified with the face font-latex-slide-title-face
. You can add macros which should appear in this face by customizing the variable font-latex-match-slide-title-keywords
.
Commands for changing fontsβ
LaTeX provides various macros for changing fonts or font attributes. For example, you can select an italic font with β\textit{...}
β or bold with β\textbf{...}
β. An alternative way to specify these fonts is to use special macros in TeX groups, like β{\itshape ...}
β for italics and β{\bfseries ...}
β for bold. As mentioned above, we call the former variants commands and the latter declarations.
Besides the macros for changing fonts provided by LaTeX there is an infinite number of other macrosβeither defined by yourself for logical markup or defined by macro packagesβwhich affect the font in the typeset text. While LaTeXβs built-in macros and macros of packages known by AUCTeX are already handled by font-latex, different keyword lists per type style and macro type are provided for entering your own macros which are listed in the table below.
font-latex-match-bold-command-keywords
β
Keywords for commands specifying a bold type style.\
Face: font-latex-bold-face
font-latex-match-italic-command-keywords
β
Keywords for commands specifying an italic font.\
Face: font-latex-italic-face
font-latex-match-math-command-keywords
β
Keywords for commands specifying a math font.\
Face: font-latex-math-face
font-latex-match-type-command-keywords
β
Keywords for commands specifying a typewriter font.\
Face: font-lock-type-face
font-latex-match-bold-declaration-keywords
β
Keywords for declarations specifying a bold type style.\
Face: font-latex-bold-face
font-latex-match-italic-declaration-keywords
β
Keywords for declarations specifying an italic font.\
Face: font-latex-italic-face
font-latex-match-type-declaration-keywords
β
Keywords for declarations specifying a typewriter font.\
Face: font-latex-type-face
Deactivating defaults of built-in keyword classesβ
font-latex ships with predefined lists of keywords for the classes described above. You can disable these defaults per class by customizing the variable font-latex-deactivated-keyword-classes
. This is a list of strings for keyword classes to be deactivated. Valid entries are "warning", "variable", "biblatexnoarg", "biblatex", "reference", "function" , "sectioning-0", "sectioning-1", "sectioning-2", "sectioning-3", "sectioning-4", "sectioning-5", "slide-title", "textual", "bold-command", "italic-command", "math-command", "type-command", "bold-declaration", "italic-declaration", "type-declaration".
You can also get rid of certain keywords only. For example if you want to remove highlighting of footnotes as references you can put the following stanza into your init file:
(eval-after-load "font-latex" '(setq-default font-latex-match-reference-keywords-local (remove (assoc-string "footnote" font-latex-match-reference-keywords-local) font-latex-match-reference-keywords-local)))
But note that this means fiddling with font-latexβs internals and is not guaranteed to work in future versions of font-latex.
User-defined keyword classesβ
In case the customization options explained above do not suffice for your needs, you can specify your own keyword classes by customizing the variable font-latex-user-keyword-classes
.
user option
font-latex-user-keyword-classesβ
Every keyword class consists of four parts, a name, a list of keywords, a face and a specifier for the type of macros to be highlighted.
When adding new entries, you have to use unique values for the class names, i.e. they must not clash with names of the built-in keyword classes or other names given by you. Additionally the names must not contain spaces.
The list of keywords defines which commands and declarations should be covered by the keyword class. A keyword can either be a simple command name omitting the leading backslash or a list consisting of the command name and a string specifying the sequence of arguments for the command.
The face argument can either be an existing face or face attributes made by you.
There are three alternatives for the type of keywordsββCommand with arguments", βDeclaration inside TeX group" and βCommand without arguments"βwhich correspond with the macro types explained above.