The previous chapter described how to write the main body of the text easily and with a minimum of errors. In this chapter we will describe some features for entering more specialized sorts of text, and for indenting and navigating through the document.
TeX is written by a mathematician, and has always contained good support for formatting mathematical text. AUC TeX supports this tradition, by offering a special minor mode for entering text with many mathematic symbols. You can enter this mode by typing C-c ~.
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-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.
LaTeX-math-mode
commands;
This value defaults to `.
The variable LaTeX-math-list
holds the actual mapping.
LaTeX-math-mode
.
The car of each element is the key and the cdr is the macro name.
The AUC TeX distributions includes a reference card for
LaTeX-math-mode
with a list of all math mode commands.
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, AUC TeX has a TeX-complete-symbol
command, usually bound to M-TAB. Using
LaTeX-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''.
A more direct way to insert a macro is with TeX-insert-macro
,
bound to C-c C-m. 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.
As a default selection, AUC TeX will suggest the macro last inserted
or, as the first choice the value of the variable
TeX-default-macro
.
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
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.
By default AUC TeX 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 section Entering Mathematics, or by setting TeX-insert-braces
to nil
Completions work because AUC TeX can analyze TeX files, and store symbols in emacs lisp files for later retrieval. See section Automatic Customization, for more information.
AUC TeX 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 section Automatic Parsing of TeX 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.
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. To uncomment, simply type C-u - C-c ; to uncomment all lines in the region, or C-u - C-c % uncomment all comment lines around point.
By default, these commands will insert or remove a single `%'. To insert more than one, give an argument. C-u 5 C-c % will add five `%' to each line, while C-u - 5 C-c % will remove up to 5 `%' from each line.
AUC TeX contains very advanced handling of indentation and
reformatting of the LaTeX source. If you have already tried AUC
TeX with auto-fill-mode
enabled, you may have noted that the
source is automatically indented and formatted as you write it. More
over, AUC TeX is able to format sections of text on demand.
It is important to realize, that AUC TeX comes with `formatting' in two fashions. Either letting TeX format the file, or letting AUC TeX make the ASCII document look better.
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. This indentation makes it easier to see the
structure of the document, and to catch errors such as a missing close
brace. Thus, the indentation is done for precisely the same reasons
that you would indent ordinary computer programs.
The following is a short sample of an itemize environment indented by AUC TeX. If more environment are nested, they are indented `accumulated' just like most programming languages usually are seen indented in nested constructs.
\begin{itemize} \item Insertion of templates for logical-structural compositions such as environments and sections. \item Hot-keys for easy access to certain often used constructs, e.g., font changes, accented letters, and mathematical symbols. \item Running application programs (such as \TeX), and then parsing the output so that errors in the document may be located easily. \item Support for multi-file documents. \item Online help for \AllTeX\ error messages. \item Outlining\Dash i.e., manipulating the document as a composition of nested/sequential logical constructs. \item Instant formatting and indentation of the \ascii-document in order to make it easier to read. \item `Completion' (and thereby spell-checking) of partially written control sequences. \end{itemize}
You can format and indent single lines, paragraphs, environments, or sections.
LaTeX-indent-line
will indent the current line.
reindent-then-newline-and-indent
indents the current line, and
then inserts a new line (much like RET) and move the cursor to an
appropriate position by the left margin.
LaTeX-fill-paragraph
will reformat or `fill' the current
paragraph.
LaTeX-fill-environment
will reformat or `fill' the current
environment. This may e.g. be the `document' environment, in which case
the entire document will be formatted.
LaTeX-fill-section
will reformat or `fill' the current
logical sectional unit.
LaTeX-fill-region
will format or `fill' the current region.
Warning: The formatting cannot handle tabular-like environments. Those will be completely messed-up if you try to format them.
GNU Emacs earlier than version 19.19 does not have a useful outline mode. If you want to use outlines with old versions of emacs, please get the file `outln-18.el' from `sunsite.auc.dk:/packages/auctex/outln-18.el'. It is a port of the Emacs 19.19 outline mode to Emacs 18 and Lucid Emacs.
AUC TeX supports the standard outline minor mode using LaTeX
sectioning commands as header lines. See section `Outline Mode' in GNU Emacs Manual. By default
outline-minor-mode
will use the prefix key C-c which is
also used by AUC TeX, so it is suggested that you choose another
prefix key by inserting
(setq outline-minor-mode-prefix "\C-c\C-o") ; Or whatever...
in your `.emacs' file.
You can add your own headings by setting the variable
TeX-outline-extra
.
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
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.