Marking up Text for TEX and LATEX

GNU Emacs provides much fuller support for marking up TEX files than it does for troff files. Both TEX and LATEX modes are major modes; once you turn them on, all kinds of special behavior kicks in to help you mark up and process these files from within Emacs. Many of the features of TEX mode also apply to LATEX; users should read this section first, then go on to read about additional features of LATEX mode.

To enter TEX mode, type ESC x tex-mode RETURN. Emacs looks at the file to see if it looks like TEX or LATEX and puts you in the correct mode. If you want to specify TEX mode particularly, type ESC x plain-tex-mode RETURN. Similarly, to start LATEX mode, type ESC x latex-mode RETURN.

Matching Braces

TEX commands often take the form \keyword{text}. TEX mode doesn’t try to figure out if you’re using the “right” keywords, since TEX is extensible and you may have defined your own keywords. It does, however, provide support for avoiding the most common TEX error: mismatched curly braces and dollar signs.

In TEX, curly braces ({}) and dollar signs ($$) should always appear in pairs; Emacs checks to make sure that each opening brace or dollar sign also has a counterpart. When you type a closing brace or dollar sign, the cursor moves quickly to its counterpart (provided that it is on the screen; it shows the context in the minibuffer if it is not), then back again. This visual check doesn’t actually affect the cursor’s location in the file; if ...

Get Learning GNU Emacs, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.