     [file version.texi not included]
     [file macros.texi not included]

AUCTeX
******

This manual may be copied under the conditions spelled out in Copying this Manual.

AUCTeX is an integrated environment for editing LaTeX, ConTeXt, docTeX, Texinfo, and TeX files.

Although AUCTeX contains a large number of features, there are no reasons to despair.  You can continue to write TeX and LaTeX documents the way you are used to, and only start using the multiple features in small steps.  AUCTeX is not monolithic, each feature described in this manual is useful by itself, but together they provide an environment where you will make very few LaTeX errors, and makes it easy to find the errors that may slip through anyway.

It is a good idea to make a printout of AUCTeX's reference card tex-ref.tex or one of its typeset versions.

If you want to make AUCTeX aware of style files and multi-file documents right away, insert the following in your .emacs file.

     (setq TeX-auto-save t)
     (setq TeX-parse-self t)
     (setq-default TeX-master nil)

Another thing you should enable is RefTeX, a comprehensive solution for managing cross references, bibliographies, indices, document navigation and a few other things.  (see Installation (The RefTeX manual))

For detailed information about the previewlatex subsystem of AUCTeX, see Introduction (The previewlatex Manual).

There is a mailing list for general discussion about AUCTeX: write a mail with ``subscribe'' in the subject to auctex-request@gnu.org to join it.  Send contributions to auctex@gnu.org.

Bug reports should go to bug-auctex@gnu.org, suggestions for new features, and pleas for help should go to either auctex-devel@gnu.org (the AUCTeX developers), or to auctex@gnu.org if they might have general interest.  Please use the command M-x TeX-submit-bug-report RET to report bugs if possible.  You can subscribe to a low-volume announcement list by sending ``subscribe'' in the subject of a mail to info-auctex-request@gnu.org.

Copying
*******

AUCTeX primarily consists of Lisp files for Emacs (and XEmacs), but there are also installation scripts and files and TeX support files. All of those are free; this means that everyone is free to use them and free to redistribute them on a free basis.  The files of AUCTeX are not in the public domain; they are copyrighted and there are restrictions on their distribution, but these restrictions are designed to permit everything that a good cooperating citizen would want to do.  What is not allowed is to try to prevent others from further sharing any version of these programs that they might get from you.

Specifically, we want to make sure that you have the right to give away copies of the files that constitute AUCTeX, that you receive source code or else can get it if you want it, that you can change these files or use pieces of them in new free programs, and that you know you can do these things.

To make sure that everyone has such rights, we have to forbid you to deprive anyone else of these rights.  For example, if you distribute copies of parts of AUCTeX, you must give the recipients all the rights that you have.  You must make sure that they, too, receive or can get the source code.  And you must tell them their rights.

Also, for our own protection, we must make certain that everyone finds out that there is no warranty for AUCTeX.  If any parts are modified by someone else and passed on, we want their recipients to know that what they have is not what we distributed, so that any problems introduced by others will not reflect on our reputation.

The precise conditions of the licenses for the files currently being distributed as part of AUCTeX are found in the General Public Licenses that accompany them.  This manual specifically is covered by the GNU Free Documentation License (see Copying this Manual).

Introduction
************

     [file intro.texi not included]

     [file install.texi not included]

     [file quickstart.texi not included]

Editing the Document Source
***************************

The most commonly used commands/macros of AUCTeX are those which simply insert templates for often used TeX, LaTeX, or ConTeXt constructs, like font changes, handling of environments, etc.  These features are very simple, and easy to learn, and help you avoid mistakes like mismatched braces, or \begin{}-\end{} pairs.

Apart from that this chapter contains a description of some features for entering more specialized sorts of text, for formatting the source by indenting and filling and for navigating through the document.

Insertion of Quotes, Dollars, and Braces
========================================

Quotation Marks
---------------

