With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

Chapter 2. Editing

This chapter describes several writing environments available for creating and modifying TeX documents. In practice, you can use almost any editing program you wish, but I'll focus on GNU emacs in this chapter. I've chosen GNU emacs for two reasons: it is a popular and very powerful editor available on many platforms (unix, NeXT, MS-DOS, OS/2, Macintosh, VMS, Amiga, $...$), and it has the most comprehensive TeX editing environment that I've ever seen. At the end of the chapter, I'll discuss several other editors for MS-DOS and OS/2 that also have TeX editing environments.

The sole requirement for a TeX editor is that it must save files in a flat, ASCII format without any additional formatting characters or special encodings. Word processors, such as Microsoft Word, usually add special formatting information to your document when they save it to disk. TeX will not understand this information, so you cannot use a word processor to edit TeX documents.[17]

A program that allows you to edit flat ASCII files is usually called an editor (as opposed to a word processor, for example). Choosing an editor is a remarkably personal decision. Computer programmers and other people who use editors every day frequently become very attached to a particular editor. This chapter explores a number of features that an editor can provide to make editing TeX documents easier. If possible, choose an editor that offers these features. In any event, make sure you choose an editor you will be comfortable using. You'll spend a lot of time using it.

Many editors have some sort of built-in programming language. The features described in this chapter rely on modifying the behavior of the editor with its programming language. This does not mean that you will have to do any programming. All of the editors discussed in this chapter have TeX editing environments already available. However, if you use another editor and it doesn't have a programming language, it's unlikely that these features will be available to you.

The next section explores some helpful editor features. All of the editors in this chapter provide some or all of the features discussed, and require little or no programming on your part.

What Can an Editor Do?

You will do most of your work with TeX in the editor. There are two ways that an editor can help you edit TeX documents. One is to provide typing shortcuts that are either intuitive replacements for cumbersome operations or quick ways of typing common TeX commands. The other way that an editor can help is by running TeX for you and automatically displaying the location of formatting errors in your document.

Quoting Automatically

Most typewriters and many word processors use the same symbol for opening and closing quotations. You are probably used to typing the double-quote key to insert quotation marks into your text. However, if you look carefully at TeX output (or any professionally typeset document) you will notice that the opening and closing quotation marks do not look the same. The proper way to type an opening quote (“) in TeX is with two single back-quotes in a row (). A closing quote (”) is entered with two single quotes (apostrophes) in a row (''). This process is tedious and error-prone since you are used to typing something else.

If you accidentally use the double quote symbol in your input, you most frequently get text that looks like ”this.” The exact result is actually dependent upon the font you are using. This is explained in Chapter 5, Chapter 5. Most programmable editors can change the meaning of the double-quote key to insert the correct quotation marks.

If you are interested in programming your editor to do this, you can use the following algorithm to select the correct quotation marks most of the time: if the character to the immediate left of the cursor is a space, opening brace, parenthesis, or bracket, insert opening quotes; otherwise, insert closing quotes. As a further enhancement, double quotes should be inserted immediately following a backslash.

Matching Braces

Braces, as mentioned in Chapter 1, Chapter 1, are used by TeX to delimit sections of text; they appear often in TeX documents. GNU emacs, Multi-Edit, and Brief can all be programmed to highlight the matching open brace whenever you type a closing brace.

For example, if you have entered the text

\footnote{This is {\it not} the only case.}

and the next character that you type is }, the open brace immediately following the word \footnote is highlighted, or all of the text between that brace and the current cursor position is highlighted. This feature makes it easier to find places where you have forgotten to insert a closing brace.

If you usually work in “insert” mode, you may also find it convenient to have the editor insert braces in pairs and then insert text between them. This can be accomplished in almost any editor that can be programmed, even one that isn't equipped to handle brace matching.

Inserting Common Control Sequences

Most editors can be programmed to insert arbitrary text when a special key is pressed. This feature can be used to insert common control sequences. For example, you might have Alt-c insert the \chapter control sequence or Ctrl-e insert \begin{enumerate}.

Running TeX Automatically

One of the nicest features that an editor can provide is the ability to run TeX automatically without leaving the editor. This is a feature that programmers demand because it allows them to run compilers directly from the editor. Editors that provide this feature usually include some mechanism for programming the editor to locate the position of errors reported by the compiler. The editor searches for error messages in the output generated by the compiler, and it positions the cursor at the location of each error. This speeds up the traditional edit/compile/debug cycle of programming. You can take advantage of these features to shorten the edit/typeset/rewrite cycle of creating a TeX document.

All of the editors discussed in this chapter can easily be adapted to run TeX in this way. If you already have a favorite editor and want to add this functionality for TeX, see the section “the section called “Running TeX”” later in this chapter; it describes the process at a very general level.

GNU Emacs

This section describes the TeX modes distributed as part of GNU emacs. Emacs is one of the most popular and most powerful editors around. Distributed by the Free Software Foundation (FSF), GNU emacs is the de facto standard editor in many unix environments. Recently, GNU emacs has been ported to many other platforms, including MS-DOS (demacs), OS/2, Macintosh, VMS, Amiga, and NeXT.

This section and the following section on aucTeX assume that you are familiar with general emacs concepts. In particular, you should be familiar with the concepts of buffers, files, regions, command keys, editing modes, and prefix arguments. If you are unfamiliar with these concepts, you can learn about them in the online help, called Info pages, for GNU emacs. Info pages should be available by pressing Ctrl-H i in emacs. You can also consult a reference to GNU emacs, such as Learning GNU Emacs [or:emacs] for more information.

