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

2.1 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. By default, 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.

With optional arg, insert that many dollar signs.

TeX and LaTeX users often look for a way to insert inline equations like ‘$...$’ or ‘\(...\)’ simply typing $. AUCTeX helps them through the customizable variable TeX-electric-math.

User Option: TeX-electric-math

If the variable is non-nil and you type $ outside math mode, AUCTeX will automatically insert the opening and closing symbols for an inline equation and put the point between them. The opening symbol will blink when blink-matching-paren is non-nil. If TeX-electric-math is nil, typing $ simply inserts ‘$’ at point, this is the default.

Besides nil, possible values for this variable are (cons "$" "$") for TeX inline equations ‘$...$’, and (cons "\\(" "\\)") for LaTeX inline equations ‘\(...\)’.

If the variable is non-nil and point is inside math mode right between a couple of single dollars, pressing $ will insert another pair of dollar signs and leave the point between them. Thus, if TeX-electric-math is set to (cons "$" "$") you can easily obtain a TeX display equation ‘$$...$$’ by pressing $ twice in a row. (Note that you should not use double dollar signs in LaTeX because this practice can lead to wrong spacing in typeset documents.)

In addition, when the variable is non-nil and there is an active region outside math mode, typing $ will put around the active region symbols for opening and closing inline equation and keep the region active, leaving point after the closing symbol. By pressing repeatedly $ while the region is active you can toggle between an inline equation, a display equation, and no equation. To be precise, ‘$...$’ is replaced by ‘$$...$$’, whereas ‘\(...\)’ is replaced by ‘\[...\]’.

If you want to automatically insert ‘$...$’ in plain TeX files, and ‘\(...\)’ in LaTeX files by pressing $, add the following to your init file

 
(add-hook 'plain-TeX-mode-hook
	  (lambda () (set (make-variable-buffer-local 'TeX-electric-math)
			  (cons "$" "$"))))
(add-hook 'LaTeX-mode-hook
	  (lambda () (set (make-variable-buffer-local 'TeX-electric-math)
			  (cons "\\(" "\\)"))))

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.

When writing complex math formulas in LaTeX documents, you sometimes need to adjust the size of braces with pairs of macros like ‘\left’-‘\right’, ‘\bigl’-‘\bigr’ and so on. You can avoid unbalanced pairs with the help of TeX-insert-macro, bound to C-c C-m or C-c <RET> (see Completion). If you insert left size adjusting macros such as ‘\left’, ‘\bigl’ etc. with TeX-insert-macro, it asks for left brace to use and supplies automatically right size adjusting macros such as ‘\right’, ‘\bigr’ etc. and corresponding right brace in addtion to the intended left macro and left brace.

The completion by TeX-insert-macro also applies when entering macros such as ‘\langle’, ‘\lfloor’ and ‘\lceil’, which produce the left part of the paired braces. For example, inserting ‘\lfloor’ by C-c C-m is immediately followed by the insertion of ‘\rfloor’. In addition, if the point was located just after ‘\left’ or its friends, the corresponding ‘\right’ etc. will be inserted in front of ‘\rfloor’. In both cases, active region is honored.

As a side effect, when LaTeX-math-mode (see Mathematics) is on, just typing `( inserts not only ‘\langle’, but also ‘\rangle’.

If you do not like such auto completion at all, it can be disabled by a user option.

User Option: TeX-arg-right-insert-p

If this option is turned off, the automatic supply of the right macros and braces is suppressed.

When you edit LaTeX documents, you can enable automatic brace pairing when typing (, { and [.

User Option: LaTeX-electric-left-right-brace

If this option is on, just typing (, { or [ immediately adds the corresponding right brace ‘)’, ‘}’ or ‘]’. The point is left after the opening brace. If there is an active region, braces are put around it.

They recognize the preceeding backslash or size adjusting macros such as ‘\left’, ‘\bigl’ etc., so the following completions will occur:

This auto completion feature may be a bit annoying when editing an already existing LaTeX document. In that case, use C-u 1 or C-q before typing (, { or [. Then no completion is done and just a single left brace is inserted. In fact, with optional prefix arg, just that many open braces are inserted without any completion.


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

This document was generated by Mosè Giordano on October 29, 2014 using texi2html 1.82.