Skip to main content

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-local-variable 'TeX-electric-math)            (cons "$" "$")))) (add-hook 'LaTeX-mode-hook    (lambda () (set (make-local-variable '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 preceding backslash or size adjusting macros such as β€˜\left’, β€˜\bigl’ etc., so the following completions will occur:

  • (when typing single left brace)

    • - β€˜(’ -οΉ₯ β€˜()’
    • - β€˜{’ -οΉ₯ β€˜{}’
    • - β€˜[’ -οΉ₯ β€˜[]’
  • (when typing left brace just after a backslash)

    • - β€˜\(’ -οΉ₯ β€˜\(\)’
    • - β€˜\{’ -οΉ₯ β€˜\{\}’
    • - β€˜\[’ -οΉ₯ β€˜\[\]’
  • (when typing just after β€˜\left’ or β€˜\bigl’)

    • - β€˜\left(’ -οΉ₯ β€˜\left(\right)’
    • - β€˜\bigl[’ -οΉ₯ β€˜\bigl[\bigr]’
  • (when typing just after β€˜\Bigl\’)

    • - β€˜\Bigl\{’ -οΉ₯ β€˜\Bigl\{\Bigr\}’

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.