5.3 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-index-regexp-listβ
Only parse LaTeX index and glossary entries.
constant
LaTeX-auto-class-regexp-listβ
Only parse macros in LaTeX classes and packages.
constant
LaTeX-auto-pagestyle-regexp-listβ
Only parse LaTeX pagestyles.
constant
LaTeX-auto-counter-regexp-listβ
Only parse LaTeX counters.
constant
LaTeX-auto-length-regexp-listβ
Only parse LaTeX lengths.
constant
LaTeX-auto-savebox-regexp-listβ
Only parse LaTeX saveboxes.
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.