<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <HTML> <HEAD> <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9"> <TITLE>The teTeX HOWTO: The Linux-teTeX Local Guide: TeX commands.</TITLE> <LINK HREF="TeTeX-HOWTO-4.html" REL=next> <LINK HREF="TeTeX-HOWTO-2.html" REL=previous> <LINK HREF="TeTeX-HOWTO.html#toc3" REL=contents> </HEAD> <BODY> <A HREF="TeTeX-HOWTO-4.html">Next</A> <A HREF="TeTeX-HOWTO-2.html">Previous</A> <A HREF="TeTeX-HOWTO.html#toc3">Contents</A> <HR> <H2><A NAME="s3">3. TeX commands.</A></H2> <P>Preparing documents for TeX typesetting is easy. Make sure there's a blank line between the paragraphs of a plain text file, and run file through the TeX program with the command <PRE> tex your_text_file </PRE> The result will be a file of the same base name and the extension <CODE>.dvi</CODE>. TeX formats the text in 10-point, Computer Modern Roman, single-spaced, with justified left and right margins. If you receive error messages from special characters like dollar signs, escape them with a backslash character, <CODE>\</CODE>, and run TeX on the file again. You should be able to process the resulting file with the <CODE>.dvi</CODE> file translator of your choice (see above) to get printed output. <P>One peculiarity of TeX input is that you must use opening and closing quotes, which are denoted in the input file with the grave accent and single quote characters. Emacs' TeX mode does this for you automatically. <PRE> "These are ASCII-type quotes." ``These are `TeX-style' quotes.'' </PRE> <P> <H2><A NAME="ss3.1">3.1 Command overview.</A> </H2> <P>Commands in TeX start with a backslash (``\''). For example, the command to change the spacing between lines is <PRE> \baselineskip=24pt </PRE> <P>The baseline is the bottom of the characters on a line, not counting descenders. The distance between the baseline of one line and the next is the <CODE>\baselineskip</CODE>, and is assigned a value of 24 points. <P>Measurements or dimensions in TeX are often given in the following units: <PRE> pt % Point 1/72 in. pc % Pica: 12 pt. in % Inch: 72.27 pt. cm % Centimeter: 2.54 cm = 1 in. mm % Millimeter: 10 mm = 1 cm. </PRE> <P>Some commands do not take assignments. For example: <PRE> \smallskip % Approximately 3 pt. \medskip % Two \smallskips. \bigskip % Two \medskips. </PRE> <P>A <CODE>\smallskip</CODE> inserts a 3 pt. vertical space in the document. The measurements are approximate because TeX needs to adjust the dimensions for page breaks, section headings, and other units of vertical space. This is true for horizontal spacing as well. <PRE> \hsize=6.5in </PRE> This command sets the line length to a width of 6.5 inches. TeX tries to fill the line by adjusting the spacing between words, and some letters. If TeX cannot fill a line to within its tolerances, it produces a warning message, and adjusts the horizontal spacing within the line as best it can. Formatting tolerances are discussed in Section <A HREF="#tolerances">Tolerances</A>. <P>There are many other commands that specify horizontal and vertical dimensions and tolerances, and the most commonly use commands are described below. <P> <H2><A NAME="tex-font-commands"></A> <A NAME="ss3.2">3.2 Font commands. </A> </H2> <P>In TeX, the default font is 10 pt. Computer Modern Roman. To specify a typeface, like italic, bold, or monospaced, use the following commands. <PRE> \rm % Roman (the default). \it % Italics. \bf % Bold. \tt % Monospaced (teletype). \sl % Oblique (slanted). </PRE> The commands change the typeface where they appear in the text, as in this example. <PRE> This text is Roman, \it and this text is italic. \bf This text is bold, and \rm this text is in Roman again. </PRE> <P>To specify a font for your document, use the<CODE>\font</CODE> command. <PRE> \font\romantwelve=cmr12 </PRE> This creates the font command <CODE>\romantwelve</CODE>, which, when used in the text, changes the font to Computer Modern Roman, 12 point. <PRE> \romantwelve This is the Computer Modern Roman font at 12 points. </PRE> For information about the fonts in the teTeX distribution look at the file: <PRE> /usr/lib/teTeX/texmf/doc/fonts/fontname/fontname.dvi </PRE> <P>If you want to print a sample of a font, TeX the file <PRE> /usr/lib/teTeX/texmf/tex/plain/base/fontchart.tex </PRE> and fill in the name of the font you want to print at the prompt. <P>You can also change the size of a font to get different effects. Font magnification is exponential, and specified with the <CODE>scaled \magstep</CODE> command, which is placed after the font specification. <PRE> \font\sfmedium=cmss12 scaled \magstep 1 </PRE> This command will give you a sans serif font that is 120 percent the size of the 12-point Computer Modern sans serif font. Fonts can be magnified in steps from 0 to 5. Each step provides and additional 120 percent magnification. <P> <H2><A NAME="para-dimen"></A> <A NAME="ss3.3">3.3 Paragraph styles and dimensions. </A> </H2> <P>As mentioned above, TeX typesets text in 10-point Computer Modern Roman by default. The length of a line is the value of <CODE>\hsize</CODE>, which defaults to 6.5 in. If you want to change the value of <CODE>\hsize</CODE> to 5.5 in. for example, use this command. <PRE> \hsize=5.5in </PRE> <P>In TeX a <EM>dimension</EM> is an adjustable unit of length, either horizontal or vertical. The amount by which a dimension can be increased or decreased can be specified in its definition. Closely related to a dimension is a <EM>skip,</EM> which is a dimension that is placed in one of TeX's internal registers. Skips are defined with the <CODE>\newskip</CODE> command. The <CODE>\smallskip</CODE> dimension, as defined by TeX is: <PRE> \newskip\smallskipamount \smallskipamount=3pt plus 1pt minus 1pt </PRE> The <CODE>\smallskip</CODE> command is shorthand for: <PRE> \vskip\smallskipamount </PRE> <P>There are a number of dimensions that control the page layout. They are summarized in Section <A HREF="#tex-page">Page layout</A>. <P>TeX formats paragraphs with justified left and right margins. If you want the text to be left justified only, use this command: <PRE> \raggedright </PRE> <P>To typeset a line that is justified to the right margin, use the <CODE>\rightline</CODE> command: <PRE> \rightline{This is the line to be typeset.} </PRE> <P>The <CODE>\line</CODE> command typesets the text of its argument to fill the entire line. <PRE> \line{This text will be spaced to fit the entire line.} </PRE> <P>The <CODE>\hfil</CODE> command adds space to fill out the line where it occurs. So, for example, the <CODE>\rightline</CODE> command is equivalent to: <PRE> \line{\hfilThis line will be right justified.} </PRE> <P>To typeset a line that is centered, use the <CODE>\centerline</CODE> command. <PRE> \centerline{This is the line to be centered.} </PRE> <P>To change the left margin, set the value of <CODE>\hoffset</CODE>, as in this example: <PRE> \hoffset=1.5in </PRE> <P>The <CODE>\parindent</CODE> command specifies the amount that the first line of every paragraph is indented. <PRE> \parindent=.5in </PRE> <P>Two other dimensions, <CODE>\leftskip</CODE> and <CODE>\rightskip</CODE>, will indent the right and left margins, respectively, of the paragraphs that come after them. <PRE> \leftskip=.5in \rightskip=.5in </PRE> The control word <CODE>\narrower</CODE> is equivalent to: <PRE> \leftskip=\parindent \rightskip=\parindent </PRE> That is, <CODE>\narrower</CODE> narrows the paragraph margins by the value of <CODE>\parindent</CODE> <P>As mentioned in the previous section, the <CODE>\baselineskip</CODE> specifies the distance between lines. The default is 12 pt. To approximate double-spaced text, use the following command. <PRE> \baselineskip=\baselineskip*1.6 </PRE> <P>The <CODE>\parskip</CODE> command specifies the distance in addition to <CODE>\baselineskip</CODE> between paragraphs. By default, no extra space is added, but the distance between paragraphs can stretch as much as 1 pt. to fill the page correctly. To put a blank line between paragraphs, use this command: <PRE> \parskip=\baselineskip </PRE> <P> <H3><A NAME="tolerances"></A> Tolerances. (What are those black rectangles after every line?)</H3> <P>TeX normally formats text to strict tolerances. If, for some reason, text cannot be formatted to within those tolerances, TeX produces a warning message and formats the text the best it can. If the text must be stretched too much to fit the line, TeX warns you that the <CODE>\hbox</CODE> is underfull. Text that must be squeezed to fit in the line produces an overfull <CODE>\hbox</CODE> warning. <P>For each overfull <CODE>\hbox</CODE>, TeX places a <EM>slug</EM>, a black rectangle, after the line. The slug indicates that the line could not be formatted to within the specifications set by the <CODE>\hbadness</CODE> parameter. <P>The fit of the text within its specified dimensions is measured by its <EM>badness</EM>, which is a number between 0 and 10000. A badness of 0 is a perfect fit, and a badness of 10000 means that the line probably will never fit. The default value of <CODE>\hbadness</CODE> is 1000. If you set <CODE>\hbadness</CODE> to 10000, TeX does not report underfull lines. <P>Sometimes TeX allows a line to extend past the right margin. This is an aesthetic decision on the part of TeX's author. The amount is determined by the <CODE>\hfuzz</CODE> parameter, which defaults to 0.1 pt. If the text does not fit within the line, the <CODE>\tolerance</CODE> parameter determines how TeX will handle the overfull <CODE>\hbox</CODE>. The default value of <CODE>\tolerance</CODE> is 200. Setting <CODE>\tolerance</CODE> to 1000 suppresses overfull <CODE>\hbox</CODE> warnings and the printing of slugs. <P> <H2><A NAME="tex-page"></A> <A NAME="ss3.4">3.4 Page layout. </A> </H2> <P>In addition to the left margin and line length dimensions that are described in the previous section, TeX also lets you specify top and bottom margins, and vertical spacing. <P>Like the <CODE>\hsize</CODE> and <CODE>\hoffset</CODE> dimensions described in the previous section, TeX also provides the <CODE>\vsize</CODE> and <CODE>\voffset</CODE> commands. The default for <CODE>\vsize</CODE> is 8.9 in., and <CODE>\voffset</CODE> defaults to 0. <P>Normally, teTeX places the beginning of the first line of text 1 in. below the top of the paper and 1 in. from the left edge. You can start the text closer to the top of the page with the command: <PRE> \voffset=-0.5in </PRE> <P>If you want to add vertical space in a document, the commands <CODE>\smallskip</CODE>, <CODE>\medskip</CODE>, and <CODE>\bigskip</CODE> will add approximately 3, 6, and 12 points of blank vertical space. These measurements are approximate; TeX will adjust them by as much as 1 pt. so the page is filled correctly. <P>The <CODE>\vfill</CODE> command adds an adjustable vertical space between paragraphs on a page. It is infinitely stretchable, so it will add vertical space to fill as much of the rest of the page as possible. If you want to specify a dimension, use <CODE>\vskip</CODE> as in: <PRE> \vskip 10pt </PRE> <P>The commands <CODE>\hss</CODE> and <CODE>\vss</CODE> are similar to <CODE>\hfil</CODE> and <CODE>\vfill</CODE>, but they provide dimensions that are infinitely shrinkable as well as infinitely stretchable. <P>The <CODE>\vskip</CODE> and <CODE>\vfill</CODE> commands produce flexible lengths. They do not add space where no text exists; for example, at the top of a page. Use <CODE>\vglue</CODE> if you want to add an absolute space. <P>TeX fills the <CODE>\vsize</CODE> dimension with as much text as possible before it starts a new page. To force a page break, use the <CODE>\vfill \eject</CODE> sequence. If <CODE>\vfill</CODE> is not used, the text before the <CODE>\break</CODE> will be spaced to fill the page. <P>If you want TeX to be more flexible about its vertical page sizing, place the <CODE>\raggedbottom</CODE> command in your document. TeX will then adjust the bottom margin of each page slightly to make vertical spacing more consistent. <P> <H2><A NAME="ss3.5">3.5 Page numbers, headers, and footers.</A> </H2> <P>teTeX by default places the page number at the bottom center of the page. If you want to change the location and style of the page number, you can specify alternate headers and footers by changing definitions of <CODE>\headline</CODE> and <CODE>\footline</CODE>. The default value for <CODE>\footline</CODE> contains the <CODE>\folio</CODE> command, which prints the page number. The default value for <CODE>\headline</CODE> is <CODE>\hfil</CODE>, so a blank line is printed. <P>The <CODE>\pageno</CODE> command is a synonym for TeX's internal page counter. You can change the page number by changing the value of <CODE>\pageno</CODE>. If <CODE>\pageno</CODE> is negative, the numbers are printed as Roman numerals. <PRE> \pageno=10 \pageno=-1 </PRE> <P>The command <CODE>\nopagenumbers</CODE> is shorthand for: <PRE> \headline={\hfil} \footline={\hfil} </PRE> <P>The default footline also contains the font command <CODE>\tenrm</CODE>, which sets the page number's font to 10-point Roman. If you want to print the page number in 12-point Roman, for example, you would first define a 12-point Roman font, and use that in the definition of <CODE>\footline</CODE>. Font commands are discussed in Section <A HREF="#tex-font-commands">Font commands</A>. <PRE> \font\twelvrm=cmr12 \footline={\hss\twelvrm\folio\hss} </PRE> <P>You can put a <EM>rule</EM>, a horizontal line, at the top of each page by redefining <CODE>\headline</CODE> as: <PRE> \headline={\hrulefill} </PRE> <P>To specify different headers for even and odd pages use the <CODE>\ifodd</CODE>command, which has the form: <PRE> \ifodd[condition][true-action]\else[false-action </PRE> An example <CODE>\headline</CODE> that uses different headers for even and odd pages would be: <PRE> \headline={\ifodd\pageno odd-page-header \else even-page-header} </PRE> The <CODE>\ifodd</CODE> statement uses the first argument if the page number is odd, and the second argument otherwise. <P> <H2><A NAME="ss3.6">3.6 Titles and macros. </A> </H2> <P>TeX provides only the <CODE>\beginsection</CODE> macro for section headings. It leaves a space above its argument, prints the text of the heading in bold type, adds a <CODE>\smallskip</CODE> after the text of the heading, and starts the next paragraph with no indent. <P>The LaTeX chapter and section commands described below add section numbering, and will print the section names and numbers in the page headings, and automatically add the sections to the Table of Contents. <P>In plain TeX, you must write these functions yourself. The <CODE>\def</CODE> command allows you to define new commands. Suppose you want to print a chapter title. First you define the font that you want to use. A large, sans serif font for chapter titles would be defined like this: <PRE> \font\chapterfontsans=cmss12 scaled \magstep 4 </PRE> You can use the <CODE>\chapterfontsans</CODE> command anywhere you want to switch to this font, which is approximately 24 points in height. However, in this example, it will be used primarily in the command <CODE>\chaptertitlesans</CODE>. Here is its definition: <PRE> \def\chaptertitlesans#1{\hbox{}\bigskip\bigskip \noindent{\leftline{\chapterfontsans#1}} \par\bigskip\bigskip\noindent} </PRE> The first line, <CODE>\hbox{}\bigskip</CODE>, anchors a 12-point space at the top of the page by placing an empty <CODE>\hbox{}</CODE> there. The line with the chapter title is not indented, nor is the paragraph which immediately follows it. If you place a blank line between the <CODE>\sschaptertitle</CODE> macro and the next paragraph, the final <CODE>\noindent</CODE> applies to the blank line, not the text of the following paragraph. To format correctly, use the <CODE>\sschaptertitle</CODE> as in this example: <P>The <CODE>#1</CODE> statement in the definition is replaced by the first argument to <CODE>\chaptertitlesans</CODE>; that is, the title of the chapter. Parameters TeX definitions are declared with <CODE>#1</CODE>, <CODE>#2</CODE>, <CODE>#3</CODE>, and so on. An example usage of <CODE>\chaptertitlesans</CODE> would be: <PRE> \chaptertitlesans{Chapter 1} This is the starting text of the first paragraph of the chapter. The paragraph will not be indented. The chapter's title is "Chapter 1." </PRE> <P> <HR> <A HREF="TeTeX-HOWTO-4.html">Next</A> <A HREF="TeTeX-HOWTO-2.html">Previous</A> <A HREF="TeTeX-HOWTO.html#toc3">Contents</A> </BODY> </HTML>