[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4. Inserting Frequently Used Commands

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

4.1 Insertion of Quotes, Dollars, and Braces  Inserting double quotes
4.2 Inserting Font Specifiers  
4.3 Inserting chapters, sections, etc.  
4.4 Inserting Environment Templates  

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 Insertion of Quotes, Dollars, and Braces

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.

User Option: TeX-close-quote
String inserted by typing " to close a quotation.

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.

If you include the style files `german' or `ngerman' TeX-open-quote and TeX-close-quote will be set to the values of LaTeX-german-open-quote and LaTeX-german-close-quote respectively. TeX-quote-after-quote will be set to the value of LaTeX-german-quote-after-quote. If you write texts which facilitate the style files mentioned before, you should customize those special variables instead of the standard variables.

Similarly you should customize LaTeX-csquotes-open-quote, LaTeX-csquotes-close-quote and LaTeX-csquotes-quote-after-quote if you use the `csquotes' package. 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 `(n)german'-related ones.

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. If you enter a dollar sign that matches a double dollar sign `$$' AUCTeX will automatically insert two dollar signs. If you enter a second dollar sign that matches a single dollar sign, the single dollar sign will automatically be converted to a double 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.

With optional arg, insert that many dollar signs.

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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 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 @iftex {@textsf sans serif}@c sans serif@c

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

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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

The following variables can be set to customize the function.

Hooks to be run when inserting a section.
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

Numeric section level, default set by prefix arg to LaTeX-section.
Name of the sectioning command, derived from level.
The title of the section, default to an empty string.
Entry for the table of contents list, default nil.
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.

Query the user about the name of the sectioning command. Modifies level and name.
Query the user about the title of the section. Modifies title.
Query the user for the toc entry. Modifies toc.
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.
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

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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4 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 section 4.4.5 Customizing environments.

4.4.1 Equations  
4.4.2 Floats  
4.4.3 Itemize-like  
4.4.4 Tabular-like  
4.4.5 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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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

This is the caption of the float.

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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.3 Itemize-like

In an itemize-like environment, nodes (i.e., `\item's) 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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.4 Tabular-like

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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.5 Customizing environments

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

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by XEmacs Webmaster on October, 2 2007 using texi2html