(M)  s i s t e m a   o p e r a c i o n a l   m a g n u x   l i n u x ~/ · documentação · suporte · sobre

  Next Previous Contents

3. TeX commands.

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

tex your_text_file
The result will be a file of the same base name and the extension .dvi. 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, \, and run TeX on the file again. You should be able to process the resulting file with the .dvi file translator of your choice (see above) to get printed output.

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.

"These are ASCII-type quotes."
``These are `TeX-style' quotes.''

3.1 Command overview.

Commands in TeX start with a backslash (``\''). For example, the command to change the spacing between lines is

\baselineskip=24pt

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 \baselineskip, and is assigned a value of 24 points.

Measurements or dimensions in TeX are often given in the following units:

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.

Some commands do not take assignments. For example:

\smallskip        % Approximately 3 pt.
\medskip          % Two \smallskips.
\bigskip          % Two \medskips.

A \smallskip 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.

\hsize=6.5in
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 Tolerances.

There are many other commands that specify horizontal and vertical dimensions and tolerances, and the most commonly use commands are described below.

3.2 Font commands.

In TeX, the default font is 10 pt. Computer Modern Roman. To specify a typeface, like italic, bold, or monospaced, use the following commands.

\rm          % Roman (the default).
\it          % Italics.
\bf          % Bold.
\tt          % Monospaced (teletype).
\sl          % Oblique (slanted).
The commands change the typeface where they appear in the text, as in this example.
This text is Roman, \it and this text is italic.  \bf This text is
bold, and \rm this text is in Roman again.

To specify a font for your document, use the\font command.

\font\romantwelve=cmr12
This creates the font command \romantwelve, which, when used in the text, changes the font to Computer Modern Roman, 12 point.
\romantwelve
This is the Computer Modern Roman font at 12 points.
For information about the fonts in the teTeX distribution look at the file:
/usr/lib/teTeX/texmf/doc/fonts/fontname/fontname.dvi

If you want to print a sample of a font, TeX the file

/usr/lib/teTeX/texmf/tex/plain/base/fontchart.tex
and fill in the name of the font you want to print at the prompt.

You can also change the size of a font to get different effects. Font magnification is exponential, and specified with the scaled \magstep command, which is placed after the font specification.

\font\sfmedium=cmss12 scaled \magstep 1
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.

3.3 Paragraph styles and dimensions.

As mentioned above, TeX typesets text in 10-point Computer Modern Roman by default. The length of a line is the value of \hsize, which defaults to 6.5 in. If you want to change the value of \hsize to 5.5 in. for example, use this command.

\hsize=5.5in

In TeX a dimension 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 skip, which is a dimension that is placed in one of TeX's internal registers. Skips are defined with the \newskip command. The \smallskip dimension, as defined by TeX is:

\newskip\smallskipamount \smallskipamount=3pt plus 1pt minus 1pt
The \smallskip command is shorthand for:
\vskip\smallskipamount

There are a number of dimensions that control the page layout. They are summarized in Section Page layout.

TeX formats paragraphs with justified left and right margins. If you want the text to be left justified only, use this command:

\raggedright

To typeset a line that is justified to the right margin, use the \rightline command:

\rightline{This is the line to be typeset.}

The \line command typesets the text of its argument to fill the entire line.

\line{This text will be spaced to fit the entire line.}

The \hfil command adds space to fill out the line where it occurs. So, for example, the \rightline command is equivalent to:

\line{\hfilThis line will be right justified.}

To typeset a line that is centered, use the \centerline command.

\centerline{This is the line to be centered.}

To change the left margin, set the value of \hoffset, as in this example:

\hoffset=1.5in

The \parindent command specifies the amount that the first line of every paragraph is indented.

\parindent=.5in

Two other dimensions, \leftskip and \rightskip, will indent the right and left margins, respectively, of the paragraphs that come after them.

\leftskip=.5in
\rightskip=.5in
The control word \narrower is equivalent to:
\leftskip=\parindent
\rightskip=\parindent
That is, \narrower narrows the paragraph margins by the value of \parindent

As mentioned in the previous section, the \baselineskip specifies the distance between lines. The default is 12 pt. To approximate double-spaced text, use the following command.

\baselineskip=\baselineskip*1.6

The \parskip command specifies the distance in addition to \baselineskip 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:

\parskip=\baselineskip

Tolerances. (What are those black rectangles after every line?)

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 \hbox is underfull. Text that must be squeezed to fit in the line produces an overfull \hbox warning.

For each overfull \hbox, TeX places a slug, a black rectangle, after the line. The slug indicates that the line could not be formatted to within the specifications set by the \hbadness parameter.

The fit of the text within its specified dimensions is measured by its badness, 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 \hbadness is 1000. If you set \hbadness to 10000, TeX does not report underfull lines.

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 \hfuzz parameter, which defaults to 0.1 pt. If the text does not fit within the line, the \tolerance parameter determines how TeX will handle the overfull \hbox. The default value of \tolerance is 200. Setting \tolerance to 1000 suppresses overfull \hbox warnings and the printing of slugs.

3.4 Page layout.

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.

Like the \hsize and \hoffset dimensions described in the previous section, TeX also provides the \vsize and \voffset commands. The default for \vsize is 8.9 in., and \voffset defaults to 0.

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:

\voffset=-0.5in

If you want to add vertical space in a document, the commands \smallskip, \medskip, and \bigskip 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.

The \vfill 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 \vskip as in:

\vskip 10pt

The commands \hss and \vss are similar to \hfil and \vfill, but they provide dimensions that are infinitely shrinkable as well as infinitely stretchable.

The \vskip and \vfill commands produce flexible lengths. They do not add space where no text exists; for example, at the top of a page. Use \vglue if you want to add an absolute space.

TeX fills the \vsize dimension with as much text as possible before it starts a new page. To force a page break, use the \vfill \eject sequence. If \vfill is not used, the text before the \break will be spaced to fill the page.

If you want TeX to be more flexible about its vertical page sizing, place the \raggedbottom command in your document. TeX will then adjust the bottom margin of each page slightly to make vertical spacing more consistent.

3.5 Page numbers, headers, and footers.

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 \headline and \footline. The default value for \footline contains the \folio command, which prints the page number. The default value for \headline is \hfil, so a blank line is printed.

The \pageno command is a synonym for TeX's internal page counter. You can change the page number by changing the value of \pageno. If \pageno is negative, the numbers are printed as Roman numerals.

\pageno=10
\pageno=-1

The command \nopagenumbers is shorthand for:

\headline={\hfil}
\footline={\hfil}

The default footline also contains the font command \tenrm, 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 \footline. Font commands are discussed in Section Font commands.

\font\twelvrm=cmr12
\footline={\hss\twelvrm\folio\hss}

You can put a rule, a horizontal line, at the top of each page by redefining \headline as:

\headline={\hrulefill}

To specify different headers for even and odd pages use the \ifoddcommand, which has the form:

\ifodd[condition][true-action]\else[false-action
An example \headline that uses different headers for even and odd pages would be:
\headline={\ifodd\pageno odd-page-header \else even-page-header}
The \ifodd statement uses the first argument if the page number is odd, and the second argument otherwise.

3.6 Titles and macros.

TeX provides only the \beginsection macro for section headings. It leaves a space above its argument, prints the text of the heading in bold type, adds a \smallskip after the text of the heading, and starts the next paragraph with no indent.

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.

In plain TeX, you must write these functions yourself. The \def 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:

\font\chapterfontsans=cmss12 scaled \magstep 4
You can use the \chapterfontsans 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 \chaptertitlesans. Here is its definition:
\def\chaptertitlesans#1{\hbox{}\bigskip\bigskip
  \noindent{\leftline{\chapterfontsans#1}}
  \par\bigskip\bigskip\noindent}
The first line, \hbox{}\bigskip, anchors a 12-point space at the top of the page by placing an empty \hbox{} 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 \sschaptertitle macro and the next paragraph, the final \noindent applies to the blank line, not the text of the following paragraph. To format correctly, use the \sschaptertitle as in this example:

The #1 statement in the definition is replaced by the first argument to \chaptertitlesans; that is, the title of the chapter. Parameters TeX definitions are declared with #1, #2, #3, and so on. An example usage of \chaptertitlesans would be:

\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."


Next Previous Contents