Customizing some of the features of GNU emacs requires familiarity with GNU emacs lisp, which is also described in the Info pages.

Starting TeX Mode

GNU emacs provides two similar TeX editing modes: one designed for editing Plain TeX documents (plain-tex-mode) and the other for editing LaTeX documents (latex-mode). The latex-mode is a superset of plain-tex-mode that provides additional shortcut keys for some LaTeX control sequences.

There are three ways to start TeX mode in GNU emacs:

 M-x tex-mode Attempts to select the correct mode. M-x plain-tex-mode Always selects Plain TeX mode. M-x latex-mode Always selects LaTeX mode.

If you use M-x tex-mode, emacs examines the top of the buffer in order to select the appropriate mode. If the control sequences \documentstyle or \begin{document} occur near the top of the buffer, latex-mode is selected; otherwise, the default mode is selected. The default mode is stored in the emacs lisp variable TeX-default-mode.

You can also tell emacs to invoke TeX mode automatically whenever you edit a file that has a name ending in .tex. To do so, add the following lines to your emacs startup file, usually called .emacs in your home directory:[18]

% #1 = "Id"
% #2 = filename
% #3 = vers
% #4 = date
% #5 = time
% #6 = author
% #7 = state [locker]
\ifdraft
\setbox0=\hbox to 0pt{
\tolerance=100000
\parbox{4in}{
\rm\tiny #2\\ #3\\ #4}
\hss}
\marginpar{\box0}
\typeout{Draft Id: #2 #3 #4 #5 #6 #7}
\fi
}

TeX Shells

The iterative nature of TeX (edit, TeX, BibTeX, make indexes, preview, repeat) can be tedious to perform by hand. As a result, several TeX “shells” have been developed which provide a more automatic interface to many aspects of the TeX process. Several of these packages are described below. In everyday use, they make TeX much more user friendly.

TeXShell

TeXShell was designed as an add-on for emTeX (it installs directly into the emTeX directory hierarchy). This character-based interface is available for both MS-DOS and OS/2. TeXShell provides an editor, a complete help system, and fully customizable push-button access to TeX. An example of the TeXShell interface is shown in Figure 2.8. The default TeX menu and help windows are shown.

Figure 2.8. TeXShell

TeXPert

TeXPert is a character-based shell for TeX. MS-DOS and OS/2 versions of TeXPert are available in either German or English. The default configuration files for TeXPert are designed to work with emTeX, but TeXPert does not install directly into the emTeX directory heirarchy. The TeXPert interface is shown in Figure 2.9.

Figure 2.9. TeXPert

TeXPert provides an editor, an archive tool for speedy access to commonly used files, and an interface to grep for quickly scanning files. The exact look and feel of TeXPert can be customized.

4TeX

The 4TeX system uses the 4DOS extended batch language and a number of utilities to integrate emTeX with a wide variety of free, shareware, and commercial tools. The system is well documented in a manual that describes installation, setup, use, and customization. The 4TeX interface is shown in Figure 2.10.

Figure 2.10. 4TeX

PMTeX

PMTeX is an OS/2 presentation manager program. Although it does not provide a built-in editor, it can control four independent DOS and OS/2 sessions, one each for editing, TeX processing, previewing, and printing. The options passed to each program can be controlled from the PMTeX Options menu.

PMTeX was designed to work with emTeX, but can be configured to use any TeX system. PMTeX was also designed to support two preprocessors for phonetic transcription: the TeuTeX-P and ALDTeX-P scanners. These scanners are useful in dialectology and are available separately from PMTeX's author.

A example of the PMTeX interface is shown in Figure 2.11. Note that the menu bar is very wide and does not fit in a standard 640x480 VGA window.

Figure 2.11. PMTeX

TeXit

The TeXit shell (which I wrote) is much less ambitious in many ways. Written entirely in Perl, TeXit does not offer a full screen interface or an editor at all. Instead, it provides a simple menu of choices as shown in Figure 2.12 (all of the menu choices are completely customizable).

Figure 2.12. TeXit

Processing: ./driver.tex
Again? [?]status, [T]eX & View, [b]ibtex, [c]leanup,
[e]dit a file, [p]rint, [q]uery printer, [t]ex,
[v]iew, e[x]it:

One of TeXit's strengths is its ability to parse the log file created by TeX and to determine when additional actions are required. For example, TeXit will recognize when a document contains unresolved references and citations and can automatically run BibTeX and repeatedly run TeX to resolve the references. With the addition of a few “user specified” rules in the document, TeXit can easily handle index construction and other more sophisticated relationships.

[17] Most word processors can be coerced into saving your document in plain text. If your word processor can do this, you may be able to edit TeX documents with it.

[18] On file systems that don't allow filenames to begin with a period, the name frequently begins with an underscore instead.

[19] That's one of the reasons that the regular GNU emacs TeX modes are described first.

[20] A 16MHz 386SX machine with only 8Mb of memory struggling to run GNU emacs under OS/2. ;-)

[21] A minor mode is a kind of editing environment provided by GNU emacs. If you are unfamiliar with minor modes, consult your emacs reference.

[22] There are two versions of the program; the one discussed here is the version for Windows.

[23] Or known to me, anyway.

[24] Unfortunately, parentheses can occur in the log file for other reasons.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required