In TeX, literal double quotes "like this" are seldom used, instead two single quotes are used ``like this''.  To help you insert these efficiently, AUCTeX allows you to continue to press " to insert two single quotes.  To get a literal double quote, press " twice.

 -- Command: TeX-insert-quote COUNT
     (") Insert the appropriate quote marks for TeX.

     Inserts the value of TeX-open-quote (normally ``) or TeX-close-quote (normally '') depending on the context. With prefix argument, always inserts " characters.

 -- User Option: TeX-open-quote
     String inserted by typing " to open a quotation. (see European, for language-specific quotation mark insertion.)

 -- User Option: TeX-close-quote
     String inserted by typing " to close a quotation. (see European, for language-specific quotation mark insertion.)

 -- User Option: TeX-quote-after-quote
     Determines the behavior of ".  If it is non-nil, typing " will insert a literal double quote.  The respective values of TeX-open-quote and TeX-close-quote will be inserted after typing " once again.

The babel package provides special support for the requirements of typesetting quotation marks in many different languages.  If you use this package, either directly or by loading a language-specific style file, you should also use the special commands for quote insertion instead of the standard quotes shown above.  AUCTeX is able to recognize several of these languages and will change quote insertion accordingly.  See European, for details about this feature and how to control it.

In case you are using the csquotes package, you should customize LaTeX-csquotes-open-quote, LaTeX-csquotes-close-quote and LaTeX-csquotes-quote-after-quote.  The quotation characters will only be used if both variables---LaTeX-csquotes-open-quote and LaTeX-csquotes-close-quote---are non-empty strings.  But then the csquotes-related values will take precedence over the language-specific ones.

Dollar Signs
------------

In AUCTeX, dollar signs should match like they do in TeX.  This has been partially implemented, we assume dollar signs always match within a paragraph.  The first $ you insert in a paragraph will do nothing special.  The second $ will match the first.  This will be indicated by moving the cursor temporarily over the first dollar sign.

 -- Command: TeX-insert-dollar ARG
     ($) Insert dollar sign.

     Show matching dollar sign if this dollar sign end the TeX math mode. Ensure double dollar signs match up correctly by inserting extra dollar signs when needed if TeX-math-close-double-dollar is non-nil.

     With optional ARG, insert that many dollar signs.

 -- User Option: TeX-math-close-double-dollar
     Control the insertion of double dollar signs for delimiting display math.  (Note that you should not use double dollar signs in LaTeX because this practice can lead to wrong spacing in typeset documents.) If the variable is non-nil and you enter a dollar sign that matches a double dollar sign $$ AUCTeX will automatically insert two dollar signs.

Braces
------

To avoid unbalanced braces, it is useful to insert them pairwise.  You can do this by typing C-c {.

 -- Command: TeX-insert-braces
     (C-c {) Make a pair of braces and position the cursor to type inside of them.  If there is an active region, put braces around it and leave point after the closing brace.

Inserting Font Specifiers
=========================

Perhaps the most used keyboard commands of AUCTeX are the short-cuts available for easy insertion of font changing macros.

If you give an argument (that is, type C-u) to the font command, the innermost font will be replaced, i.e. the font in the TeX group around point will be changed.  The following table shows the available commands, with -!- indicating the position where the text will be inserted.

C-c C-f C-b
     Insert bold face \textbf{-!-} text.

C-c C-f C-i
     Insert italics \textit{-!-} text.

C-c C-f C-e
     Insert emphasized \emph{-!-} text.

C-c C-f C-s
     Insert slanted \textsl{-!-} text.

C-c C-f C-r
     Insert roman \textrm{-!-} text.

C-c C-f C-f
     Insert sans serif \textsf{-!-} text.

C-c C-f C-t
     Insert typewriter \texttt{-!-} text.

C-c C-f C-c
     Insert SMALL CAPS \textsc{-!-} text.

C-c C-f C-d
     Delete the innermost font specification containing point.

 -- Command: TeX-font replace what
     (C-c C-f) Insert template for font change command.

     If REPLACE is not nil, replace current font.  WHAT determines the font to use, as specified by TeX-font-list.

 -- User Option: TeX-font-list
     List of fonts used by TeX-font.

     Each entry is a list with three elements.  The first element is the key to activate the font.  The second element is the string to insert before point, and the third element is the string to insert after point.  An optional fourth element means always replace if not nil.

 -- User Option: LaTeX-font-list
     List of fonts used by TeX-font in LaTeX mode.  It has the same structure as TeX-font-list.

Inserting chapters, sections, etc.
==================================

Insertion of sectioning macros, that is \chapter, \section, \subsection, etc. and accompanying \label's may be eased by using C-c C-s.  This command is highly customizable, the following describes the default behavior.

When invoking you will be asked for a section macro to insert.  An appropriate default is automatically selected by AUCTeX, that is either: at the top of the document; the top level sectioning for that document style, and any other place: The same as the last occurring sectioning command.

Next, you will be asked for the actual name of that section, and last you will be asked for a label to be associated with that section. The label will be prefixed by the value specified in LaTeX-section-hook.

 -- Command: LaTeX-section ARG
     (C-c C-s) Insert a sectioning command.

     Determine the type of section to be inserted, by the argument ARG.

       * If ARG is nil or missing, use the current level.

       * If ARG is a list (selected by C-u), go downward one level.

       * If ARG is negative, go up that many levels.

       * If ARG is positive or zero, use absolute level:

            + 0 : part

            + 1 : chapter

            + 2 : section

            + 3 : subsection

            + 4 : subsubsection

            + 5 : paragraph

            + 6 : subparagraph

     The following variables can be set to customize the function.

     LaTeX-section-hook
          Hooks to be run when inserting a section.

     LaTeX-section-label
          Prefix to all section references.

The precise behavior of LaTeX-section is defined by the contents of LaTeX-section-hook.

 -- User Option: LaTeX-section-hook
     List of hooks to run when a new section is inserted.

     The following variables are set before the hooks are run

     level
          Numeric section level, default set by prefix arg to LaTeX-section.

     name
          Name of the sectioning command, derived from LEVEL.

     title
          The title of the section, default to an empty string.

     toc
          Entry for the table of contents list, default nil.

     done-mark
          Position of point afterwards, default nil meaning after the inserted text.

     A number of hooks are already defined.  Most likely, you will be able to get the desired functionality by choosing from these hooks.

     LaTeX-section-heading
          Query the user about the name of the sectioning command.  Modifies LEVEL and NAME.

     LaTeX-section-title
          Query the user about the title of the section. Modifies TITLE.

     LaTeX-section-toc
          Query the user for the toc entry.  Modifies TOC.

     LaTeX-section-section
          Insert LaTeX section command according to NAME, TITLE, and TOC.  If TOC is nil, no toc entry is inserted.  If TOC or TITLE are empty strings, DONE-MARK will be placed at the point they should be inserted.

     LaTeX-section-label
          Insert a label after the section command.  Controlled by the variable LaTeX-section-label.

     To get a full featured LaTeX-section command, insert

          (setq LaTeX-section-hook
                '(LaTeX-section-heading
          	LaTeX-section-title
          	LaTeX-section-toc
          	LaTeX-section-section
          	LaTeX-section-label))

     in your .emacs file.

The behavior of LaTeX-section-label is determined by the variable LaTeX-section-label.

 -- User Option: LaTeX-section-label
     Default prefix when asking for a label.

     If it is a string, it is used unchanged for all kinds of sections. If it is nil, no label is inserted. If it is a list, the list is searched for a member whose car is equal to the name of the sectioning command being inserted.  The cdr is then used as the prefix.  If the name is not found, or if the cdr is nil, no label is inserted.

     By default, chapters have a prefix of cha: while sections and subsections have a prefix of sec:.  Labels are not automatically inserted for other types of sections.

Inserting Environment Templates
===============================

A large apparatus is available that supports insertions of environments, that is \begin{} --- \end{} pairs.

AUCTeX is aware of most of the actual environments available in a specific document.  This is achieved by examining your \documentclass command, and consulting a precompiled list of environments available in a large number of styles.

You insert an environment with C-c C-e, and select an environment type.  Depending on the environment, AUCTeX may ask more questions about the optional parts of the selected environment type.  With C-u C-c C-e you will change the current environment.

 -- Command: LaTeX-environment ARG
     (C-c C-e)  AUCTeX will prompt you for an environment to insert.  At this prompt, you may press TAB or SPC to complete a partially written name, and/or to get a list of available environments.  After selection of a specific environment AUCTeX may prompt you for further specifications.

     If the optional argument ARG is not-nil (i.e. you have given a prefix argument), the current environment is modified and no new environment is inserted.

As a default selection, AUCTeX will suggest the environment last inserted or, as the first choice the value of the variable LaTeX-default-environment.

 -- User Option: LaTeX-default-environment
     Default environment to insert when invoking LaTeX-environment first time.

If the document is empty, or the cursor is placed at the top of the document, AUCTeX will default to insert a `document' environment.

Most of these are described further in the following sections, and you may easily specify more.  See Customizing Environments.

You can close the current environment with C-c ], but we suggest that you use C-c C-e to insert complete environments instead.

 -- Command: LaTeX-close-environment
     (C-c ]) Insert an \end that matches the current environment.

Equations
---------

When inserting equation-like environments, the \label will have a default prefix, which is controlled by the following variables:

 -- User Option: LaTeX-equation-label
     Prefix to use for `equation' labels.

 -- User Option: LaTeX-eqnarray-label
     Prefix to use for `eqnarray' labels.

 -- User Option: LaTeX-amsmath-label
     Prefix to use for amsmath equation labels.  Amsmath equations include align, alignat, xalignat, aligned, flalign and gather.

Floats
------

Figures and tables (i.e., floats) may also be inserted using AUCTeX. After choosing either `figure' or `table' in the environment list described above, you will be prompted for a number of additional things.

float position
     This is the optional argument of float environments that controls how they are placed in the final document.  In LaTeX this is a sequence of the letters htbp as described in the LaTeX manual.  The value will default to the value of LaTeX-float.

caption
     This is the caption of the float.  The default is to insert the caption at the bottom of the float.  You can specify floats where the caption should be placed at the top with LaTeX-top-caption-list.

label
     The label of this float.  The label will have a default prefix, which is controlled by the variables LaTeX-figure-label and LaTeX-table-label.

Moreover, you will be asked if you want the contents of the float environment to be horizontally centered.  Upon a positive answer a \centering macro will be inserted at the beginning of the float environment.

 -- User Option: LaTeX-float
     Default placement for floats.

 -- User Option: LaTeX-figure-label
     Prefix to use for figure labels.

 -- User Option: LaTeX-table-label
     Prefix to use for table labels.

 -- User Option: LaTeX-top-caption-list
     List of float environments with top caption.

Itemize-like Environments
-------------------------

In an itemize-like environment, nodes (i.e., \items) may be inserted using C-c LFD.

 -- Command: LaTeX-insert-item
     (C-c LFD) Close the current item, move to the next line and insert an appropriate \item for the current environment. That is, `itemize' and `enumerate' will have \item  inserted, while `description' will have \item[] inserted.

Tabular-like Environments
-------------------------

When inserting Tabular-like environments, that is, `tabular' `array' etc., you will be prompted for a template for that environment. Related variables:

 -- User Option: LaTeX-default-format
     Default format string for array and tabular environments.

 -- User Option: LaTeX-default-position
     Default position string for array and tabular environments.  If nil, act like the empty string is given, but don't prompt for a position.

Customizing Environments
------------------------

See Adding Environments, for how to customize the list of known environments.

Entering Mathematics
====================

TeX is written by a mathematician, and has always contained good support for formatting mathematical text.  AUCTeX supports this tradition, by offering a special minor mode for entering text with many mathematical symbols.  You can enter this mode by typing C-c ~.

 -- Command: LaTeX-math-mode
     (C-c ~) Toggle LaTeX Math mode.  This is a minor mode rebinding the key LaTeX-math-abbrev-prefix to allow easy typing of mathematical symbols.  ` will read a character from the keyboard, and insert the symbol as specified in LaTeX-math-default and LaTeX-math-list.  If given a prefix argument, the symbol will be surrounded by dollar signs.

You can use another prefix key (instead of `) by  setting the variable LaTeX-math-abbrev-prefix.

To enable LaTeX Math mode by default, add the following in your .emacs file:

     (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)

 -- User Option: LaTeX-math-abbrev-prefix
     A string containing the prefix of LaTeX-math-mode commands; This value defaults to `.

     The string has to be a key or key sequence in a format understood by the kbd macro.  This corresponds to the syntax usually used in the manuals for Emacs Emacs Lisp.

The variable LaTeX-math-list allows you to add your own mappings.

 -- User Option: LaTeX-math-list
     A list containing user-defined keys and commands to be used in LaTeX Math mode.  Each entry should be a list of two to four elements.

     First, the key to be used after LaTeX-math-abbrev-prefix for macro insertion.  If it is nil, the symbol has no associated keystroke (it is available in the menu, though).

     Second, a string representing the name of the macro (without a leading backslash.)

     Third, a string representing the name of a submenu the command should be added to.  Use a list of strings in case of nested menus.

     Fourth, the position of a Unicode character to be displayed in the menu alongside the macro name.  This is an integer value.

 -- User Option: LaTeX-math-menu-unicode
     Whether the LaTeX menu should try using Unicode for effect.  Your Emacs built must be able to display include Unicode characters in menus for this feature.

AUCTeX's reference card tex-ref.tex includes a list of all math mode commands.

AUCTeX can help you write subscripts and superscripts in math constructs by automatically inserting a pair of braces after typing _ or ^ respectively and putting point between the braces. In order to enable this feature, set the variable TeX-electric-sub-and-superscript to a non-nil value.

 -- User Option: TeX-electric-sub-and-superscript
     If non-nil, insert braces after typing ^ and _ in math mode.

Completion
==========

Emacs lisp programmers probably know the lisp-complete-symbol command, usually bound to M-TAB.  Users of the wonderful ispell mode know and love the ispell-complete-word command from that package.  Similarly, AUCTeX has a TeX-complete-symbol command, by default bound to M-TAB which is equivalent to M-C-i.  Using TeX-complete-symbol makes it easier to type and remember the names of long LaTeX macros.

In order to use TeX-complete-symbol, you should write a backslash and the start of the macro.  Typing M-TAB will now complete as much of the macro, as it unambiguously can.  For example, if you type `\renewc' and then M-TAB, it will expand to `\renewcommand'.

 -- Command: TeX-complete-symbol
     (M-TAB)  Complete TeX symbol before point.

A more direct way to insert a macro is with TeX-insert-macro, bound to C-c C-m which is equivalent to C-c RET.  It has the advantage over completion that it knows about the argument of most standard LaTeX macros, and will prompt for them.  It also knows about the type of the arguments, so it will for example give completion for the argument to \include.  Some examples are listed below.

 -- Command: TeX-insert-macro
     (C-c C-m or C-c RET) Prompt (with completion) for the name of a TeX macro, and if AUCTeX knows the macro, prompt for each argument.

As a default selection, AUCTeX will suggest the macro last inserted or, as the first choice the value of the variable TeX-default-macro.

 -- User Option: TeX-insert-macro-default-style
     Specifies whether TeX-insert-macro will ask for all optional arguments.

     If set to the symbol show-optional-args, TeX-insert-macro asks for optional arguments of TeX macros.  If set to mandatory-args-only, TeX-insert-macro asks only for mandatory arguments.  When TeX-insert-macro is called with prefix argument (C-u), it's the other way round.

     Note that for some macros, there are special mechanisms, e.g. LaTeX-includegraphics-options-alist.

 -- User Option: TeX-default-macro
     Default macro to insert when invoking TeX-insert-macro first time.

A faster alternative is to bind the function TeX-electric-macro to \.  This can be done by setting the variable TeX-electric-escape

 -- User Option: TeX-electric-escape
     If this is non-nil when AUCTeX is loaded, the TeX escape character \ will be bound to TeX-electric-macro

The difference between TeX-insert-macro and TeX-electric-macro is that space will complete and exit from the minibuffer in TeX-electric-macro.  Use TAB if you merely want to complete.

 -- Command: TeX-electric-macro
     Prompt (with completion) for the name of a TeX macro, and if AUCTeX knows the macro, prompt for each argument. Space will complete and exit.

By default AUCTeX will put an empty set braces {} after a macro with no arguments to stop it from eating the next whitespace. This can be stopped by entering LaTeX-math-mode, see Mathematics, or by setting TeX-insert-braces to nil.

 -- User Option: TeX-insert-braces
     If non-nil, append a empty pair of braces after inserting a macro.

Completions work because AUCTeX can analyze TeX files, and store symbols in Emacs Lisp files for later retrieval.  See Automatic, for more information.

AUCTeX will also make completion for many macro arguments, for example existing labels when you enter a \ref macro with TeX-insert-macro or TeX-electric-macro, and BibTeX entries when you enter a \cite macro.  For this kind of completion to work, parsing must be enabled as described in see Parsing Files.  For \cite you must also make sure that the BibTeX files have been saved at least once after you enabled automatic parsing on save, and that the basename of the BibTeX file does not conflict with the basename of one of TeX files.

Commenting
==========

It is often necessary to comment out temporarily a region of TeX or LaTeX code.  This can be done with the commands C-c ; and C-c %.  C-c ; will comment out all lines in the current region, while C-c % will comment out the current paragraph. Type C-c ; again to uncomment all lines of a commented region, or C-c % again to uncomment all comment lines around point. These commands will insert or remove a single % respectively.

 -- Command: TeX-comment-or-uncomment-region
     (C-c ;) Add or remove % from the beginning of each line in the current region.  Uncommenting works only if the region encloses solely commented lines.  If AUCTeX should not try to guess if the region should be commented or uncommented the commands TeX-comment-region and TeX-uncomment-region can be used to explicitly comment or uncomment the region in concern.

 -- Command: TeX-comment-or-uncomment-paragraph
     (C-c %) Add or remove % from the beginning of each line in the current paragraph.  When removing % characters the paragraph is considered to consist of all preceding and succeeding lines starting with a %, until the first non-comment line.

Indenting
=========

Indentation means the addition of whitespace at the beginning of lines to reflect special syntactical constructs.  This makes it easier to see the structure of the document, and to catch errors such as a missing closing brace.  Thus, the indentation is done for precisely the same reasons that you would indent ordinary computer programs.

Indentation is done by LaTeX environments and by TeX groups, that is the body of an environment is indented by the value of LaTeX-indent-level (default 2).  Also, items of an `itemize-like' environment are indented by the value of LaTeX-item-indent, default -2.  (Items are identified with the help of LaTeX-item-regexp.)  If more environments are nested, they are indented `accumulated' just like most programming languages usually are seen indented in nested constructs.

You can explicitely indent single lines, usually by pressing TAB, or marked regions by calling indent-region on it.  If you have auto-fill-mode enabled and a line is broken while you type it, Emacs automatically cares about the indentation in the following line. If you want to have a similar behavior upon typing RET, you can customize the variable TeX-newline-function and change the default of newline which does no indentation to newline-and-indent which indents the new line or reindent-then-newline-and-indent which indents both the current and the new line.

There are certain LaTeX environments which should be indented in a special way, like tabular or verbatim.  Those environments may be specified in the variable LaTeX-indent-environment-list together with their special indentation functions.  Taking the verbatim environment as an example you can see that current-indentation is used as the indentation function.  This will stop AUCTeX from doing any indentation in the environment if you hit TAB for example.

There are environments in LaTeX-indent-environment-list which do not bring a special indentation function with them.  This is due to the fact that first the respective functions are not implemented yet and second that filling will be disabled for the specified environments. This shall prevent the source code from being messed up by accidently filling those environments with the standard filling routine.  If you think that providing special filling routines for such environments would be an appropriate and challenging task for you, you are invited to contribute. (see Filling, for further information about the filling functionality)

The check for the indentation function may be enabled or disabled by customizing the variable LaTeX-indent-environment-check.

As a side note with regard to formatting special environments: Newer Emacsen include align.el and therefore provide some support for formatting tabular and tabbing environments with the function align-current which will nicely align columns in the source code.

AUCTeX is able to format commented parts of your code just as any other part.  This means LaTeX environments and TeX groups in comments will be indented syntactically correct if the variable LaTeX-syntactic-comments is set to t.  If you disable it, comments will be filled like normal text and no syntactic indentation will be done.

Following you will find a list of most commands and variables related to indenting with a small summary in each case:

TAB
     LaTeX-indent-line will indent the current line.

LFD
     newline-and-indent inserts a new line (much like RET) and moves the cursor to an appropriate position by the left margin.

     Most keyboards nowadays lack a linefeed key and C-j may be tedious to type.  Therefore you can customize AUCTeX to perform indentation upon typing RET as well.  The respective option is called TeX-newline-function.

C-j
     Alias for LFD

 -- User Option: LaTeX-indent-environment-list
     List of environments with special indentation.  The second element in each entry is the function to calculate the indentation level in columns.

     The filling code currently cannot handle tabular-like environments which will be completely messed-up if you try to format them.  This is why most of these environments are included in this customization option without a special indentation function.  This will prevent that they get filled.

 -- User Option: LaTeX-indent-level
     Number of spaces to add to the indentation for each \begin not matched by a \end.

 -- User Option: LaTeX-item-indent
     Number of spaces to add to the indentation for \item's in list environments.

 -- User Option: TeX-brace-indent-level
     Number of spaces to add to the indentation for each { not matched by a }.

 -- User Option: LaTeX-syntactic-comments
     If non-nil comments will be filled and indented according to LaTeX syntax.  Otherwise they will be filled like normal text.

 -- User Option: TeX-newline-function
     Used to specify the function which is called when RET is pressed. This will normally be newline which simply inserts a new line. In case you want to have AUCTeX do indentation as well when you press RET, use the built-in functions newline-and-indent or reindent-then-newline-and-indent.  The former inserts a new line and indents the following line, i.e. it moves the cursor to the right position and therefore acts as if you pressed LFD.  The latter function additionally indents the current line.  If you choose Other, you can specify your own fancy function to be called when RET is pressed.

Filling
=======

Filling deals with the insertion of line breaks to prevent lines from becoming wider than what is specified in fill-column.  The linebreaks will be inserted automatically if auto-fill-mode is enabled.  In this case the source is not only filled but also indented automatically as you write it.

auto-fill-mode can be enabled for AUCTeX by calling turn-on-auto-fill in one of the hooks AUCTeX is running. See Modes and Hooks.  As an example, if you want to enable auto-fill-mode in LaTeX-mode, put the following into your init file:

     (add-hook 'LaTeX-mode-hook 'turn-on-auto-fill)

You can manually fill explicitely marked regions, paragraphs, environments, complete sections, or the whole buffer.  (Note that manual filling in AUCTeX will indent the start of the region to be filled in contrast to many other Emacs modes.)

There are some syntactical constructs which are handled specially with regard to filling.  These are so-called code comments and paragraph commands.

Code comments are comments preceded by code or text in the same line. Upon filling a region, code comments themselves will not get filled. Filling is done from the start of the region to the line with the code comment and continues after it.  In order to prevent overfull lines in the source code, a linebreak will be inserted before the last non-comment word by default.  This can be changed by customizing LaTeX-fill-break-before-code-comments.  If you have overfull lines with code comments you can fill those explicitely by calling LaTeX-fill-paragraph or pressing M-q with the cursor positioned on them.  This will add linebreaks in the comment and indent subsequent comment lines to the column of the comment in the first line of the code comment.  In this special case M-q only acts on the current line and not on the whole paragraph.

Lines with \par are treated similarly to code comments, i.e. \par will be treated as paragraph boundary which should not be followed by other code or text.  But it is not treated as a real paragraph boundary like an empty line where filling a paragraph would stop.

Paragraph commands like \section or \noindent (the list of commands is defined by LaTeX-paragraph-commands) are often to be placed in their own line(s).  This means they should not be consecuted with any preceding or following adjacent lines of text.  AUCTeX will prevent this from happening if you do not put any text except another macro after the end of the last brace of the respective macro.  If there is other text after the macro, AUCTeX regards this as a sign that the macro is part of the following paragraph.

Here are some examples:

     \begin{quote}
       text text text text

     \begin{quote}\label{foo}
       text text text text

If you press M-q on the first line in both examples, nothing will change.  But if you write

     \begin{quote} text
       text text text text

and press M-q, you will get

     \begin{quote} text text text text text

Besides code comments and paragraph commands, another speciality of filling in AUCTeX involves commented lines.  You should be aware that these comments are treated as islands in the rest of the LaTeX code if syntactic filling is enabled.  This means, for example, if you try to fill an environment with LaTeX-fill-environment and have the cursor placed on a commented line which does not have a surrounding environment inside the comment, AUCTeX will report an error.

The relevant commands and variables with regard to filling are:

C-c C-q C-p
     LaTeX-fill-paragraph will fill and indent the current paragraph.

M-q
     Alias for C-c C-q C-p

C-c C-q C-e
     LaTeX-fill-environment will fill and indent the current environment.  This may e.g. be the `document' environment, in which case the entire document will be formatted.

C-c C-q C-s
     LaTeX-fill-section will fill and indent the current logical sectional unit.

C-c C-q C-r
     LaTeX-fill-region will fill and indent the current region.

 -- User Option: LaTeX-fill-break-at-separators
     List of separators before or after which respectively linebreaks will be inserted if they do not fit into one line.  The separators can be curly braces, brackets, switches for inline math ($, \(, \)) and switches for display math (\[, \]).  Such formatting can be useful to make macros and math more visible or to prevent overfull lines in the LaTeX source in case a package for displaying formatted TeX output inside the Emacs buffer, like preview-latex, is used.

 -- User Option: LaTeX-fill-break-before-code-comments
     Code comments are comments preceded by some other text in the same line. When a paragraph containing such a comment is to be filled, the comment start will be seen as a border after which no line breaks will be inserted in the same line.  If the option LaTeX-fill-break-before-code-comments is enabled (which is the default) and the comment does not fit into the line, a line break will be inserted before the last non-comment word to minimize the chance that the line becomes overfull.

Controlling Screen Display
**************************

It is often desirable to get visual help of what markup code in a text actually does whithout having to decipher it explicitely.  For this purpose Emacs and AUCTeX provide font locking (also known as syntax highlighting) which visually sets off markup code like macros or environments by using different colors or fonts.  For example text to be typeset in italics can be displayed with an italic font in the editor as well, or labels and references get their own distinct color.

While font locking helps you grasp the purpose of markup code and separate markup from content, the markup code can still be distracting. AUCTeX lets you hide those parts and show them again at request with its built-in support for hiding macros and environments which we call folding here.

Besides folding of macros and environments, AUCTeX provides support for Emacs' outline mode which lets you narrow the buffer content to certain sections of your text by hiding the parts not belonging to these sections.

Font Locking
============

Font locking is supposed to improve readability of the source code by highlighting certain keywords with different colors or fonts.  It thereby lets you recognize the function of markup code to a certain extent without having to read the markup command.  For general information on controlling font locking with Emacs' Font Lock mode, see Font Lock Mode (GNU Emacs Manual).

 -- User Option: TeX-install-font-lock
     Once font locking is enabled globally or for the major modes provided by AUCTeX, the font locking patterns and functionality of fontlatex are activated by default.  You can switch to a different font locking scheme or disable font locking in AUCTeX by customizing the variable TeX-install-font-lock.

     Besides fontlatex AUCTeX ships with a scheme which is derived from Emacs' default LaTeX mode and activated by choosing tex-font-setup.  Be aware that this scheme is not coupled with AUCTeX's style system and not the focus of development.  Therefore and due to fontlatex being much more feature-rich the following explanations will only cover fontlatex.

     In case you want to hook in your own fontification scheme, you can choose other and insert the name of the function which sets up your font locking patterns.  If you want to disable fontification in AUCTeX completely, choose ignore.

fontlatex provides many options for customization which are accessible with M-x customize-group RET font-latex RET.  For this description the various options are explained in conceptional groups.

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:

 1. 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 face font-lock-keyword-face will be used and for the optional arguments the face font-lock-variable-name-face.  The face applied to the mandatory argument depends on the macro class represented by the respective built-in variables.

 2. 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 face font-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.

 3. 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
---------------------

fontlatex 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 fontlatex 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 fontlatex, 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
-------------------------------------------------

fontlatex 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", "reference", "function" , "sectioning-0", "sectioning-1", "sectioning-2", "sectioning-3", "sectioning-4", "sectioning-5", "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 "footnote" font-latex-match-reference-keywords-local)))

But note that this means fiddling with fontlatex's internals and is not guaranteed to work in future versions of fontlatex.

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 font specifications made by you.  (The latter option is not available on XEmacs.)

     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.

Fontification of quotes
-----------------------

Text in quotation marks is displayed with the face font-latex-string-face.  Besides the various forms of opening and closing double and single quotation marks, so-called guillemets (<<, >>) can be used for quoting.  Because there are two styles of using them---French style: << text >>; German style: >>text<<---you can customize the variable font-latex-quotes to tell fontlatex which type you are using if the correct value cannot be derived from document properties.

 -- User Option: font-latex-quotes
     The default value of font-latex-quotes is auto which means that fontlatex will try to derive the correct type of quotation mark matching from document properties like the language option supplied to the babel LaTeX package.

     If the automatic detection fails for you and you mostly use one specific style you can set it to a specific language-dependent value as well. Set the value to german if you are using >>German quotes<< and to french if you are using << French quotes >>.  fontlatex will recognize the different ways these quotes can be given in your source code, i.e. ("<, ">), (<<, >>) and the respective 8-bit variants.

     If you set font-latex-quotes to nil, quoted content will not be fontified.

Fontification of mathematical constructs
----------------------------------------

In LaTeX mathematics can be indicated by a variety of different methods: toggles (like dollar signs), macros and environments.  Math constructs known by fontlatex are displayed with the face font-latex-math-face.  Support for dollar signs and shorthands like \(...\) or \[...\] is built-in and not customizable. Support for other math macros and environments can be adapted by customizing the variables font-latex-match-math-command-keywords and font-latex-math-environments respectively.

In order to make math constructs more readable, fontlatex displays subscript and superscript parts in a smaller font and raised or lowered respectively.  This fontification feature can be controlled with the variables font-latex-fontify-script and font-latex-script-display.

 -- User Option: font-latex-fontify-script
     If non-nil, fontify subscript and superscript strings.

     Note that this feature is not available on XEmacs, for which it is disabled per default.  In GNU Emacs raising and lowering is not enabled for versions 21.3 and before due to it working not properly.

 -- User Option: font-latex-script-display
     Display specification for subscript and superscript content.  The car is used for subscript, the cdr is used for superscript.  The feature is implemented using so-called display properties.  For information on what exactly to specify for the values, see Other Display Specifications (GNU Emacs Lisp Reference Manual).

Verbatim macros and environments
--------------------------------

Usually it is not desirable to have content to be typeset verbatim highlighted according to LaTeX syntax.  Therefore this content will be fontified uniformly with the face font-latex-verbatim-face.

fontlatex differentiates three different types of verbatim constructs for fontification.  Macros with special characters like | as delimiters, macros with braces, and environments.  Which macros and environments are recognized is controlled by the variables LaTeX-verbatim-macros-with-delims, LaTeX-verbatim-macros-with-braces, and LaTeX-verbatim-environments respectively.

Faces used by fontlatex
-----------------------

In case you want to change the colors and fonts used by fontlatex please refer to the faces mentioned in the explanations above and use M-x customize-face RET <face> RET.  All faces defined by fontlatex are accessible through a customization group by typing M-x customize-group RET font-latex-highlighting-faces RET.

Known fontification problems
----------------------------

In certain cases the fontification machinery fails to interpret buffer contents correctly.  This can lead to color bleed, i.e. large parts of a buffer get fontified with an inappropriate face.  A typical situation for this to happen is the use of a dollar sign ($) in a verbatim macro or environment.  If fontlatex is not aware of the verbatim construct, it assumes the dollar sign to be a toggle for mathematics and fontifies the following buffer content with the respective face until it finds a closing dollar sign or till the end of the buffer.

As a remedy you can make the verbatim construct known to fontlatex, see Verbatim content.  If this is not possible, you can insert a commented dollar sign (%$) at the next suitable end of line as a quick workaround.

Folding Macros and Environments
===============================

A popular complaint about markup languages like TeX and LaTeX is that there is too much clutter in the source text and that one cannot focus well on the content.  There are macros where you are only interested in the content they are enclosing, like font specifiers where the content might already be fontified in a special way by font locking. Or macros the content of which you only want to see when actually editing it, like footnotes or citations.  Similarly you might find certain environments or comments distracting when trying to concentrate on the body of your document.

With AUCTeX's folding functionality you can collapse those items and replace them by a fixed string, the content of one of their arguments, or a mixture of both.  If you want to make the original text visible again in order to view or edit it, move point sideways onto the placeholder (also called display string) or left-click with the mouse pointer on it.  (The latter is currently only supported on Emacs.)  The macro or environment will unfold automatically, stay open as long as point is inside of it and collapse again once you move point out of it. (Note that folding of environments currently does not work in every AUCTeX mode.)

In order to use this feature, you have to activate TeX-fold-mode which will activate the auto-reveal feature and the necessary commands to hide and show macros and environments.  You can activate the mode in a certain buffer by typing the command M-x TeX-fold-mode RET or using the keyboard shortcut C-c C-o C-f.  If you want to use it every time you edit a LaTeX document, add it to a hook:

     (add-hook 'LaTeX-mode-hook (lambda ()
                                  (TeX-fold-mode 1)))

If it should be activated in all AUCTeX modes, use TeX-mode-hook instead of LaTeX-mode-hook.

Once the mode is active there are several commands available to hide and show macros, environments and comments:

 -- Command: TeX-fold-buffer
     (C-c C-o C-b) Hide all foldable items in the current buffer according to the setting of TeX-fold-type-list.

     If you want to have this done automatically every time you open a file, add it to a hook and make sure the function is called after font locking is set up for the buffer.  The following code should accomplish this:

          (add-hook 'find-file-hook 'TeX-fold-buffer t)

     The command can be used any time to refresh the whole buffer and fold any new macros and environments which were inserted after the last invocation of the command.

 -- User Option: TeX-fold-type-list
     List of symbols determining the item classes to consider for folding. This can be macros, environments and comments.  Per default only macros and environments are folded.

 -- User Option: TeX-fold-force-fontify
     In order for all folded content to get the right faces, the whole buffer has to be fontified before folding is carried out. TeX-fold-buffer therefore will force fontification of unfontified regions.  As this will prolong the time folding takes, you can prevent forced fontification by customizing the variable TeX-fold-force-fontify.

 -- User Option: TeX-fold-preserve-comments
     By default items found in comments will be folded.  If your comments often contain unfinished code this might lead to problems.  Give this variable a non-nil value and foldable items in your comments will be left alone.

 -- Command: TeX-fold-region
     (C-c C-o C-r) Hide all configured macros in the marked region.

 -- Command: TeX-fold-paragraph
     (C-c C-o C-p) Hide all configured macros in the paragraph containing point.

 -- Command: TeX-fold-macro
     (C-c C-o C-m) Hide the macro on which point currently is located. If the name of the macro is found in TeX-fold-macro-spec-list, the respective display string will be shown instead.  If it is not found, the name of the macro in sqare brackets or the default string for unspecified macros (TeX-fold-unspec-macro-display-string) will be shown, depending on the value of the variable TeX-fold-unspec-use-name.

 -- Command: TeX-fold-env
     (C-c C-o C-e) Hide the environment on which point currently is located.  The behavior regarding the display string is analogous to TeX-fold-macro and determined by the variables TeX-fold-env-spec-list and TeX-fold-unspec-env-display-string respectively.

 -- Command: TeX-fold-math
     Hide the math macro on which point currently is located.  If the name of the macro is found in TeX-fold-math-spec-list, the respective display string will be shown instead.  If it is not found, the name of the macro in sqare brackets or the default string for unspecified macros (TeX-fold-unspec-macro-display-string) will be shown, depending on the value of the variable TeX-fold-unspec-use-name.

 -- Command: TeX-fold-comment
     (C-c C-o C-c) Hide the comment point is located on.

 -- Command: TeX-fold-clearout-buffer
     (C-c C-o b) Permanently unfold all macros and environments in the current buffer.

 -- Command: TeX-fold-clearout-region
     (C-c C-o r) Permanently unfold all macros and environments in the marked region.

 -- Command: TeX-fold-clearout-paragraph
     (C-c C-o p) Permanently unfold all macros and environments in the paragraph containing point.

 -- Command: TeX-fold-clearout-item
     (C-c C-o i) Permanently show the macro or environment on which point currently is located.  In contrast to temporarily opening the macro when point is moved sideways onto it, the macro will be permanently unfolded and will not collapse again once point is leaving it.

 -- Command: TeX-fold-dwim
     (C-c C-o C-o) Hide or show items according to the current context. If there is folded content, unfold it.  If there is a marked region, fold all configured content in this region.  If there is no folded content but a macro or environment, fold it.

In case you want to use a different prefix than C-c C-o for these commands you can customize the variable TeX-fold-command-prefix. (Note that this will not change the key binding for activating the mode.)

The commands above will only take macros or environments into consideration which are specified in the variables TeX-fold-macro-spec-list or TeX-fold-env-spec-list respectively.

 -- User Option: TeX-fold-macro-spec-list
     List of replacement specifiers and macros to fold.  The specifier can be a string, an integer or a function symbol.

     If you specify a string, it will be used as a display replacement for the whole macro.  Numbers in braces, brackets, parens or angle brackets will be replaced by the respective macro argument.  For example {1} will be replaced by the first mandatory argument of the macro.  One can also define alternatives within the specifier which are used if an argument is not found.  Alternatives are separated by ||.  They are most useful with optional arguments.  As an example, the default specifier for \item is [1]:||* which means that if there is an optional argument, its value is shown followed by a colon.  If there is no optional argument, only an asterisk is used as the display string.

     If you specify a number as the first element, the content of the respective mandatory argument of a LaTeX macro will be used as the placeholder.

     If the first element is a function symbol, the function will be called with all mandatory arguments of the macro and the result of the function call will be used as a replacement for the macro.

     The placeholder is made by copying the text from the buffer together with its properties, i.e. its face as well.  If fontification has not happened when this is done (e.g. because of lazy font locking) the intended fontification will not show up.  As a workaround you can leave Emacs idle a few seconds and wait for stealth font locking to finish before you fold the buffer.  Or you just re-fold the buffer with TeX-fold-buffer when you notice a wrong fontification.

 -- User Option: TeX-fold-env-spec-list
     List of display strings or argument numbers and environments to fold. Argument numbers refer to the \begin statement.  That means if you have e.g. \begin{tabularx}{\linewidth}{XXX} ... \end{tabularx} and specify 3 as the argument number, the resulting display string will be ``XXX''.

 -- User Option: TeX-fold-math-spec-list
     List of display strings and math macros to fold.

The variables TeX-fold-macro-spec-list, TeX-fold-env-spec-list, and TeX-fold-math-spec-list apply to any AUCTeX mode.  If you want to make settings which are only applied to LaTeX mode, you can use the mode-specific variables LaTeX-fold-macro-spec-list, LaTeX-fold-env-spec-list, and LaTeX-fold-math-spec-list

 -- User Option: TeX-fold-unspec-macro-display-string
     Default display string for macros which are not specified in TeX-fold-macro-spec-list.

 -- User Option: TeX-fold-unspec-env-display-string
     Default display string for environments which are not specified in TeX-fold-env-spec-list.

 -- User Option: TeX-fold-unspec-use-name
     If non-nil the name of the macro or environment surrounded by square brackets is used as display string, otherwise the defaults specified in TeX-fold-unspec-macro-display-string or TeX-fold-unspec-env-display-string respectively.

When you hover with the mouse pointer over folded content, its original text will be shown in a tooltip or the echo area depending on Tooltip mode being activate.  In order to avoid exorbitantly big tooltips and to cater for the limited space in the echo area the content will be cropped after a certain amount of characters defined by the variable TeX-fold-help-echo-max-length.

 -- User Option: TeX-fold-help-echo-max-length
     Maximum length of original text displayed in a tooltip or the echo area for folded content.  Set it to zero in order to disable this feature.

Outlining the Document
======================

AUCTeX supports the standard outline minor mode using LaTeX/ConTeXt sectioning commands as header lines.  See Outline Mode (GNU Emacs Manual).

You can add your own headings by setting the variable TeX-outline-extra.

 -- Variable: TeX-outline-extra
     List of extra TeX outline levels.

     Each element is a list with two entries.  The first entry is the regular expression matching a header, and the second is the level of the header. A ^ is automatically prepended to the regular expressions in the list, so they must match text at the beginning of the line.

     See LaTeX-section-list or ConTeXt-INTERFACE-section-list for existing header levels.

The following example add \item and \bibliography headers, with \bibliography at the same outline level as \section, and \item being below \subparagraph.

     (setq TeX-outline-extra
           '(("[ \t]*\\\\\\(bib\\)?item\\b" 7)
     	("\\\\bibliography\\b" 2)))

You may want to check out the unbundled out-xtra package for even better outline support.  It is available from your favorite emacs lisp archive.

Starting Processors, Viewers and Other Programs
***********************************************

The most powerful features of AUCTeX may be those allowing you to run TeX, LaTeX, ConTeXt and other external commands like BibTeX and makeindex from within Emacs, viewing and printing the results, and moreover allowing you to debug your documents.

AUCTeX comes with a special tool bar for TeX and LaTeX which provides buttons for the most important commands.  You can enable or disable it by customizing the options plain-TeX-enable-toolbar and LaTeX-enable-toolbar in the TeX-tool-bar customization group.

Executing Commands
==================

Formatting the document with TeX, LaTeX or ConTeXt, viewing with a previewer, printing the document, running BibTeX, making an index, or checking the document with lacheck or chktex all require running an external command.

Starting a Command on a Document or Region
------------------------------------------

There are two ways to run an external command, you can either run it on the current document with TeX-command-master, or on the current region with TeX-command-region.  A special case of running TeX on a region is TeX-command-buffer which differs from TeX-command-master if the current buffer is not its own master file.

 -- Command: TeX-command-master
     (C-c C-c)  Query the user for a command, and run it on the master file associated with the current buffer.  The name of the master file is controlled by the variable TeX-master.  The available commands are controlled by the variable TeX-command-list.

 -- Command: TeX-command-region
     (C-c C-r) Query the user for a command, and run it on the contents of the selected region.  The region contents are written into the region file, after extracting the header and trailer from the master file.  If mark is inactive (which can happen with Transient Mark mode), use the old region.  See also the command TeX-pin-region about how to fix a region.

     The name of the region file is controlled by the variable TeX-region.  The name of the master file is controlled by the variable TeX-master.  The header is all text up to the line matching the regular expression TeX-header-end.  The trailer is all text from the line matching the regular expression TeX-trailer-start.  The available commands are controlled by the variable TeX-command-list.

 -- Command: TeX-command-buffer
     (C-c C-b) Query the user for a command, and apply it to the contents of the current buffer.  The buffer contents are written into the region file, after extracting the header and trailer from the master file.  The command is then actually run on the region file.  See above for details.

 -- User Option: TeX-region
     The name of the file for temporarily storing the text when formatting the current region.

 -- User Option: TeX-header-end
     A regular expression matching the end of the header.  By default, this is \begin{document} in LaTeX mode and %**end of header in TeX mode.

 -- User Option: TeX-trailer-start
     A regular expression matching the start of the trailer.  By default, this is \end{document} in LaTeX mode and \bye in TeX mode.

If you want to change the values of TeX-header-end and TeX-trailer-start you can do this for all files by setting the variables in a mode hook or per file by specifying them as file variables (see File Variables (The Emacs Editor)).

 -- Command: TeX-pin-region
     (C-c C-t C-r) If you don't have a mode like Transient Mark mode active, where marks get disabled automatically, the region would need to get properly set before each call to TeX-command-region.  If you fix the current region with C-c C-t C-r, then it will get used for more commands even though mark and point may change.  An explicitly activated mark, however, will always define a new region when calling TeX-command-region.

AUCTeX will allow one process for each document, plus one process for the region file to be active at the same time.  Thus, if you are editing N different documents, you can have N plus one processes running at the same time.  If the last process you started was on the region, the commands described in Debugging and Control will work on that process, otherwise they will work on the process associated with the current document.

Selecting and Executing a Command
---------------------------------

Once you started the command selection with C-c C-c, C-c C-s or C-c C-b you will be prompted for the type of command. AUCTeX will try to guess which command is appropriate in the given situation and propose it as default.  Usually this is a processor like TeX or LaTeX if the document was changed or a viewer if the document was just typeset.  Other commands can be selected in the minibuffer with completion support by typing TAB.

The available commands are defined by the variable TeX-command-list.  Per default it includes commands for typesetting the document (e.g. LaTeX), for viewing the output (View), for printing (Print), for generating an index (Index) or for spell checking (Spell) to name but a few. You can also add your own commands by adding entries to TeX-command-list.  Refer to its doc string for information about its syntax.  You might also want to look at TeX-expand-list to learn about the expanders you can use in TeX-command-list.

Note that the default of the variable occasionally changes.  Therefore it is advisable to add to the list rather than overwriting it.  You can do this with a call to add-to-list in your init file.  For example, if you wanted to add a command for running a program called foo on the master or region file, you could do this with the following form.

     (eval-after-load "tex"
       '(add-to-list 'TeX-command-list
     		'("Foo" "foo %s" TeX-run-command t t :help "Run foo") t))

As mentioned before, AUCTeX will try to guess what command you want to invoke.  If you want to use another command than TeX, LaTeX or whatever processor AUCTeX thinks is appropriate for the current mode, set the variable TeX-command-default.  You can do this for all files by setting it in a mode hook or per file by specifying it as a file variable (see File Variables (The Emacs Editor)).

 -- User Option: TeX-command-default
     The default command to run in this buffer.  Must be an entry in TeX-command-list.

After confirming a command to execute, AUCTeX will try to save any buffers related to the document, and check if the document needs to be reformatted.  If the variable TeX-save-query is non-nil, AUCTeX will query before saving each file.  By default AUCTeX will check emacs buffers associated with files in the current directory, in one of the TeX-macro-private directories, and in the TeX-macro-global directories.  You can change this by setting the variable TeX-check-path.

 -- User Option: TeX-check-path
     Directory path to search for dependencies.

     If nil, just check the current file. Used when checking if any files have changed.

Options for TeX Processors
--------------------------

There are some options you can customize affecting which processors are invoked or the way this is done and which output they produce as a result.  These options control if DVI or PDF output should be produced, if TeX should be started in interactive or nonstop mode, if source specials or a SyncTeX file should be produced for making inverse and forward search possible or which TeX engine should be used instead of regular TeX, like PDFTeX, Omega or XeTeX.

 -- Command: TeX-PDF-mode
     (C-c C-t C-p) This command toggles the PDF mode of AUCTeX, a buffer-local minor mode.  You can customize TeX-PDF-mode to give it a different default.  The default is used when AUCTeX does not have additional clue about what a document might want.  This option usually results in calling either PDFTeX or ordinary TeX.

 -- User Option: TeX-DVI-via-PDFTeX
     If this is set, DVI will also be produced by calling PDFTeX, setting \pdfoutput=0.  This makes it possible to use PDFTeX features like character protrusion even when producing DVI files.  Contemporary TeX distributions do this anyway, so that you need not enable the option within AUCTeX.

 -- Command: TeX-interactive-mode
     (C-c C-t C-i) This command toggles the interactive mode of AUCTeX, a global minor mode.  You can customize TeX-interactive-mode to give it a different default.  In interactive mode, TeX will pause with an error prompt when errors are encountered and wait for the user to type something.

 -- Command: TeX-source-correlate-mode
     (C-c C-t C-s) Toggles support for forward and inverse search. Forward search refers to jumping to the place in the previewed document corresponding to where point is located in the document source and inverse search to the other way round.  See I/O Correlation.

     You can permanently activate TeX-source-correlate-mode by customizing the variable TeX-source-correlate-mode.  There is a bunch of customization options for the mode, use M-x customize-group RET TeX-view RET to find out more.

     AUCTeX is aware of three different means to do I/O correlation: source specials (only DVI output), the pdfsync LaTeX package (only PDF output) and SyncTeX.  The choice between source specials and SyncTeX can be controlled with the variable TeX-source-correlate-method.

     Should you use source specials it has to be stressed very strongly however, that source specials can cause differences in page breaks and spacing, can seriously interfere with various packages and should thus never be used for the final version of a document. In particular, fine-tuning the page breaks should be done with source specials switched off.

AUCTeX also allows you to easily select different TeX engines for processing, either by using the entries in the TeXing Options submenu below the Command menu or by calling the function TeX-engine-set.  These eventually set the variable TeX-engine which you can also modify directly.

 -- User Option: TeX-engine
     This variable allows you to choose which TeX engine should be used for typesetting the document, i.e. the executables which will be used when you invoke the TeX or LaTeX commands.  The value should be one of the symbols defined in TeX-engine-alist-builtin or TeX-engine-alist.  The symbols default, xetex, luatex and omega are available from the built-in list.

Note that TeX-engine is buffer-local, so setting the variable directly or via the above mentioned menu or function will not take effect in other buffers.  If you want to activate an engine for all AUCTeX modes, set TeX-engine in your init file, e.g. by using M-x customize-variable <RET>.  If you want to activate it for a certain AUCTeX mode only, set the variable in the respective mode hook.  If you want to activate it for certain files, set it through file variables (see File Variables (The Emacs Editor)).

Should you need to change the executable names related to the different engine settings, there are some variables you can tweak.  Those are TeX-command, LaTeX-command, TeX-Omega-command, LaTeX-Omega-command, ConTeXt-engine and ConTeXt-Omega-engine.  The rest of the executables is defined directly in TeX-engine-alist-builtin.  If you want to override an entry from that, add an entry to TeX-engine-alist that starts with the same symbol as that the entry in the built-in list and specify the executables you want to use instead.  You can also add entries to TeX-engine-alist in order to add support for engines not covered per default.

 -- User Option: TeX-engine-alist
     Alist of TeX engines and associated commands.  Each entry is a list with a maximum of five elements.  The first element is a symbol used to identify the engine.  The second is a string describing the engine.  The third is the command to be used for plain TeX.  The fourth is the command to be used for LaTeX.  The fifth is the command to be used for the --engine parameter of ConTeXt's texexec program.  Each command can either be a variable or a string.  An empty string or nil means there is no command available.

You can customize AUCTeX to show the processor output as it is produced.

 -- User Option: TeX-show-compilation
     If non-nil, the output of TeX compilation is shown in another window.

Viewing the Formatted Output
============================

AUCTeX allows you to start external programs for previewing the formatted output of your document.

Starting Viewers
----------------

Viewers are normally invoked by pressing C-c C-c once the document is formatted, which will propose the View command, or by activating the respective entry in the Command menu.  Alternatively you can type C-c C-v which calls the function TeX-view.

 -- Command: TeX-view
     (C-c C-v) Start a viewer without confirmation.  The viewer is started either on a region or the master file, depending on the last command issued.  This is especially useful for jumping to the location corresponding to point in the viewer when using TeX-source-correlate-mode.

AUCTeX will try to guess which type of viewer (DVI, PostScript or PDF) has to be used and what options are to be passed over to it.  This decision is based on the output files present in the working directory as well as the class and style options used in the document.  For example, if there is a DVI file in your working directory, a DVI viewer will be invoked.  In case of a PDF file it will be a PDF viewer.  If you specified a special paper format like a5paper or use the landscape option, this will be passed to the viewer by the appropriate options. Especially some DVI viewers depend on this kind of information in order to display your document correctly.  In case you are using pstricks or psfrag in your document, a DVI viewer cannot display the contents correctly and a PostScript viewer will be invoked instead.

The association between the tests for the conditions mentioned above and the viewers is made in the variable TeX-view-program-selection. Therefore this variable is the starting point for customization if you want to use other viewers than the ones suggested by default.

 -- User Option: TeX-view-program-selection
     This is a list of predicates and viewers which is evaluated from front to back in order to find out which viewer to call under the given conditions.  In the first element of each list item you can reference one or more predicates defined in TeX-view-predicate-list or TeX-view-predicate-list-builtin.  In the second element you can reference a viewer defined in TeX-view-program-list or TeX-view-program-list-builtin.  The viewer of the first item with a positively evaluated predicate is selected.

So TeX-view-program-selection only contains references to the actual implementations of predicates and viewer commands respectively which can be found elsewhere.  AUCTeX comes with a set of preconfigured predicates and viewer commands which are stored in the variables TeX-view-predicate-list-builtin and TeX-view-program-list-builtin respectively.  If you are not satisfied with those and want to overwrite one of them or add your own definitions, you can do so via the variables TeX-view-predicate-list and TeX-view-program-list.

 -- User Option: TeX-view-predicate-list
     This is a list of predicates for viewer selection and invocation.  The first element of each list item is a symbol and the second element a Lisp form to be evaluated.  The form should return nil if the predicate is not fulfilled.

     A built-in predicate from TeX-view-predicate-list-builtin can be overwritten by defining a new predicate with the same symbol.

 -- User Option: TeX-view-program-list
     This is a list of viewer specifications each consisting of a symbolic name and either a command line or a function to be invoked when the viewer is called.  If a command line is used, parts of it can be conditionalized by prefixing them with predicates from TeX-view-predicate-list or TeX-view-predicate-list-builtin.  (See the doc string for the exact format to use.)  The command line can also contain placeholders as defined in TeX-expand-list which are expanded before the viewer is called.

     A built-in viewer spec from TeX-view-program-list-builtin can be overwritten by defining a new viewer spec with the same name.

Note that the viewer selection and invocation as described above will only work if certain default settings in AUCTeX are intact.  For one, the whole viewer selection machinery will only be triggered if the %V expander in TeX-expand-list is unchanged.  So if you have trouble with the viewer invocation you might check if there is an older customization of the variable in place.  In addition, the use of a function in TeX-view-program-list only works if the View command in TeX-command-list makes use of the hook TeX-run-discard-or-function.

Note also that the implementation described above replaces an older one which was less flexible.  This old implementation works with the variables TeX-output-view-style and TeX-view-style which are used to associate file types and style options with viewers.  If desired you can reactivate it by using the placeholder %vv for the View command in TeX-command-list.  Note however, that it is bound to be removed from AUCTeX once the new implementation proved to be satisfactory.  For the time being, find a short description of the mentioned customization options below.

 -- User Option: TeX-output-view-style
     List of output file extensions, style options and view options.  Each item of the list consists of three elements.  If the first element (a regular expression) matches the output file extension, and the second element (a regular expression) matches the name of one of the style options, any occurrence of the string %V in a command in TeX-command-list will be replaced with the third element.

 -- User Option: TeX-view-style
     List of style options and view options.  This is the predecessor of TeX-output-view-style which does not provide the possibility to specify output file extensions.  It is used as a fallback in case none of the alternatives specified in TeX-output-view-style match.  In case none of the entries in TeX-view-style match either, no suggestion for a viewer is made.

Forward and Inverse Search
--------------------------

Forward and inverse search refer to the correlation between the document source in the editor and the typeset document in the viewer.  Forward search allows you to jump to the place in the previewed document corresponding to a certain line in the document source and inverse search vice versa.

AUCTeX supports three methods for forward and inverse search: source specials (only DVI output), the pdfsync LaTeX package (only PDF output) and SyncTeX (any type of output).  If you want to make use of forward and inverse searching with source specials or SyncTeX, switch on TeX-source-correlate-mode.  See Processor Options, on how to do that.  The use of the pdfsync package is detected automatically if document parsing is enabled.

Forward search happens automatically upon calling the viewer, e.g. by typing C-c C-v (TeX-view).  This will open the viewer or bring it to front and display the output page corresponding to the position of point in the source file.  AUCTeX will automatically pass the necessary command line options to the viewer for this to happen.

Upon opening the viewer you will be asked if you want to start a server process (Gnuserv or Emacs server) which is necessary for inverse search. This happens only if there is no server running already.  You can customize the variable TeX-source-correlate-start-server to inhibit the question and always or never start the server respectively.

 -- User Option: TeX-source-correlate-start-server
     If TeX-source-correlate-mode is active and a viewer is invoked, the default behavior is to ask if a server process should be started. Set this variable to t if the question should be inhibited and the server should always be started.  Set it to nil if the server should never be started.  Inverse search will not be available in the latter case.

Inverse search, i.e. jumping to the part of your document source in Emacs corresponding to a certain position in the viewer, is triggered from the viewer, typically by a mouse click.  Refer to the documentation of your viewer to find out how it has to be configured and what you have to do exactly.  In xdvi you normally have to use C-down-mouse-1.

Catching the errors
===================

Once you've formatted your document you may `debug' it, i.e. browse through the errors (La)TeX reported.

 -- Command: TeX-next-error
     (C-c `)  Go to the next error reported by TeX.  The view will be split in two, with the cursor placed as close as possible to the error in the top view.  In the bottom view, the error message will be displayed along with some explanatory text.

Normally AUCTeX will only report real errors, but you may as well ask it to report `bad boxes' and warnings as well.

 -- Command: TeX-toggle-debug-bad-boxes
     (C-c C-t C-b) Toggle whether AUCTeX should stop at bad boxes (i.e. overfull and underfull boxes) as well as normal errors.

 -- Command: TeX-toggle-debug-warnings
     (C-c C-t C-w) Toggle whether AUCTeX should stop at warnings as well as normal errors.

As default, AUCTeX will display a special help buffer containing the error reported by TeX along with the documentation.  There is however an `expert' option, which allows you to display the real TeX output.

 -- User Option: TeX-display-help
     If t AUCTeX will automatically display a help text whenever an error is encountered using TeX-next-error (C-c `).  If nil a terse information about the error is displayed in the echo area.  If expert AUCTeX will display the output buffer with the raw TeX output.

Checking for problems
=====================

Running TeX or LaTeX will only find regular errors in the document, not examples of bad style.  Furthermore, description of the errors may often be confusing.  The utility lacheck can be used to find style errors, such as forgetting to escape the space after an abbreviation or using ... instead of \ldots and many other problems like that.  You start lacheck with C-c C-c Check RET.  The result will be a list of errors in the *compilation* buffer.  You can go through the errors with C-x ` (next-error, see Compilation (The Emacs Editor)), which will move point to the location of the next error.

Another newer program which can be used to find errors is chktex. It is much more configurable than lacheck, but doesn't find all the problems lacheck does, at least in its default configuration. You must install the programs before using them, and for chktex you may also need modify TeX-command-list unless you use its lacheck compatibility wrapper.  You can get lacheck from <URL:ftp://ftp.ctan.org/tex-archive/support/lacheck/> or alternatively chktex from <URL:ftp://ftp.ctan.org/tex-archive/support/chktex/>.

Controlling the output
======================

A number of commands are available for controlling the output of an application running under AUCTeX

 -- Command: TeX-kill-job
     (C-c C-k)  Kill currently running external application. This may be either of TeX, LaTeX, previewer, BibTeX, etc.

 -- Command: TeX-recenter-output-buffer
     (C-c C-l)  Recenter the output buffer so that the bottom line is visible.

 -- Command: TeX-home-buffer
     (C-c ^) Go to the `master' file in the document associated with the current buffer, or if already there, to the file where the current process was started.

Cleaning intermediate and output files
======================================

 -- Command: TeX-clean
     Remove generated intermediate files.  In case a prefix argument is given, remove output files as well.

     Canonical access to the function is provided by the Clean and Clean All entries in TeX-command-list, invokable with C-c C-c or the Command menu.

     The patterns governing which files to remove can be adapted separately for each AUCTeX mode by means of the variables plain-TeX-clean-intermediate-suffixes, plain-TeX-clean-output-suffixes, LaTeX-clean-intermediate-suffixes, LaTeX-clean-output-suffixes, docTeX-clean-intermediate-suffixes, docTeX-clean-output-suffixes, Texinfo-clean-intermediate-suffixes, Texinfo-clean-output-suffixes, ConTeXt-clean-intermediate-suffixes and ConTeXt-clean-output-suffixes.

 -- User Option: TeX-clean-confirm
     Control if deletion of intermediate and output files has to be confirmed before it is actually done.  If non-nil, ask before deleting files.

Documentation about macros and packages
=======================================

 -- Command: TeX-doc
     (C-c ?)  Get documentation about macros, packages or TeX & Co. in general.  The function will prompt for the name of a command or manual, providing a list of available keywords for completion.  If point is on a command or word with available documentation, this will be suggested as default.

     In case no documentation could be found, a prompt for querying the texdoc program is shown, should the latter be available.

     The command can be invoked by the key binding mentioned above as well as the Find Documentation... entry in the mode menu.

Customization and Extension
***************************

Modes and Hooks
===============

AUCTeX supports a wide variety of derivatives and extensions of TeX.  Besides plain TeX those are LaTeX, AMS-TeX, ConTeXt, Texinfo and docTeX.  For each of them there is a separate major mode in AUCTeX and each major mode runs text-mode-hook, TeX-mode-hook as well as a hook special to the mode in this order.  The following table provides an overview of the respective mode functions and hooks.

Type   Mode function   Hook
Plain TeX   plain-TeX-mode   plain-TeX-mode-hook
LaTeX       LaTeX-mode       LaTeX-mode-hook
AMS-TeX     ams-tex-mode     AmS-TeX-mode-hook
ConTeXt     ConTeXt-mode     ConTeXt-mode-hook
Texinfo        Texinfo-mode     Texinfo-mode-hook
DocTeX      docTeX-mode      docTeX-mode-hook

If you need to make a customization via a hook which is only relevant for one of the modes listed above, put it into the respective mode hook, if it is relevant for any AUCTeX mode, add it to TeX-mode-hook and if it is relevant for all text modes, append it to text-mode-hook.

Multifile Documents
===================

You may wish to spread a document over many files (as you are likely to do if there are multiple authors, or if you have not yet discovered the power of the outline commands (see Outline)).  This can be done by having a ``master'' file in which you include the various files with the TeX macro \input or the LaTeX macro \include.  These files may also include other files themselves.  However, to format the document you must run the commands on the top level master file.

When you, for example, ask AUCTeX to run a command on the master file, it has no way of knowing the name of the master file.  By default, it will assume that the current file is the master file.  If you insert the following in your .emacs file AUCTeX will use a more advanced algorithm.

     (setq-default TeX-master nil) ; Query for master file.

If AUCTeX finds the line indicating the end of the header in a master file (TeX-header-end), it can figure out for itself that this is a master file.  Otherwise, it will ask for the name of the master file associated with the buffer.  To avoid asking you again, AUCTeX will automatically insert the name of the master file as a file variable (see File Variables (The Emacs Editor)).  You can also insert the file variable yourself, by putting the following text at the end of your files.

     %%% Local Variables:
     %%% TeX-master: "master"
     %%% End:

You should always set this variable to the name of the top level document.  If you always use the same name for your top level documents, you can set TeX-master in your .emacs file.

     (setq-default TeX-master "master") ; All master files called "master".

 -- User Option: TeX-master
     The master file associated with the current buffer.  If the file being edited is actually included from another file, then you can tell AUCTeX the name of the master file by setting this variable.  If there are multiple levels of nesting, specify the top level file.

     If this variable is nil, AUCTeX will query you for the name.

     If the variable is t, then AUCTeX will assume the file is a master file itself.

     If the variable is shared, then AUCTeX will query for the name, but will not change the file.

 -- User Option: TeX-one-master
     Regular expression matching ordinary TeX files.

     You should set this variable to match the name of all files, for which it is a good idea to append a TeX-master file variable entry automatically.  When AUCTeX adds the name of the master file as a file variable, it does not need to ask next time you edit the file.

     If you dislike AUCTeX automatically modifying your files, you can set this variable to "<none>".  By default, AUCTeX will modify any file with an extension of .tex.

 -- Command: TeX-master-file-ask
     (C-c _) Query for the name of a master file and add the respective File Variables (see File Variables (The Emacs Editor)) to the file for setting this variable permanently.

     AUCTeX will not ask for a master file when it encounters existing files.  This function shall give you the possibility to insert the variable manually.

AUCTeX keeps track of macros, environments, labels, and style files that are used in a given document.  For this to work with multifile documents, AUCTeX has to have a place to put the information about the files in the document.  This is done by having an auto subdirectory placed in the directory where your document is located.  Each time you save a file, AUCTeX will write information about the file into the auto directory.  When you load a file, AUCTeX will read the information in the auto directory about the file you loaded and the master file specified by TeX-master.  Since the master file (perhaps indirectly) includes all other files in the document, AUCTeX will get information from all files in the document.  This means that you will get from each file, for example, completion for all labels defined anywhere in the document.

AUCTeX will create the auto directory automatically if TeX-auto-save is non-nil.  Without it, the files in the document will not know anything about each other, except for the name of the master file.  See Automatic Local.

 -- Command: TeX-save-document
     (C-c C-d) Save all buffers known to belong to the current document.

 -- User Option: TeX-save-query
     If non-nil, then query the user before saving each file with TeX-save-document.

Automatic Parsing of TeX Files
==============================

AUCTeX depends heavily on being able to extract information from the buffers by parsing them.  Since parsing the buffer can be somewhat slow, the parsing is initially disabled.  You are encouraged to enable them by adding the following lines to your .emacs file.

     (setq TeX-parse-self t) ; Enable parse on load.
     (setq TeX-auto-save t) ; Enable parse on save.

The latter command will make AUCTeX store the parsed information in an auto subdirectory in the directory each time the TeX files are stored, see Automatic Local.  If AUCTeX finds the pre-parsed information when loading a file, it will not need to reparse the buffer. The information in the auto directory is also useful for multifile documents, see Multifile, since it allows each file to access the parsed information from all the other files in the document. This is done by first reading the information from the master file, and then recursively the information from each file stored in the master file.

The variables can also be done on a per file basis, by changing the file local variables.

     %%% Local Variables:
     %%% TeX-parse-self: t
     %%% TeX-auto-save: t
     %%% End:

Even when you have disabled the automatic parsing, you can force the generation of style information by pressing C-c C-n.  This is often the best choice, as you will be able to decide when it is necessary to reparse the file.

 -- User Option: TeX-parse-self
     Parse file after loading it if no style hook is found for it.

 -- User Option: TeX-auto-save
     Automatically save style information when saving the buffer.

 -- Command: TeX-normal-mode ARG
     (C-c C-n) Remove all information about this buffer, and apply the style hooks again.  Save buffer first including style information.  With optional argument, also reload the style hooks.

When AUCTeX saves your buffer, it can optionally convert all tabs in your buffer into spaces. Tabs confuse AUCTeX's error message parsing and so should generally be avoided.  However, tabs are significant in some environments, and so by default AUCTeX does not remove them. To convert tabs to spaces when saving a buffer, insert the following in your .emacs file:

     (setq TeX-auto-untabify t)

 -- User Option: TeX-auto-untabify
     Automatically remove all tabs from a file before saving it.

Instead of disabling the parsing entirely, you can also speed it significantly up by limiting the information it will search for (and store) when parsing the buffer.  You can do this by setting the default values for the buffer local variables TeX-auto-regexp-list and TeX-auto-parse-length in your .emacs file.

     ;; Only parse LaTeX class and package information.
     (setq-default TeX-auto-regexp-list 'LaTeX-auto-minimal-regexp-list)
     ;; The class and package information is usually near the beginning.
     (setq-default TeX-auto-parse-length 2000)

This example will speed the parsing up significantly, but AUCTeX will no longer be able to provide completion for labels, macros, environments, or bibitems specified in the document, nor will it know what files belong to the document.

These variables can also be specified on a per file basis, by changing the file local variables.

     %%% Local Variables:
     %%% TeX-auto-regexp-list: TeX-auto-full-regexp-list
     %%% TeX-auto-parse-length: 999999
     %%% End:

 -- User Option: TeX-auto-regexp-list
     List of regular expressions used for parsing the current file.

 -- User Option: TeX-auto-parse-length
     Maximal length of TeX file that will be parsed.

The pre-specified lists of regexps are defined below.  You can use these before loading AUCTeX by quoting them, as in the example above.

 -- Constant: TeX-auto-empty-regexp-list
     Parse nothing

 -- Constant: LaTeX-auto-minimal-regexp-list
     Only parse LaTeX class and packages.

 -- Constant: LaTeX-auto-label-regexp-list
     Only parse LaTeX labels.

 -- Constant: LaTeX-auto-regexp-list
     Parse common LaTeX commands.

 -- Constant: plain-TeX-auto-regexp-list
     Parse common plain TeX commands.

 -- Constant: TeX-auto-full-regexp-list
     Parse all TeX and LaTeX commands that AUCTeX can use.

Language Support
================

TeX and Emacs are usable for European (Latin, Cyrillic, Greek) based languages.  Some LaTeX and EmacsLisp packages are available for easy typesetting and editing documents in European languages.

For CJK (Chinese, Japanese, and Korean) languages, Emacs or XEmacs with MULE (MULtilingual Enhancement to GNU Emacs) support is required.  MULE is part of Emacs by default since Emacs 20.  XEmacs has to be configured with the --with-mule option.  Special versions of TeX are needed for CJK languages: CTeX and ChinaTeX for Chinese, ASCII pTeX and NTT jTeX for Japanese, HLaTeX and kTeX for Korean.  The CJK-LaTeX package is required for supporting multiple CJK scripts within a single document.

Note that Unicode is not fully supported in Emacs 21 and XEmacs 21. CJK characters are not usable.  Please use the MULE-UCS EmacsLisp package or Emacs 22 (not released yet) if you need CJK.

Using AUCTeX with European Languages
------------------------------------

Typing and Displaying Non-ASCII Characters
..........................................

First you will need a way to write non-ASCII characters.  You can either use macros, or teach TeX about the ISO character sets.  I prefer the latter, it has the advantage that the usual standard emacs word movement and case change commands will work.

With LaTeX2e, just add \usepackage[latin1]{inputenc}.  Other languages than Western European ones will probably have other encoding needs.

To be able to display non-ASCII characters you will need an appropriate font and a version of GNU Emacs capable of displaying 8-bit characters (e.g. Emacs 21).  The manner in which this is supported differs between Emacsen, so you need to take a look at your respective documentation.

A compromise is to use an European character set when editing the file, and convert to TeX macros when reading and writing the files.

iso-cvt.el
     Much like iso-tex.el but is bundled with Emacs 19.23 and later.

x-compose.el
     Similar package bundled with new versions of XEmacs.

X-Symbol
     a much more complete package for both Emacs and XEmacs that can also handle a lot of mathematical characters and input methods.

Style Files for Different Languages
...................................

AUCTeX supports style files for several languages.  Each style file may modify AUCTeX to better support the language, and will run a language specific hook that will allow you to for example change ispell dictionary, or run code to change the keyboard remapping.  The following will for example choose a Danish dictionary for documents including \usepackage[danish]{babel}. This requires parsing to be enabled, see Parsing Files.

     (add-hook 'TeX-language-dk-hook
     	  (lambda () (ispell-change-dictionary "danish")))

The following style files are recognized:

bulgarian
     Runs style hook TeX-language-bg-hook.  Gives " word syntax, makes the " key insert a literal ".  Typing " twice will insert insert "` or "' depending on context. Typing - twice will insert "=, three times --.

czech
     Runs style hook TeX-language-cz-hook.  Pressing " will insert \uv{ and } depending on context.

danish
     Runs style hook TeX-language-dk-hook.  Pressing " will insert "` and "' depending on context.  Typing - twice will insert "=, i.e. a hyphen string allowing hyphenation in the composing words.

dutch
     Runs style hook TeX-language-nl-hook.

german
ngerman
     Runs style hook TeX-language-de-hook.  Gives " word syntax, makes the " key insert a literal ".  Pressing the key twice will give you opening or closing German quotes ("` or "').  Typing - twice will insert "=, three times --.

frenchb
francais
     Runs style hook TeX-language-fr-hook.  Pressing " will insert \\og and \\fg depending on context.  Note that the language name for customizing TeX-quote-language-alist is french.

icelandic
     Runs style hook TeX-language-is-hook.  Gives " word syntax, makes the " key insert a literal ".  Typing " twice will insert insert "` or "' depending on context. Typing - twice will insert "=, three times --.

italian
     Runs style hook TeX-language-it-hook.  Pressing " will insert "< and "> depending on context.

polish
     Runs style hook TeX-language-pl-hook.  Gives " word syntax and makes the " key insert a literal ".  Pressing " twice will insert "` or "' depending on context.

polski
     Runs style hook TeX-language-pl-hook.  Makes the " key insert a literal ".  Pressing " twice will insert ,, or '' depending on context.

slovak
     Runs style hook TeX-language-sk-hook.  Pressing " will insert \uv{ and } depending on context.

swedish
     Runs style hook TeX-language-sv-hook.  Pressing " will insert ''.  Typing - twice will insert "=, three times --.

Replacement of language-specific hyphen strings like "= with dashes does not require to type - three times in a row.  You can put point after the hypen string anytime and trigger the replacement by typing -.

In case you are not satisfied with the suggested behavior of quote and hyphen insertion you can change it by customizing the variables TeX-quote-language-alist and LaTeX-babel-hyphen-language-alist respectively.

 -- User Option: TeX-quote-language-alist
     Used for overriding the default language-specific quote insertion behavior.  This is an alist where each element is a list consisting of four items.  The first item is the name of the language in concern as a string.  See the list of supported languages above.  The second item is the opening quotation mark.  The third item is the closing quotation mark.  Opening and closing quotation marks can be specified directly as strings or as functions returning a string.  The fourth item is a boolean controlling quote insertion.  It should be non-nil if if the special quotes should only be used after inserting a literal " character first, i.e. on second key press.

 -- User Option: LaTeX-babel-hyphen-language-alist
     Used for overriding the behavior of hyphen insertion for specific languages.  Every element in this alist is a list of three items.  The first item should specify the affected language as a string.  The second item denotes the hyphen string to be used as a string.  The third item, a boolean, controls the behavior of hyphen insertion and should be non-nil if the special hyphen should be inserted after inserting a literal - character, i.e. on second key press.

The defaults of hyphen insertion are defined by the variables LaTeX-babel-hyphen and LaTeX-babel-hyphen-after-hyphen respectively.

 -- User Option: LaTeX-babel-hyphen
     String to be used when typing -.  This usually is a hyphen alternative or hyphenation aid provided by babel and the related language style files, like "=, "~ or "-.

     Set it to an empty string or nil in order to disable language-specific hyphen insertion.

 -- User Option: LaTeX-babel-hyphen-after-hyphen
     Control insertion of hyphen strings.  If non-nil insert normal hyphen on first key press and swap it with the language-specific hyphen string specified in the variable LaTeX-babel-hyphen on second key press. If nil do it the other way round.

Using AUCTeX with Japanese TeX
------------------------------

To write Japanese text with AUCTeX, you need to have versions of TeX and Emacs that support Japanese.  There exist at least two variants of TeX for Japanese text (NTT jTeX and ASCII pTeX). AUCTeX can be used with MULE (MULtilingual Enhancement to GNU Emacs) supported Emacsen.

To use the Japanese TeX variants, simply activate japanese-plain-tex-mode or japanese-latex-mode and everything should work.  If not, send mail to Masayuki Ataka <ataka@milk.freemail.ne.jp>, who kindly donated the code for supporting Japanese in AUCTeX.  None of the primary AUCTeX maintainers understand Japanese, so they cannot help you.

If you usually use AUCTeX in Japanese, setting the following variables is useful.

 -- User Option: TeX-default-mode
     Mode to enter for a new file when it cannott be determined whether the file is plain TeX or LaTeX or what.

     If you want to enter Japanese LaTeX mode whenever this may happen, set the variable like this:

          (setq TeX-default-mode 'japanese-latex-mode)

 -- User Option: japanese-TeX-command-default
     The default command for TeX-command in Japanese TeX mode.

     The default value is "pTeX".

 -- User Option: japanese-LaTeX-command-default
     The default command for TeX-command in Japanese LaTeX mode.

     The default value is "LaTeX".

 -- User Option: japanese-LaTeX-default-style
     The default style/class when creating a new Japanese LaTeX document.

     The default value is "jarticle".

See tex-jp.el for more information.

Automatic Customization
=======================

Since AUCTeX is so highly customizable, it makes sense that it is able to customize itself.  The automatic customization consists of scanning TeX files and extracting symbols, environments, and things like that.

The automatic customization is done on three different levels.  The global level is the level shared by all users at your site, and consists of scanning the standard TeX style files, and any extra styles added locally for all users on the site.  The private level deals with those style files you have written for your own use, and use in different documents.  You may have a ~/lib/TeX/ directory where you store useful style files for your own use.  The local level is for a specific directory, and deals with writing customization for the files for your normal TeX documents.

If compared with the environment variable TEXINPUTS, the global level corresponds to the directories built into TeX.  The private level corresponds to the directories you add yourself, except for ., which is the local level.

By default AUCTeX will search for customization files in all the global, private, and local style directories, but you can also set the path directly.  This is useful if you for example want to add another person's style hooks to your path.  Please note that all matching files found in TeX-style-path are loaded, and all hooks defined in the files will be executed.

 -- User Option: TeX-style-path
     List of directories to search for AUCTeX style files. Each must end with a slash.

By default, when AUCTeX searches a directory for files, it will recursively search through subdirectories.

 -- User Option: TeX-file-recurse
     Whether to search TeX directories recursively: nil means do not recurse, a positive integer means go that far deep in the directory hierarchy, t means recurse indefinitely.

By default, AUCTeX will ignore files name ., .., SCCS, RCS, and CVS.

 -- User Option: TeX-ignore-file
     Regular expression matching file names to ignore.

     These files or directories will not be considered when searching for TeX files in a directory.

Automatic Customization for the Site
------------------------------------

Assuming that the automatic customization at the global level was done when AUCTeX was installed, your choice is now: will you use it?  If you use it, you will benefit by having access to all the symbols and environments available for completion purposes.  The drawback is slower load time when you edit a new file and perhaps too many confusing symbols when you try to do a completion.

You can disable the automatic generated global style hooks by setting the variable TeX-auto-global to nil.

 -- User Option: TeX-macro-global
     Directories containing the site's TeX style files.

 -- User Option: TeX-style-global
     Directory containing hand generated TeX information. Must end with a slash.

     These correspond to TeX macros shared by all users of a site.

 -- User Option: TeX-auto-global
     Directory containing automatically generated information.

     For storing automatic extracted information about the TeX macros shared by all users of a site.

Automatic Customization for a User
----------------------------------

You should specify where you store your private TeX macros, so AUCTeX can extract their information.  The extracted information will go to the directories listed in TeX-auto-private

Use M-x TeX-auto-generate RET to extract the information.

 -- User Option: TeX-macro-private
     Directories where you store your personal TeX macros.  The value defaults to the directories listed in the TEXINPUTS and BIBINPUTS environment variables or to the respective directories in $TEXMFHOME if no results can be obtained from the environment variables.

 -- User Option: TeX-auto-private
     List of directories containing automatically generated AUCTeX style files.  These correspond to the personal TeX macros.

 -- Command: TeX-auto-generate TEX AUTO
     (M-x TeX-auto-generate RET) Generate style hook for TEX and store it in AUTO.  If TEX is a directory, generate style hooks for all files in the directory.

 -- User Option: TeX-style-private
     List of directories containing hand generated AUCTeX style files. These correspond to the personal TeX macros.

Automatic Customization for a Directory
---------------------------------------

AUCTeX can update the style information about a file each time you save it, and it will do this if the directory TeX-auto-local exist. TeX-auto-local is by default set to "auto", so simply creating an auto directory will enable automatic saving of style information.

The advantage of doing this is that macros, labels, etc. defined in any file in a multifile document will be known in all the files in the document.  The disadvantage is that saving will be slower.  To disable, set TeX-auto-local to nil.

 -- User Option: TeX-style-local
     Directory containing hand generated TeX information. Must end with a slash.

     These correspond to TeX macros found in the current directory.

 -- User Option: TeX-auto-local
     Directory containing automatically generated TeX information. Must end with a slash.

     These correspond to TeX macros found in the current directory.

Writing Your Own Style Support
==============================

See Automatic, 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.

If you write some useful support for a public TeX style file, please send it to us.

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")))

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.

 -- Function: TeX-add-style-hook STYLE HOOK
     Add HOOK to the list of functions to run when we use the TeX file STYLE.

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-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" ]))))

 -- 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 chose 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-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.

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.

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.

TeX-arg-macro
     Prompt for a TeX macro with completion.

TeX-arg-environment
     Prompt for a LaTeX environment with completion.

TeX-arg-cite
     Prompt for a BibTeX citation.

TeX-arg-counter
     Prompt for a LaTeX counter.

TeX-arg-savebox
     Prompt for a LaTeX savebox.

TeX-arg-file
     Prompt for a filename in the current directory, and use it without the 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.

TeX-arg-define-label
     Prompt for a label completing with known labels.  Add label to list of defined labels.

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

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.

Adding Support for Environments
-------------------------------

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"
      (lambda ()
        (LaTeX-add-environments
         '("document" LaTeX-env-document)
         '("enumerate" LaTeX-env-item)
         '("itemize" LaTeX-env-item)
         '("list" LaTeX-env-list))))

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.  The fact that an argument is optional can be indicated by wrapping the prompt string in a vector.

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"
      (lambda ()
        (LaTeX-add-environments
         '("loop" "From" "To" "Step"))))

If an environment is defined multiple times, AUCTeX will choose 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"
      (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.

 -- Function: LaTeX-add-environments ENV ...
     Add each ENV to list of loaded environments.

 -- Function: LaTeX-insert-environment ENV [ EXTRA ]
     Insert environment of type ENV, with optional argument EXTRA.

Following is a list of available hooks for LaTeX-add-environments:

LaTeX-env-item
     Insert the given environment and the first item.

LaTeX-env-figure
     Insert the given figure-like environment with a caption and a label.

LaTeX-env-array
     Insert the given array-like environment with position and column specifications.

LaTeX-env-label
     Insert the given environment with a label.

LaTeX-env-list
     Insert the given list-like environment, a specifier for the label and the first item.

LaTeX-env-minipage
     Insert the given minipage-like environment with position and width specifications.

LaTeX-env-tabular*
     Insert the given tabular*-like environment with width, position and column specifications.

LaTeX-env-picture
     Insert the given environment with width and height specifications.

LaTeX-env-bib
     Insert the given environment with a label for a bibitem.

LaTeX-env-contents
     Insert the given environment with a filename as its argument.

LaTeX-env-args
     Insert the given environment with arguments.  You can use this as a hook in case you want to specify multiple complex arguments just like in elements of TeX-add-symbols.  This is most useful if the specification of arguments to be prompted for with strings and strings wrapped in a vector as described above is too limited.

     Here is an example from listings.el which calls a function with one argument in order to prompt for a key=value list to be inserted as an optional argument of the lstlisting environment:

          (LaTeX-add-environments
           `("lstlisting" LaTeX-env-args
             [TeX-arg-key-val ,LaTeX-listings-key-val-options]))

Adding Other Information
------------------------

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.

 -- Function: LaTeX-add-bibliographies BIBLIOGRAPHY ...
     Add each BIBLIOGRAPHY to list of loaded bibliographies.

 -- Function: LaTeX-add-labels LABEL ...
     Add each LABEL to the list of known labels.

Automatic Extraction of New Things
----------------------------------

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 (lambda (list)
     	    (mapcar (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"
      (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.

 -- Variable: TeX-auto-regexp-list
     List of regular expressions matching TeX macro definitions.

     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.

 -- Variable: TeX-auto-prepare-hook nil
     List of functions to be called before parsing a TeX file.

 -- Variable: TeX-auto-cleanup-hook nil
     List of functions to be called after parsing a TeX file.

Copying, Changes, Development, FAQ
**********************************

Copying this Manual
===================

The copyright notice for this manual is:

This manual is for AUCTeX (version VERSION from UPDATED), a sophisticated TeX environment for Emacs.

Copyright © 1992, 1993, 1994, 1995, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.

     Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts.  A copy of the license is included in the section entitled ``GNU Free Documentation License.''

The full license text can be read here:

     [file fdl.texi not included]

Changes and New Features
========================

     [file changes.texi not included]

Older versions
--------------

See the file history.texi for older changes.

Future Development
==================

     [file todo.texi not included]

Frequently Asked Questions
==========================

     [file faq.texi not included]

Indices
*******