1.3.1 Functions for editing TeX files
1.3.1.1 Making your TeX code more readable​
AUCTeX can do syntax highlighting of your source code, that means commands will get special colors or fonts. You can enable it locally by typing M-x font-lock-mode RET
. If you want to have font locking activated generally, enable global-font-lock-mode
, e.g. with M-x customize-variable RET global-font-lock-mode RET
.
AUCTeX will indent new lines to indicate their syntactical relationship to the surrounding text. For example, the text of a \footnote
or text inside of an environment will be indented relative to the text around it. If the indenting has gotten wrong after adding or deleting some characters, use ﹤TAB﹥ to reindent the line, M-q
for the whole paragraph, or M-x LaTeX-fill-buffer RET
for the whole buffer.
1.3.1.2 Entering sectioning commands​
Insertion of sectioning macros, that is ‘\chapter
’, ‘\section
’, ‘\subsection
’, etc. and accompanying ‘\label
’ commands may be eased by using C-c C-s
. You will be asked for the section level. As nearly everywhere in AUCTeX, you can use the ﹤TAB﹥ or ﹤SPC﹥ key to get a list of available level names, and to auto-complete what you started typing. Next, you will be asked for the printed title of the section, and last you will be asked for a label to be associated with the section.
1.3.1.3 Inserting environments​
Similarly, you can insert environments, that is ‘\begin{}
’–‘\end{}
’ pairs: Type C-c C-e
, and select an environment type. Again, you can use ﹤TAB﹥ or ﹤SPC﹥ to get a list, and to complete what you type. Actually, the list will not only provide standard LaTeX environments, but also take your ‘\documentclass
’ and ‘\usepackage
’ commands into account if you have parsing enabled by setting TeX-parse-self
to t
. If you use a couple of environments frequently, you can use the up and down arrow keys (or M-p
and M-n
) in the minibuffer to get back to the previously inserted commands.
Some environments need additional arguments. Often, AUCTeX knows about this and asks you to enter a value.
1.3.1.4 Inserting macros​
C-c C-m
, or simply C-c RET
will give you a prompt that asks you for a LaTeX macro. You can use ﹤TAB﹥ for completion, or the up/down arrow keys (or M-p
and M-n
) to browse the command history. In many cases, AUCTeX knows which arguments a macro needs and will ask you for that. It even can differentiate between mandatory and optional arguments—for details, see Completion.
An additional help for inserting macros is provided by the possibility to complete macros right in the buffer. With point at the end of a partially written macro, you can complete it by typing M-TAB
.
1.3.1.5 Changing the font​
AUCTeX provides convenient keyboard shortcuts for inserting macros which specify the font to be used for typesetting certain parts of the text. They start with C-c C-f
, and the last C-
combination tells AUCTeX which font you want:
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 sans serif ‘\textsf{∗}
’ text.
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.
If you want to change font attributes of existing text, mark it as an active region, and then invoke the commands. If no region is selected, the command will be inserted with empty braces, and you can start typing the changed text.
Most of those commands will also work in math mode, but then macros like \mathbf
will be inserted.
1.3.1.6 Other useful features​
AUCTeX also tries to help you when inserting the right “quote" signs for your language, dollar signs to typeset math, or pairs of braces. It offers shortcuts for commenting out text (C-c ;
for the current region or C-c %
for the paragraph you are in). The same keystrokes will remove the % signs, if the region or paragraph is commented out yet. With TeX-fold-mode
, you can hide certain parts (like footnotes, references etc.) that you do not edit currently. Support for Emacs’ outline mode is provided as well. And there’s more, but this is beyond the scope of this Quick Start Guide.