Typesetting with TEX and LATEX
Total Page:16
File Type:pdf, Size:1020Kb
Typesetting with TEX and LATEX Alan Hoenig 17 Bay Avenue Huntington, NY 11743 [email protected] (This presentation appears in a considerably ex- TEX in the public domain. The logo ‘TEX’ is related panded form as chapter 1 of my book TEX Unbound: to the Greek root ‘τχ’ from whence come words LATEXandTEX Strategies for Fonts, Graphics, and like ‘technology’. If pronounced properly, the face More published just this year by the Oxford of your listener may become slightly moist (but no University Press.) one complains if you say ‘tek’). By typesetting, we mean the ability to place el- The purpose of this survey is to acquaint read- ements of a document on a page according to gen- ers with the aspects of the TEX cycle necessary to erally accepted principles which most people seem produce handsome papers and books. This presen- to agree look best and make it easiest to read and tation should not be regarded as a be-all-and-end- comprehend the document. It’s surprisingly diffi- all tutorial, since (like many other mature and so- cult to do that — a typesetter has to decide how phisticated software systems) lengthy books are not best to break paragraphs into lines, how to hyphen- enough to do full justice to it. ate words, how to leave space for footnotes, how to prepare indexes and the other detritus of scholarly The TEX production cycle publishing, and provide the optimum space between Why is ‘typesetting’ not the same thing as ‘word elements on the page (among many other things). processing’? Typically, a word processor allows edit- The spacing issue is particularly critical for techni- ing of the document, but in its impatience to display cal documents. Formulas make extensive use of ar- the results immediately onscreen (most word proces- cane symbols which have different appearances and sors are aggressively wysiwyg in behavior), certain spacing depending on context. Consider, for exam- niceties are sacrificed. These niceties — fine control ple, how the placement and spacing of the ordinary of spacing, word placement, hyphenation, and so numeral ‘2’ changes in forth — are never ignored in TEX. 2 x2 2xx e− It’s useful to consider the TEX production cycle and how the spacing surrounding minus sign changes by comparing it with that of word processors. In a in word processor, the program assists you in preparing x y and x + y the document, after which it is printed. TEX relies − − on three steps. Other symbols may change depending upon whether the equation appears in text ‘ xdx’ or display 1. We use a text editor to prepare the source docu- mode: ment — the document file which consists of the R text and data of your document together with xdx. the TEX formatting commands. Let’s suppose Furthermore, if a computerZ system is going to con- this file is called myfile.tex. trol the typesetting, we expect more of it than from 2. We run myfile.tex through the T X program. a mere human. We may expect, for example, to be E If all goes well, this generates a file in which the able to label an equation in some logical way and typesetting commands are made explicit using then refer to it later by this label in our source doc- a generic printer description language indepen- ument. It would be up to the typesetter to resolve dent of any particular printer; it is device inde- these labels and references and replace the labels by pendent.TX names this file myfile.dvi.Just properly formatted label numbers. E like a computer program source file with syn- The T X system has been freely available since E tax errors, if there are any errors, we return to the mid-80s or so and accomplishes all of the above step 1 and correct them before continuing. tasks (and more) in a particularly effective manner. TEX is the creation of Donald E. Knuth of Stanford 3. Finally, we need the assistance of a special de- University, who has placed all the source code for vice driver customized to the printer. It’s the TEXNorthEast Conference, March 22 – 24, 1998 168 TUGboat, Volume 19 (1998), No. 2 169 driver’s task to translate the generic dvi com- see, LATEXisthesameasTEX, so these procedures mands into the form the printer understands. follow for a LATEX document as well. The advantages of creating a .dvi file are that 1. Use a text editor to create the source document we can print the document on any printer (at least, for subsequent processing by TEX. The source any printer for which device drivers exist) and rest document is the document file — text and type- assured that the output is identical on each device setting commands. Take care not to use a word (except for raster resolution). processor. These programs aim to do the for- matting themselves, and tend to do so by insert- Macros; logical document design ing non-Ascii characters into the document file. TEX has been called an assembly language for type- Quite apart from the fact that TEX(orLATEX) setting. This means that there are plenty of primi- needs no help with the typesetting, these binary tive commands to control fine points, but these com- characters will only confuse TEX. (If it is neces- mands may not be entirely appropriate for creating sary to use a word processor, make sure to save a new section head or aligned equation. As a re- the document in some way so as not to include sult, TEX has a rich and powerful macro creation the word processing formatting information.) facility. It’s possible (as we will see later) to string 2. Run this source file through the TEX program. primitive commands and pre-existing macro com- the simplest form of the command to do that is mands together to create new, custom typesetting commands. tex myfile Remember that the T X production cycle E where the source file has the name myfile.tex. means that we prepare a source file which is fed LATEX users will use the command into TEX at a later point. This plus the nature of the macros means that TEX supports the notion of tex &lplain myfile logical document design. We can embed components (Unix users may have to enter the ampersand of the document by means of tags which can be as \&.) defined or redefined depending upon context. One example suffices. Here’s a theorem. As in any compilation process, TEX may un- Theorem There is no royal road to typesetting. cover errors. (Warnings may be ignored, at Computer typesetting is a surprisingly least at this stage.) Return to step 1 to cor- complex task. rect these errors, and re-run it through TEX. This was typeset by means of inserting Repeat this process until all errors have been dealt with (or until there is enough of a docu- \theorem There ... ment to print.) in the source document. It may happen that it is The result of a successful T X compilation is more appropriate to display that theorem as E a new file with a dvi extension. In this example, Theorem There is no royal road we would have a new file myfile.dvi. to typesetting. Computer typeset- ting is a surprisingly complex task. 3. With the document in hand, it can be printed or The same command string will accomplish this pro- previewed on screen. In each case, appropriate vided that only the macro definition of \theorem device drivers are necessary to properly render needs be changed. The implications are enormous — the document on screen or on paper. we can design our document so that it will properly As we see, the TEX process is actually a con- printed for any set of particular formatting require- certed action between several programs in addition ments provided only that we change the particular to TEX — a text editor, a device driver, and a definitions of the macros. Many strategies exist for screen previewer. Many implementations of TEX facilitating this use of definitions. may merge several or all of these into one integrated module. AfirstTEX document The TEX document: input conventions The “steps” for generating a TEX document are well- defined, but there are sufficiently idiosyncratic im- Although it is not practical or possible to deal with plementations of TEX floating around so that it may all or even a completely useful subset of all TEX(or be necessary to adapt these procedures to a local LATEX) commands in this article, it is possible to adaptation. By the way, some readers may be inter- summarize the keyboard conventions that any TEX estedintheTEX dialect called ‘LATEX’; as we will typesetting must adhere to. TEXNorthEast Conference, March 22 – 24, 1998 170 TUGboat, Volume 19 (1998), No. 2 White space. TEX normally regards all white ‘‘Oh, the selfish shell-fish---that space as equivalent, where we include carriage re- lobster mobster---tasted turns, tabs, and of course spaces in this category. best when basted west,’’ quoth Aaron Furthermore, multiple spaces are generally equiva- while reading lent to a single space. Important exception: we pages~12--33 of his cookbook. signal the end of one paragraph and the beginning of to typeset another by skipping a line in the source file; that is, we enter two hard carriage returns in a row. (But “Oh, the selfish shell-fish — that lobster mob- three or more consecutive carriage returns is still ster — tasted best when basted west,” quoth equivalent to a pair of carriage returns.) Aaron while reading pages 12 – 33 of his cookbook.