GNU Emacs As a Front End to LATEX
Total Page:16
File Type:pdf, Size:1020Kb
GNU Emacs as a Front End to LATEX Kresten Krab Thorup Dept. of Mathematics and Computer Science Institute of Electronic Systems Aalborg University DK-9220 Aalborg Ø Denmark [email protected] Abstract As LATEXandTEX are more widely used, the need for high-level front ends becomes urgent. This talk describes AUC TEX, one such high-level front end for LATEX, written for GNU Emacs. AUC TEX does not at all attempt to be wysiwyg; rather, it offers the author of a LATEX document a plain ascii file, together with a number of features to simplify and help the author perform certain tasks such as running (LA)TEX, finding errors, and simply typing in the document. Background — The GNU Emacs Advantages of Structure-Oriented Paradigm Editing GNU Emacs is a powerful text editor which, very AUC TEX is an application for editing (LA)TEXdoc- much like TEX, leaves the sophisticated Emacs user uments, especially LATEX. The most general advan- with the choice of affecting its behavior on demand. tage is that by knowing the general structure of a The extension language of GNU Emacs is a deriva- LATEX document, which is quite simple, AUC TEX tion of lisp called Emacs-lisp. Just as TEX allows can help a user perform certain tasks. The following you to associate functionality to a token, Emacs lets is an outline of the major features of AUC TEX. you bind functionality to the keys of your keyboard. • Insertion of templates for logical-structural When TEX implicitly inserts a \vbox whenever a plain letter is encountered, Emacs implicitly calls compositions such as environments and sec- the function self-insert-command (which simply tions. inserts the letter in the current buffer) whenever a • Hot-keys for easy access to certain often used key is pressed. Emacs-lisp is itself a fully featured constructs, e.g., font changes, accented letters, general-purpose language; this makes it possible to and mathematical symbols. make it behave anyway you want. At my site, Emacs is being used for many dif- • Running application programs (such as TEX), ferent applications, from various kinds of text edit- and then parsing the output so that errors in ing (such as source code) to Mail and Usenet news the document may be located easily. reading. The low-level editing features of Emacs will • stay the same regardless of the current application. Support for multi-file documents. As a user becomes familiar with the basics of the • Online help for (LA)TEX error messages. editor, he will have only a few problems converting to a new application. • Outlining — i.e., manipulating the document as As many users are used to (and pleased with) a composition of nested/sequential logical con- Emacs, it is desirable to use Emacs for (LA)TEXedit- structs. ing too, and this is where AUC TEXentersatthe • Instant formatting and indentation of the ascii- scene. AUC TEX is a general customizable envi- document in order to make it easier to read. ronment for editing LATEX documents. It is written entirely in Emacs-lisp, which makes it (relatively) • ‘Completion’ (and thereby spell-checking) of easy to modify to suit personal taste and needs. partially written control sequences. 304 TUGboat, 13, Number 3 — Proceedings of the 1992 Annual Meeting GNU Emacs as a Front End to LATEX AUC TEX incorporates a large number of well- To insert some sectioning command, press C-c known facilities for user interfacing. At first glance, C-x, and you will be prompted for a command (sec- it may seem that it’s just too much, but it has been tion, chapter, etc.), a title, and a label for it. Again, put together in such a way that you can easily use AUC TEX will look at the document so far, and just parts of it, without even knowing about the rest. choose some appropriate default for the command, Though featuring a lot of fancy functionality, AUC in this case section. TEX still conforms to the standard Emacs environ- In general, environments are inserted with the ment — basic operations such as cursor movement C-c C-c sequence. Some of the environments have and file handling are the same. special handlers attached to them: if you are in- Many of the features of AUC TEX which are not serting a figure environment, it will ask for place- basic Emacs functionality are implemented conform- ment modifiers, label, caption and whether the fig- ing to certain unwritten conventions, so that if you ure should be centered or not. have already tried some other Emacs mode, such as Completion. Since you have now specified the doc- C-mode for instance, you will simply know what do ument style and options, AUC T Xisnow(inprin- do. E ciple) aware of all the commands you may use in this Writing a LATEXDocument particular document. One of the AUC TEXadvan- tagesistoallowcompletion in various situations. To I guess it is about time to let you know how it really try this, type C-c C-c again, and press TAB.AUC works. We will now go on a little journey through TEX will now display a list of all the environments the world of AUC TEXand explore some of its fea- you can possibly use in the current document. If, tures. for example, you want to insert a verbatim environ- ment, just type ver TAB,andAUCTX will com- Getting started. To start AUC TEXyousimply E A plete the word verbatim for you. In case more en- run Emacs, with a L TEX file as argument: vironments start with the sequence ver, it will com- prompt$ emacs myfile.tex plete as much as it unambiguously can, and display Emacs will start and enter LATEXmode.Ifyouhave a new list of possible completions. already started Emacs, you may enter LATEXmode, Another, more general application of comple- by typing M-x latex-mode.1 tion is the completion of control sequences. Type The first thing you are likely to do is to insert a part of some command, and press ESC TAB.If a template for the overall document structure. To you want to insert the command \thispagestyle, do this, press C-c C-c. You will be prompted to in- which is very long and tedious to type in, especially sert an environment. Since the document is empty since you are likely to introduce an error, you can so far, AUC TEX will choose document as the de- simply type fault environment. Now type RET and you will be \this ESC TAB prompted for a document style, which defaults to article.TypingRET once more will prompt you and AUC TEX will complete the entire command for a list of style options. Write something and type \thispagestyle for you. As before, a list of possi- RET again. Now AUC TEX will display a template ble completions will be displayed in case of ambigu- something like the following on your screen: ity. \documentstyle[a4,12pt,dk]{article} Invoking LATEX \begin{document} Now suppose you’d like to process the contents of _ the buffer, i.e., run the file through LATEX. This is \end{document} handled very easily from within AUC TEX. Press and the cursor will be placed at the _. C-c C-a (Mnemonic: do it all), and the current 1 Emacs keying sequences are usually a combi- view will be split in two, of which the lower half nation of Control +anotherkey,orMeta +an- is used for TEX output, while you can still edit the other key. Thus, the notation C-x means “while document in the upper half. holding down the Control key, type the x key”; M-x AUC TEX also allows you to process only part means “press and release the Meta key (which can of a document. This is done by marking the region be system-dependent) and then type the x.” Combi- you’d like to have processed, and pressing C-c C-d don’t nations of sequences (such as C-c C-x), or combina- (Mnemonic: try to remember it). A temporary A tions of sequences + explicit words (such as Meta-x file to be processed by (L )TEX will then be created latex-mode) are also possible. in the current directory, in which AUC TEX will put TUGboat, 13, Number 3 — Proceedings of the 1992 Annual Meeting 305 Kresten Krab Thorup the preamble there (i.e., from \documentstyle to ) \begin{document}), after the marked region, and The parsing of this construct is complicated some- then insert an \end{document} in the bottom. what by the fact that other log messages may ac- Multi-file documents. In case your document is tually be any arbitrary text, and especially paren- spread over several files, AUC TEX can handle that theses, which may be unbalanced, and perhaps even too. If you insert the sequence: followed by things that may look like file names. %% Master: somefile.tex The Big Picture then the file somefile.tex will be the file actually to be formatted if you invoke C-c C-a. Also, if you Several features of AUC TEX are aimed at making invoke C-c C-d to format just a part of the docu- it easy to overview your document. This can be a ment, then the preamble will be sought in that file. great help, especially if you must edit documents not Another mechanism is also provided. If you written by yourself. In this talk, I will describe the have neither specified a %% Master line, nor does features for formatting, and outlining. your document contain a proper preamble, then Formatting When you write a document using AUC T X will insert a command to load the file E AUC TEX, you will notice that the text is automat- in the beginning of the file, which is texheader.tex ically formatted and indented as you write it.