% $Id: usingtex.tex,v 1.5 2020/01/01 23:29:59 karl Exp $ % This is part of the book TeX for the Impatient. % Copyright (C) 2003-2020 Paul W. Abrahams, Kathryn A. Hargreaves, Karl Berry. % See file fdl.tex for copying conditions. \input macros \chapter{Using \TeX} \chapterdef{usingtex} % Avoid underfull box complaint about the empty paragraph % that precedes the first section heading. % \def\par{{\parfillskip = 0pt plus 1fil\endgraf}\let\par=\endgraf} \vglue-\abovesectionskip % we've skipped enough already \vskip0pt % Make \combineskips work. \section Turning input into ink \subsection Programs and files you need In order to produce a \TeX\ document, you'll need to run the \TeX\ program and several related programs as well. You'll also need supporting files for \TeX\ and possibly for these other programs. In this book we can tell you about \TeX, but we can't tell you about the other programs and the supporting files except in very general terms because they depend on your local \TeX\ environment. The people who provide you with \TeX\ should be able to supply you with what we call \emph{local information}. \pix^^{local information} The local information tells you how to start up \TeX, how to use the related programs, and how to gain access to the supporting files. Input to \TeX\ consists of a file of ordinary text that you can prepare with a ^{text editor}. A \TeX\ input file, unlike an input file for a typical word processor, doesn't ordinarily contain any invisible ^{control characters}. Everything that \TeX\ sees is visible to you too if you look at a listing of the file. Your input file may turn out to be little more than a skeleton that calls for other input files. \TeX\ users often organize large documents such as books this way. You can use the ^|\input| command (\xref\input) to embed one input file within another. In particular, you can use |\input| to incorporate files containing \emph{macro definitions}---% ^^{macros//in auxiliary files} auxiliary definitions that enhance \TeX's capabilities. If any macro files are available at your \TeX\ installation, the local information about \TeX\ should tell you how to get at the macro files and what they can do for you. The standard form of \TeX, the one described in this book, incorporates a collection of macros and other definitions known as ^{\plainTeX} (\xref{\plainTeX}). When \TeX\ processes your document, it produces a file called the ^{\dvifile}. The abbreviation ``|dvi|'' stands for ``device independent''. The abbreviation was chosen because the information in the \dvifile\ is independent of the device that you use to print or display your document. To print your document or view it with a \emph{previewer}, ^^{previewer} you need to process the ^{\dvifile} with a \emph{device driver\/} program. ^^{device drivers} (A previewer is a program that enables you to see on a screen some approximation of what the typeset output will look like.) Different output devices usually require different device drivers. After running the device driver, you may also need to transfer the output of the device driver to the printer or other output device. ^^{printers} ^^{output devices} The local information about \TeX\ should tell you how to get the correct device driver and use it. Since \TeX\ has no built-in knowledge of particular fonts, it uses \emph{font files} ^^{font files} to obtain information about the fonts used in your document. The font files should also be part of your local \TeX\ environment. Each font normally requires two files: one containing the dimensions of the characters in the font (the \emph{metrics file}) ^^{metrics file} and one containing the shapes of the characters (the \emph{shape file}). ^^{shape file} Magnified versions of a font share the metrics file but have different shape files. ^^{magnification} Metrics files are sometimes referred to as ^{\tfmfile}s, and the different varieties of shape files are sometimes referred to as ^{\pkfile}s, ^{\pxlfile}s, and ^{\gffile}s. These names correspond to the names of the files that \TeX\ and its companion programs use. For example, |cmr10.tfm| is the metrics file for the |cmr10| font (10-point Computer Modern Roman). \TeX\ itself uses only the metrics file, since it doesn't care what the characters look like but only how much space they occupy. The device driver ordinarily uses the shape file, since it's responsible for creating the printed image of each typeset character. Some device drivers need to use the metrics file as well. Some device drivers can utilize fonts that are resident in a printer and don't need shape files for those fonts. \secondprinting{\vfill\eject} \subsection Running {\TeX} \bix^^{running \TeX} You can run \TeX\ on an input file |screed.tex| by typing ^^{input files} something like `|run tex|' or just `|tex|' (check your local information). \TeX\ will respond with something like: % 4/23/90 is Shakespeare's 426th birthday, and Karl's 26th. \csdisplay This is TeX, Version 3.0 (preloaded format=plain 90.4.23) ** | The ``preloaded format'' here refers to a predigested form of the ^{\plainTeX} macros that come with \TeX. You can now type `|screed|' to get \TeX\ to process your file. When it's done, you'll see something like: \csdisplay (screed.tex [1] [2] [3] ) Output written on screed.dvi (3 pages, 400 bytes). Transcript written on screed.log. | displayed on your terminal, or printed in the record of your run if you're not working at a terminal. Most of this output is self-explanatory. The numbers in brackets are page numbers that \TeX\ displays when it ships out each page of your document to the \dvifile. \TeX\ will usually assume an extension `|.tex|' to an input file name if the input file name you gave doesn't have an extension. For some forms of \TeX\ you may be able to invoke \TeX\ directly for an input file by typing: \csdisplay tex screed | or something like this. Instead of providing your \TeX\ input from a file, you can type it directly at your terminal. To do so, type `^|\relax|' instead of `|screed|' at the `|**|' prompt. \TeX\ will now prompt you with a `|*|' for each line of input and interpret each line of input as it sees it. To terminate the input, type a command such as `|\bye|' that tells \TeX\ you're done. Direct input is sometimes a handy way of experimenting with \TeX. When your input file contains other embedded input files, the displayed information indicates when \TeX\ begins and ends processing each embedded file. ^^{input files//embedded} \xrdef{infiles} \TeX\ displays a left parenthesis and the file name when it starts working on a file and displays the corresponding right parenthesis when it's done with the file. If you get any ^{error messages} in the displayed output, you can match them with a file by looking for the most recent unclosed left parenthesis. For a more complete explanation of how to run \TeX, see \knuth{Chapter~6} and your ^{local information}. \eix^^{running \TeX} \section Preparing an input file In this section we explain some of the conventions that you must follow in preparing input for \TeX\null. Some of the information given here also appears in the examples in \chapterref{examples} of this book. ^^{input, preparing} \subsection Commands and control sequences \bix^^{commands} \bix^^{control sequences} Input to \TeX\ consists of a sequence of commands that tell \TeX\ how to typeset your document. Most characters act as commands of a particularly simple kind: ``typeset me''. The letter `|a|', for instance, is a command to typeset an `a'. But there's another kind of command---a \emph{control sequence}---that gives \TeX\ a more elaborate instruction. A control sequence ordinarily starts with a backslash (|\|), though you can change that convention if you need to. \xrdef{@backslash} For instance, the input: \csdisplay She plunged a dagger (\dag) into the villain's heart. | contains the control sequence |\dag|; it produces the typeset output: \display{% She plunged a dagger (\dag) into the villain's heart. } \noindent Everything in this example except for the |\dag| and the spaces acts like a ``typeset me'' command. We'll explain more about spaces on \xrefpg{spaces}. There are two kinds of control sequences: \emph{control words} ^^{control words} and \emph{control symbols}: ^^{control symbols} \ulist\compact \li A control word consists of a backslash followed by one or more letters, e.g., `|\dag|'. The first character that isn't a letter marks the end of the control word. \li A control symbol consists of a backslash followed by a single character that isn't a letter, e.g., `|\$|'. The character can be a space or even the end of a line (which is a perfectly legitimate character). \endulist \noindent A control word (but not a control symbol) absorbs any spaces or ends of line that follow it. ^^{control sequences//absorbing spaces} If you don't want to lose a space after a control word, follow the control sequence with a ^{control space} (|\!visiblespace|) or with `|{}|'. Thus either: \csdisplay The wonders of \TeX\!visiblespace!.shall never cease!! | or:\hfil\ \csdisplay The wonders of \TeX{} shall never cease!! | produces: \display{% The wonders of \TeX{} shall never cease! } \noindent rather than: \display{% The wonders of \TeX shall never cease! } \noindent which is what you'd get if you left out the `|\|\visiblespace' or the `|{}|'. Don't run a control word together with the text that follows it---\TeX\ won't know where the control word ends. For instance, the |\c| control sequence places a cedilla accent on the character that follows it. The French word {\it gar\c con\/} must be typed as `|gar\c!visiblespace!.con|', not `|gar\ccon|'; if you write the latter, \TeX\ will complain about an undefined control sequence |\ccon|. A control symbol, on the other hand, doesn't absorb anything that follows it. Thus you must type `\$13.56' as `|\$13.56|', not `|\$!vs13.56|'; the latter form would produce `\hbox{\$ 13.56}'. However, those accenting commands that are named by control symbols are defined in such a way that they produce the effect of absorbing a following space. Thus, for example, you can type the French word {\it d\'eshabiller\/} either as `|d\'eshabiller|' or as `|d\'!visiblespace!.eshabiller|'. Every control sequence is also a command, but not the other way around. ^^{commands//versus control sequences} ^^{control sequences//versus commands} For instance, the letter `|N|' is a command, but it isn't a control sequence. In this book we ordinarily use ``command'' rather than ``control sequence'' when either term would do. We use ``control sequence'' when we want to emphasize aspects of \TeX\ syntax that don't apply to commands in general. \eix^^{control sequences} \eix^^{commands} \subsection Arguments \xrdef{arg1} Some commands need to be followed by one or more \emph{arguments} ^^{arguments} that help to determine what the command does. For instance, the |\vskip| command, which tells \TeX\ to skip down (or up) the page, expects an argument specifying how much space to skip. To skip down two inches, you would type `|\vskip 2in|', where |2in| is the argument of |\vskip|. Different commands expect different kinds of arguments. Many commands expect dimensions, such as the |2in| in the example above. Some commands, particularly those defined by macros, expect arguments that are either a single character or some text enclosed in braces. Yet others require that their arguments be enclosed in braces, i.e., they don't accept single-character arguments. The description of each command in this book tells you what kinds of arguments, if any, the command expects. In some cases, required braces define a group (see \xref{bracegroup}). \secondprinting{\vfill\eject} \subsection Parameters \xrdef{introparms} Some commands are parameters (\xref{parameter}). ^^{parameters//as commands} You can use a parameter in either of two ways: \olist \li You can use the value of a parameter as an argument to another command. For example, the command \hbox{|\vskip\parskip|} causes a vertical skip by the value of the |\parskip| (paragraph skip) glue parameter. \li You can change the value of the parameter by assigning something to it. For example, the assignment \hbox{|\hbadness=200|} causes the value of the |\hbadness| number parameter to be $200$. \endolist \noindent We also use the term ``parameter'' to refer to entities such as |\pageno| that are actually registers but behave just like parameters. ^^{registers//parameters as} Some commands are names of tables. These commands are used like parameters, except that they require an additional argument that specifies a particular entry in the table. For example, |\catcode| names a table of category codes (\xref{category code}). Thus the command \hbox{|\catcode`~=13|} sets the category code of the `|~|' character to $13$. \subsection Spaces \xrdef{spaces} \bix^^{spaces} You can freely use extra spaces in your input. Under nearly all circumstances \TeX\ treats several spaces in a row as being equivalent to a single space. For instance, it doesn't matter whether you put one space or two spaces after a ^{period} in your input. Whichever you do, \TeX\ performs its end-of-sentence maneuvers and leaves the appropriate (in most cases) amount of space after the period. \TeX\ also treats the end of an input line as equivalent to a space. Thus you can end your input lines wherever it's convenient---% \TeX\ makes input lines into paragraphs in the same way no matter where the line breaks are in your input. A blank line in your input marks the end of a paragraph. ^^{paragraphs//ending} Several blank lines are equivalent to a single one. \TeX\ ignores input spaces within math formulas (see below). Thus you can include or omit spaces anywhere within a math formula---\TeX\ doesn't care. Even within a math formula, however, you must not run a control word together with a following letter. If you are defining your own macros, you need to be particularly careful about where you put ends of line in their definitions. It's all too easy to define a macro that produces an ^{unwanted space} in addition to whatever else it's supposed to do. We discuss this problem elsewhere since it's somewhat technical; see \xrefpg{unwantedspace}. A space or its equivalent between two words in your input doesn't simply turn into a space character in your output. A few of these input spaces turn into ends of lines in the output, since input lines generally don't correspond to output lines. The others turn into spaces of variable width called ``glue'' (\xref{glue}), which has a natural size (the size it ``wants to be'') but can stretch or shrink. When \TeX\ is typesetting a paragraph that is supposed to have an even right margin (the usual case), it adjusts the widths of the glue in each line to get the lines to end at the margin. (The last line of a paragraph is an exception, since it isn't ordinarily required to end at the right margin.) You can prevent an input space from turning into an end of line by using a ^{tie} (^|~|). For example, you wouldn't want \TeX\ to put a line break between the `Fig.' and `8' of `Fig.~8'. By typing `|Fig.~8|' you can prevent such a line break. \eix^^{spaces} \needspace{2in} \subsection Comments \xrdef{comments} \pix\bix^^{comments} You can include comments in your \TeX\ input. When \TeX\ sees a comment it just passes over it, so what's in a comment doesn't affect your typeset document in any way. Comments are useful for providing extra information about what's in your input file. For example: \csdisplay % ========= Start of Section `Hedgehog' ========= | {\indexchar % }% A comment starts with a percent sign (|%|) and extends to the end of the input line. \TeX\ ignores not just the comment but the end of the line as well, so comments have another very important use: connecting two lines so that the end of line ^^{line breaks//deleting} between them is invisible to \TeX\ and doesn't generate an output space or an end of line. For instance, if you type: \csdisplay A fool with a spread% sheet is still a fool. | you'll get: \display{ A fool with a spread% sheet is still a fool. } \eix^^{comments} \subsection Punctuation \null \xrdef{periodspacing} \TeX\ normally adds some extra space after what it thinks is a ^{punctuation} mark at the end of a sentence, namely, `^|.|', `^|?|', or `|!!|' \indexchar ! ^^{period} ^^{question mark} ^^{exclamation point} followed by an input space. \TeX\ doesn't add the extra space if the punctuation mark follows a capital letter, though, because it assumes the capital letter to be an initial in someone's name. You can force the extra space where it wouldn't otherwise occur by typing something like: \csdisplay A computer from IBM\null? | The |\null| doesn't produce any output, but it does prevent \TeX\ from associating the capital `M' with the question mark. On the other hand, you can cancel the extra space where it doesn't belong by typing a control space after the punctuation mark, e.g.: \csdisplay Proc.\!visiblespace!.Royal Acad.\!visiblespace!.of Twits | so that you'll get: \display{Proc.\ Royal Acad.\ of Twits} \noindent rather than: \display{Proc. Royal Acad. of Twits} Some people prefer not to leave more space after punctuation at the end of a sentence. You can get this effect with the ^|\frenchspacing| command (\xref\frenchspacing). |\frenchspacing| is often recommended for ^{bibliographies}. For single ^{quotation marks}, you should use the left and right single quotes (|`| and |'|) on your keyboard. For left and right double quotation marks, use two left single quotes or two right single quotes (|``| or |''|) rather than the double quote (|"|) on your keyboard. The keyboard double quote will in fact give you a right double quotation mark in many fonts, but the two right single quotes are the preferred \TeX\ style. For example: \csdisplay There is no `q' in this sentence. ``Talk, child,'' said the Unicorn. She said, ``\thinspace`Enough!!', he said.'' | These three lines yield: \display{\par\restoreplainTeX There is no `q' in this sentence. \par ``Talk, child,'' said the Unicorn. \par She said, ``\thinspace`Enough!', he said.'' } \noindent The |\thinspace| in the third input line prevents the single quotation mark from coming too close to the double quotation marks. Without it, you'd just see three nearly equally spaced quotation marks in a row. \TeX\ has three kinds of ^{dashes}: \ulist \li Short ones (hyphens) like this ( - ). You get them by typing~`^|-|'. \li Medium ones (en-dashes) like this ( -- ). You get them by typing~`^|--|'. \li Long ones (em-dashes) like this ( --- ). You get them by typing~`^|---|'. \endulist \vskip0pt plus2pt % this page is spacey, just live with it \eject \noindent Typically you'd use hyphens to indicate compound words like ``will-o'-the-wisp'', en-dashes to indicate page ranges such as ``pages~81--87'', and em-dashes to indicate a break in continuity---like this. \subsection Special characters Certain characters have special meaning to \TeX, so you shouldn't use them in ordinary text. They are: \csdisplay $ # & % _ ^ ~ { } \ | ^^|$//in ordinary text| ^^|#//in ordinary text| ^^|&//in ordinary text| ^^|_//in ordinary text| ^^|^//in ordinary text| ^^|~//in ordinary text| ^^|%//in ordinary text| ^^|{//in ordinary text| ^^|}//in ordinary text| {\recat!ttidxref[\//in ordinary text]] \noindent In order to produce them in your typeset document, you need to use circumlocutions. For the first five, you should instead type: ^^|\$| ^^|\#| ^^|\&| ^^|\%| ^^|\_| \csdisplay \$ \# \& \% \_ | \noindent For the others, you need something more elaborate: \csdisplay \^{!visiblespace} \~{!visiblespace} $\{$ $\}$ $\backslash$ | \subsection Groups \bix^^{groups} A \emph{group} consists of material enclosed in matching left and right braces (|{| and |}|). ^^|{//starting a group| ^^|}//ending a group| By placing a command within a group, you can limit its effects to the material within the group. For instance, the |\bf| command tells \TeX\ to set something in {\bf boldface} type. If you were to put |\bf| into your input and do nothing else to counteract it, everything in your document following the |\bf| would be set in boldface. By enclosing |\bf| in a group, you limit its effect to the group. For example, if you type: \csdisplay We have {\bf a few boldface words} in this sentence. | \noindent you'll get: \display{We have {\bf a few boldface words} in this sentence.} \noindent You can also use a group to limit the effect of an assignment to one of \TeX's parameters. These parameters contain values that affect how \TeX\ typesets your document. For example, the value of the |\parindent| parameter specifies the indentation at the beginning of a paragraph. The assignment |\parindent = 15pt| sets the indentation to $15$ printer's points. By placing this assignment at the beginning of a group containing a few paragraphs, you can change the indentation of just those paragraphs. If you don't enclose the assignment in a group, the changed indentation will apply to the rest of the document (or up to the next assignment to |\parindent|, if there's a later one). \xrdef{bracegroup} Not all pairs of braces indicate a group. In particular, the braces associated with an argument for which the braces are \emph{not} required don't indicate a group---they just serve to delimit the argument. Of those commands that do require braces for their arguments, some treat the braces as defining a group and the others interpret the argument in some special way that depends on the command.\footnote {More precisely, for primitive commands either the braces define a group or they enclose tokens that aren't processed in \TeX's stomach. For |\halign| and |\valign| the group has a trivial effect because everything within the braces either doesn't reach the stomach (because it's in the template) or is enclosed in a further inner group. ^^|\halign//grouping for| ^^|\valign//grouping for| } \eix^^{groups} \subsection Math formulas \bix^^{math} \xrdef{mathform} A math formula can appear in text (\emph{text math}) ^^{text math} or set off on a line by itself with extra vertical space around it (\emph{display math}). ^^{display math} You enclose a text formula in single dollar signs (|$|) and a displayed formula in double dollar signs (|$$|). \ttidxref{$}\ttidxref{$$} For example: \csdisplay If $a