skip to primary navigationskip to content
 

Introduction to TeX

U36

Introduction

TeX is a text processor which is suitable for the preparation of papers, books, theses, etc. It is especially suited to material with a high mathematical content. Note that TeX is a text processor rather than a word processor. In particular, it is not WYSIWYG (What You See Is What You Get) like many of the word processors available on microcomputers. TeX is available on a wide range of computers including Unix systems, IBM PCs and Apple Macintoshes. It is intended to be used with Laser Printers or photo-typesetters although some implementations of TeX support draft quality output on dot-matrix printers and have preview facilities available on the screen. This leaflet provides an introduction to TeX as it is used under Unix. Leaflet U38 describes how to produce mathematical formulae in TeX.

While this leaflet is primarily concerned with the implementation of TeX for Unix, users of other implementations may find some of the sections useful.

References

The full specification of TeX is in The TeXbook which is available from commercial bookshops. A copy is available for consultation in the User Library. The Computing Service Bookshop also supplies a self-study manual called A Gentle Introduction to TeX, by Michael Doob of the University of Manitoba.

Facilities provided by TeX

TeX is a powerful text processor with extensive facilities. Some features mentioned in the list require user written macros, but many of the macros are described in the TeXbook.

  • font sizes from very small to very large
  • page layout
  • range of fonts
  • mathematical equations
  • extensive range of mathematical characters
  • extensive range of accents
  • alternative character sets, e.g. greek
  • indexing
  • footnotes
  • line drawing
  • diagrams and boxes
  • multi-column printing
  • tables

Input to TeX

Input to TeX consists of the text to be typeset or paginated and directives or commands embedded in the text.

Directives may appear anywhere in the text and are introduced by a backslash (\). There are two types of directive:

\control-words
control-words consist of a backslash followed by one or more alphabetic characters. Control words must be terminated by a non-letter, e.g., \hsize
\control-symbols
control-symbols consist of a backslash followed by a single non-alphabetic character. Control-symbols do not need any termination, e.g. \,

Spaces following a control-word are not sent to the TeX output.

The scope of a directive may be limited by enclosing the directive (usually followed by some text) in curly brackets {}, e.g. "{\it italic} text" gives "italic text".

The case of the characters of a control-word is relevant, the control-word \hello is different from \HELLO, \Hello or any other combination of cases.

A directive may be a 'primitive' or a 'control-sequence' (or macro). A 'primitive' is one of TeX's basic commands, a control-sequence is a command which groups together a series of primitives or other control-sequences for the convenience of the user. In general, it is unnecessary for the user to know whether a particular command is a primitive or a control-sequence. Users can build up their own control-sequences (often known as macros) using the \def command, described below.

Special Characters

There are certain characters which have a special meaning:

\
introduces a directive
{ and }
limit the scope of a directive and group directives
$
introduces and terminates maths mode
$$
introduces and terminates displayed maths mode
%
introduces a comment
&
denotes a tab
#
denotes an item in a \halign table or an argument in a macro
~
denotes a non-splitting space

If any of the characters above are required in printed text, special directives are available to do this.

Page Setup and default settings

By default, TeX fills lines splitting at a space character if it can, and hyphenating if it cannot. It fills a line so that there is neither too much nor too little space between the words. Lines are fully justified. The default state may be changed by the user, for example to prohibit hyphenation or to change the way in which a word should be hyphenated. Changing the default settings is described in a later section.

TeX has a default page size which assumes that output is to American sized paper, and provides a 1 inch border at the top and bottom and at either side. A footline is defined which is the page number centred on the page. Page numbering may be disabled by using the directive \nopagenumbers. The shape of the page can be changed with the directives:

\hsize
defines the width of the lines. Printing will start 1 inch from the left hand margin.
\vsize
defines the length of printed material. Printing will start 1 inch from the top margin.
\hoffset
defines the horizontal offset of the text on the page. This is in addition to the default 1 inch margin. The value of \hoffset may be negative.
\voffset
defines the vertical offset of the text on the page. This is in addition to the default 1 inch margin. Note that the value of \voffset may be negative.
\headline
this defines a headline for the page. The headline is empty by default.
\footline
this defines a footline for the page. By default, the footline consists of the page number, centred on the line.

Radical alterations to the layout of a page are made by redefining the page using the \output directive. See the TeXbook, Appendix B for details.

Page size

To get 1 inch margins all round the text on an A4 paper, the directives needed are:
\hsize=6.25in
\vsize=9.65in

The units of measurement may be inches, centimetres, points, etc. A list of the valid units of measurement is given in the TeXbook.

\vsize defines the space allowed for the text on the page. The headline and footline are in addition to the length of text set by \vsize.

If a magnification is applied to the document, the following directives will ensure that the magnification is not applied to the directives defining the page size.
\hsize=6.25truein
\vsize=9.65truein

Other default settings

Some of the default settings are given here for convenience; a complete list is in Appendix B of the TeXbook.

Directives which define an amount of space to be skipped specify the ideal amount of space to be skipped, and 'plus' and 'minus' values specify the permitted limits.

\hsize=6.5in
\vsize=8.9in
\pretolerance=100
\tolerance=200
\parindent=20pt
\parskip=0pt plus 1pt
\hbadness=1000
\vbadness=1000

\smallskip 3 pt plus 1pt minus 1 pt
\medskip 6 pt plus 2pt minus 2 pt
\bigskip 12 pt plus 4pt minus 4pt

\baselineskip=12pt

Example Input and Output

The example below shows some input to TeX and the output after processing by TeX. How to process the input to TeX is shown in a later example. A number of directives are used to introduce styles and sizes of type. The directives and the text to be processed are sometimes enclosed in curly brackets to limit the scope of the directive.

The directives used in the example are:

\rm
gives roman type
\bf
gives bold type
\sl
gives slanted type
\tt
gives typewriter style type
\it
gives italic type
\sevenrm
gives seven point type
\fiverm
gives five point type
\TeX
is a special control-sequence which is used to typeset the TeX logo
\smallskip
causes a vertical space of between 2 and 4 points to be left
\medskip
leaves a vertical space of between 4 and 8 points
\centerline
centres the text on the line (note the American spelling)
\ (space)
leaves a space after a control-word

Input to TeX

In the example following, directives are shown in boldface:

\centerline{\bf Font styles and sizes}
\medskip
\TeX\ provides access to a wide range of fonts
and styles as well as a range of sizes of font. 
Unless it is told otherwise, \TeX\ assumes that
the user wishes to use a Roman font at 10 point as in this leaflet. To
make a particular point there are {\bf bold renditions of
this font} as well as {\sl slanted} and {\it italic}
renditions.
If the user wishes to demonstrate a particular point, perhaps using a 
fixed width font, there is also {\tt typewriter font}.
\smallskip
No special definitions are required for the user to access
{\sevenrm smaller type} or
\fiverm even smaller type}.

Output from TeX

After processing by TeX the following is produced:

[Example TeX output]

>Processing the TeX input

There are three stages required to produce a printed page from the TeX input:

  1. Processing the input using TeX. The output from TeX is in DVI, DeVice Independent code
  2. Processing the DeVice Independent code so that it is suitable for a specific printing device
  3. Printing the device dependent code on a suitable device

In between stages (1) and (2), it may be possible to "preview" the output on a suitable screen. This may be done on an X-terminal or a Unix workstation running X11, as described in the next section.

The following examples show the steps that may be used to create a page on a PostScript printer. Anything shown in bold type is typed by the user.

tex test.tex This is TeX, C Version 3.14159
(test.tex)
*\end
[1]
Output written on test.dvi (1 page, 1244 bytes).
Transcript written on test.log.

The output from TeX is not humanly readable, but is intended for translation into a form suitable for output on a particular device. A copy of the output shown on the terminal is available in the transcript (or log) file, test.log. The \end directive may be included in the source file if preferred. If the \end directive is not included in the source file, TeX prompts the user for further input with a *.

If you are using X11, see the next section for previewing facilities. Otherwise, the next step is to convert the DVI code into PostScript. There are several Unix utilities for converting DVI to PostScript in existence. These have similar names, e.g. dvitps, dvips, dvitops, dvi2ps. You will need to check which is installed on your system, but, at present, the most common command is dvips, so an example using this is given below.

Use of dvips

The basic command dvips test.dvi will create a PostScript output file called test.ps, as follows.

dvips test.dvi
This is dvipsk 5.58f
TeX output 1996.10.22:1539 -> test.ps
<tex.pro>. [1]

To send test.ps to a PostScript printer, use

lpr -P[printer name] test.ps

where the name of your chosen printer has been substituted for [printer name].
Use man dvips and man lpr for more information on these commands.

NB Many printers can process DVI code, and where this is the case it is generally more efficient to send the test.dvi file to the printer, rather than do the conversion to PostScript.

Previewing the output

If you are using an X-terminal or running X11 on a Unix workstation, you can use xdvi to preview the DVI file before converting it to PostScript. Suppose you have a DVI file called doc.dvi. Then xdvi doc.dvi will create a new window on your screen containing the first page of your document.

Options to xdvi can be used to alter the initial display. For example, xdvi +5 doc.dvi will display the fifth page of doc.dvi, and xdvi -s4 doc.dvi will cause the page to be displayed with a shrinkfactor of four, instead of the default three. However, xdvi is an interactive command, and it is straightforward to alter these settings after entering xdvi.

Within xdvi the display may be altered using either keystrokes or the mouse-controlled 'buttons' that appear on the right-hand side of the xdvi window. Some useful keystroke commands are:

n
next page. If a number is given before the n, then it will move forward that number of pages, e.g. 5n means move forward five pages.
p
previous page. If a number is given before the p, then it will move back that number of pages.
s
change the shrinkfactor to the number following the s. If no number is given, the smallest factor that will fit the entire page into the xdvi window will be used.
l,r,u,d
move left,right,up,down two-thirds of a window. This is useful if a low shrinkfactor is being used, and not all the document page will fit into the window.
q
quit xvdi.

For more details of the xdvi options available use man xdvi.

Debugging

The TeXbook has a chapter on running TeX and understanding its error messages; the notes below serve as a guide for the new user. When an error occurs in TeX, a message is shown identifying the error and the user is asked what action should be taken with a ? prompt. If TeX does not understand the reply to this, it will provide more details about the response it expects:

Type <return> to proceed, S to scroll future error messages,
R to run without stopping, Q to run quietly,
I to insert something, E to edit your file,
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
H for Help, X to quit.

return
TeX attempts to recover from the error and proceeds
S
this is equivalent to typing return to all future error messages; some serious messages will cause TeX to stop and wait for further instruction. Error messages are copied to the log file.
R
this is similar to S, but TeX will not stop for any reason.
Q
this is like R, but error messages to the terminal are suppressed.
I
insert the text following. This is used to replace the text which TeX objected to.
number
the number of characters to be ignored in the input file.
H
asks TeX to provide more help
X
quit
E
enter the editor. This terminates the TeX run and enters vi, the default editor, at the appropriate line.

TeX accepts these commands in both upper and lower case. Return, H, I, E and S commands are the most useful commands while debugging.

A few examples follow which show how to use the error messages; more examples are given following the discussion of boxes.

A mistyped command

The input file a.tex consists of a single line with the \hbox directive mistyped:

\hboz to 0.7in{hello there\hfil}

An attempt to run TeX would look like:

tex a.tex
This is TeX, C Version 3.14159
(a.tex
! Undefined control sequence.
l.1 \hboz
          to 0.7in{hello there\hfil}
? i\hbox
)
*\end
[1]
Output written on a.dvi (1 page, 216 bytes).
Transcript written on a.log.

TeX shows the user where the error has occurred by splitting the line at that point. The item that TeX cannot recognise is shown in the first part of the line. This may be replaced (as here) using the I command. Note that while the run of TeX has been successful, the original file, a.tex, has not been modified.

A missing unit

The input file consists of the following:

\parindent 0
This is the first line.
\end

The TeX run would produce the following output:

tex b.tex
This is TeX, C Version 3.14159
(b.tex
! Illegal unit of measure (pt inserted).
<to be read again>
                  T
<to be read again>
                  h
l.2 Th
      is is the first line.
?

TeX has realised that the user has omitted the unit from the \parindent directive and inserts a unit. It also recognises that the two letters it tried to read as a unit are part of something else and says that they are to be reread. The user can either accept TeX's decision by pressing return (or R or S), or insert another \parindent directive using the I command.

An extra bracket

Including an extra closing bracket, or omitting a bracket, is a common mistake. TeX will usually attempt to recover from the error. The following example shows what might happen:

\centerline{Chapter 1}
\smallskip
Once upon a time there was a handsome prince called Timmy.  He lived in a small
castle high on a hill.

One day he was out walking in a nearby wood when he met a small
green and red frog called Freddy.
}

produces

tex c.tex
This is TeX, C Version 3.14159
(c.tex
! Too many }'s.
l.7 }
? return
)
*\end
[1]
Output written on c.dvi (1 page, 476 bytes).
Transcript written on c.log.

When TeX reaches the end of the paragraph, it realises that there is an extra bracket. The most practical response the user can give at this point is to type a return, in which case TeX will ignore the bracket. This will enable processing to continue and other errors to be detected.

There are some directives which may be used when an error occurs and which show the current state of a box or list or show how a control sequence is expanded:

\show
shows the expansion of a control sequence, e.g. \show\TeX shows the commands obeyed when \TeX is obeyed.
\showthe
shows the value of a directive, e.g. the value of \parindent.
\showbox
writes an account of how the box was built up to the log file.
\showlists
displays the list that TeX is processing. \showlists will stay in effect until the end of the current mode. See the TeXBook for details.
\showhyphenation
shows how a word may be hyphenated.

Overfull and Underfull Boxes

TeX thinks in boxes. Each character, word, line, paragraph and page may be thought of as a box. The boxes are held together by shrinkable and stretchable 'glue'. Each piece of 'glue' has an ideal setting, and a minimum and maximum setting which can be used without TeX believing that the line is very 'bad'. The TeXbook has a chapter on boxes (Chapter 11) and a chapter on 'glue' (Chapter 12), and the user is referred to this.

There are various types of box, the most important of which are hboxes and vboxes.

Hbox means a horizontal box; vbox means a vertical box. A line is a simple form of horizontal box. If the user tries to put more onto a line than TeX thinks is good, it complains that it has an overfull box; in terms of 'glue', this means that each bit of 'glue' is being compressed into too small a space. Similarly, if there is too little on a line, then TeX complains of an underfull box; this means that the 'glue' is being stretched too much. Usually overfull and underfull boxes will only be encountered when \hbox or \obeylines or similar directives are used. However, if hyphenation is disabled or the line length is very short, overfull or underfull boxes may occur in ordinary text.

The user has some control over how TeX decides what is a good or bad box by using the \tolerance and \pretolerance commands. When TeX breaks a line it first tries to break the line at a convenient place so that the 'badness' of the line does not exceed the limit set by \pretolerance. If this cannot be done, a second pass is attempted, using hyphenation. In this case the 'badness' of the line should not exceed the value of \tolerance. It it does, TeX will complain of either an underfull or overfull box. The limit of 'badness' can be altered with the \hbadness (horizontal) or vbadness (vertical) directives.

The \pretolerance directive defines how bad the line may be before hyphenation is attempted. \pretolerance is set to 100 by default. If \pretolerance is very small, no attempt is made to typeset the line without hyphenation. If \pretolerance is set to a large value, this pass will always succeed and hyphenation will not be attempted.

The following examples show how overfull and underfull boxes occur.

Create a file containing the following lines from the opening paragraph of this leaflet:

\TeX\ is a text processor which is suitable for the preparation of
papers, books, theses, etc. It is especially suited to material with a 
high mathematical content.  Note that \TeX\ is a {\bf text} processor
rather than a word processor.  In particular, it is {\bf not} WYSIWYG (What 
You See Is What You Get) like many of the word processors available on 
microcomputers.

Try the following exercises using the file.

  • run TeX on the paragraph. No errors are produced. If you are using X11, you can preview the output using xdvi.
  • add the directive \hsize=2.3in to the start of the file. Preview the output as above. Overfull boxes are produced and, when viewed, a couple of the lines end in hyphenated words.
  • add the directive \tolerance=1500 to the start of the file. Run TeX on the file. This time no errors are produced because TeX has been told to accept lines which are not as good as before (the tolerance level has been increased from 100 to 1500).
  • add the directive \pretolerance=15000 to the start of the file. Run TeX on the file. This time underfull boxes are produced, but none of the words are hyphenated. The warning can be suppressed by setting \hbadness to a higher level.

Paragraphs

By default, the first line of a new paragraph is indented by 20 points. Paragraphs are introduced in various ways, including:

  • \par
  • \indent
  • a blank line
  • \vskip (which includes \smallskip, etc.)

The command used to set the size of the paragraph indent is \parindent, e.g.

\parindent=0.3in

Whole sections of text can be indented on the left hand side, right hand side or both sides using the commands:

  • \leftskip
  • \rightskip
  • \narrower

Paragraphs can be set justified on the left hand side of the page only using the \raggedright command.

Another useful paragraph handling command is \hangindent. This causes subsequent lines to be indented by the value of \hangindent. The lines to be indented are specified by the \hangafter command; if \hangafter = n and the value of n is positive, the hanging indent will be applied after n lines. If the value of n is negative then the first n lines will be indented, e.g.

\hangindent=0.5\inhangafter=-2
The first two lines of this piece of text
are indented by half an inch.  The rest of the paragraph is the normal width
of the page.  You will see that this layout is used frequently in the \TeX
book around the `dangerous bend' signs.\par

produces

[Example TeX output]

The next paragraph is introduced by the directives \parindent=1in\narrower\noindent, which indents the paragraph on both sides of the page.

\parindent=1in\narrower\noindent
This paragraph is indented on both sides of the page
and might be used for quotations and other pieces of text which the 
\TeX\ user wants to stand out on a page.\smallskip

produces

[Example TeX output]

Note that the \noindent command prevents the paragraph indent being applied twice.

The next example is introduced by a \parindent=0.5in directive and each numbered point introduced by a command of the form \item{(a)}.

\parindent=0.5in
\item{(a)} A special case of hanging indents is the
{\bf $\backslash$ item} command.
\item{(b)}This is used in the case of numbered items.

produces


[Example TeX output]

\everypar is used to define a directive or set of directives to be used at the start of every paragraph. E.g. the following directives will ensure that the first word of every paragraph is emboldened:

\def\bold #1 #2\par{{\bf #1} #2}
\everypar{\bold}

Page Breaks

TeX splits pages in much the same way as it splits lines, so that the 'badness' is within certain limits. In general, there is not as much glue between lines on a page as there is between words on a line, and therefore not as much scope for padding out pages. There is glue whenever a \smallskip, \medskip or \bigskip is used and around displayed equations. TeX will break whenever it has filled up the page, but the user has some control. There are several ways of specifying how a page should be split.

\eject
forces an unconditional page break
\vfil\eject
causes an unconditional page break and fills the remainder of the page with white space. If \vfil is omitted, the contents of the page are spread out, vertically, to fill the page.
\filbreak
a page break will only occur if not all the text between this \filbreak and the next would fit onto the page.
\nobreak
prevents page or line breaks at that point.
\smallbreak \medbreak \bigbreak
indicate good places to break. \bigbreak is a more desirable place to break than \smallbreak. If a page break is not taken at these points, a \smallskip, \medskip or \bigskip will be inserted instead.
\vbadness
defines the 'badness' limit of a page.

Fonts and Magnification

The default font is CMR10 (Roman 10 point). Other sizes and styles are readily available. The various styles available are:

[Tex font styles]

Some of the fonts available are:

[Tex font families]

Greek is also available in Maths mode; see leaflet U38.

Only CMR10 in its various styles and in 10 point, 7 point and 5 point is available immediately. Note that all other fonts and sizes must be set up before they can be used. For all the fonts a line of the form:

\font\dunh=cmdun10

is required.

The largest font available without using magnification is ten point; however, any of the fonts may be magnified or a whole document may be magnified.

The \magnification command is used to apply a magnification to the whole document, (no magnification at all corresponds to the TeX command \magnification=1000). The command \magnification=1400 increases the height and width of a letter by a factor of 1.4, thus doubling the area of the letter, while the command \magnification=2000 multiplies both the height and the width of the letter by 2. For convenience, some magnification steps are provided: these are \magnification=\magstep0, \magstep1, ...magstep5 which correspond to magnifications of 1, 1.2, 1.44 (1.2 x 1.2), 1.728 (1.2 x 1.2 x 1.2) etc.

\magnification=\magstep1 increases the height and width of each letter by a factor of 1.2
and
\magnification=\magstep2 increases the height and width of each letter by a factor of 1.2 again, i.e. \magstep2 increases the height and width of the characters by 1.44
The \magnification command should only be used at the start of a document.

An individual font may be defined using the commands
\font\newfont = cmr10 at 6pt defines a 6pt font
\font\large = cmr10 scaled magstep1 defines a 12 point font (10 point scaled 1.2).
magnification=1200 enlarges everything by 1.2
magnification=2000 enlarges everything by a factor of 2

Tabs and Tables

TeX has facilities for setting up tables with fixed or variable width columns. Variable width columns may be defined either by providing a sample line which will allow TeX to see the maximum width required for each column, or by allowing TeX to read the entire table and set the column widths accordingly. Some of the directives used in setting tables are:

\settabs
introduces a table. Sets the tabs at positions specified by the user, either by the user supplying a sample line from which the tabs are set, or by asking for a certain number of columns of equal width. \settabs should be used when consistency is required for several tables.
\halign
introduces a table and specifies the number of columns required. TeX reads the entire table and then sets the width according to the widest entry encountered for each column. \halign is not suitable when several similar tables are to appear close together as all the tables will have different width columns unless \hbox is used.
\+
used to introduce a line of a table when using \settabs
#
used to specify an argument in an \halign directive.
&
used to specify a tab
\cr
used to specify the end of a line
\quad
used to specify a fixed amount of space to be left between columns
\noalign
used in a table to stop the line being set as part of the table
\omit
used to omit a fixed part of the template of the table
\multispan
used to skip over tab positions in the table.
\hfil
used to justify the text in the column.

Settabs

The simplest table consists of a number of equally spaced columns; the whole line spreads across the page:

\settabs 5 \columns
\+ January & February & March & April & May \cr

produces

[Example TeX output]

\settabs can also be used with a sample line. This would usually consist of the widest entry for each column. The sample line is not printed. The directive \qquad leaves some space after the text. The command \hfil means that the text will be justified in the column depending on the use of \hfil. Omitting \hfil will result in the text being spread across the column.

\settabs\+ J.W.~Witherspoon-Smith\hfil\qquad & Swaffham
Bulbeck, Cambs \hfil\qquad & \cr
\J.~Smith & Toft & 82156 \cr
\F.~Green & Pampisford & 675234 \cr

produces

[Example TeX output]

Halign

The third way of producing a table is to use the \halign command. This is the most powerful of the three.

\halign{ #\hfil&#\hfil&#\hfil\cr
Abingdon & Oxfordshire & 16,100\cr
Beccles & Suffolk & 23,000\cr
Cambridge & Cambridgeshire & 100,000\cr

produces

[Example TeX output]

Modes

There are six modes that TeX may work in; these are described in Chapter 13 of the TeXbook. The modes most used by users are:

horizontal
the usual mode when text is being processed and built into paragraphs
vertical
the mode used when a page is being built up
maths
used when processing mathematical formulae which are being built into a horizontal list
displayed maths
used when processing displayed mathematical formulae

For details of maths modes, see leaflet U38.

Footnotes

TeX has built in facilities for producing footnotes at the end of a page. When using the TeX provided macro, the user must specify both the number, or means of identifying the footnote, and the text. There is an exercise in the TeXbook which shows how the user might write his own macro to produce automatically numbered footnotes. The format of the \footnote command is \footnotesymbol{text}, e.g.

\footnote\dag{produces the text at the end of this page}[Example footnote]

An example of automatic numbering is given in leaflet U38.

[Example footnote]

Accents

Accents are easily produced in TeX. The following example shows how some words or phrases may be achieved, e.g.

[Example TeX output]

The following accents are available in plain TeX outside Maths mode; various others can be produced within Maths mode.

[Example TeX output]

Macros

TeX has facilities for writing macros so that these may be used exactly as if they were TeX commands. The command used to define a macro is \def, e.g.

\def\display{\obeylines\parindent=0.3in\tt}

is a definition which is used in the printed version of this leaflet. The \def command is used at the start of the leaflet. Each display is introduced by \display.

Macros can also take arguments. There is an example in section nine of this leaflet. Arguments are defined by number and are introduced by a # sign. The number of the argument is followed by the character or string which delimits the argument, e.g.

\def\bold #1 #2\par{{#1}#2}

In this case the first argument is terminated by a space, i.e. the first argument is the first word. The second argument is from the second word until the end of the paragraph. For more information about macros, see Chapter 20 of the TeXbook.

Lines and boxes

TeX has special facilities for drawing lines; \hrule draws a line as wide as the horizontal box it is in. In practice, if \hrule is not followed by any measurement, it fills the whole line. Otherwise a line is drawn to the specified length or depth, subject to any magnification factors.

Similarly, \vrule fills the vertical box it is in. Measurements may be in any of the usual units, points, inches, centimetres, etc. If a magnification affects the whole document then the rule measurements will be affected as well. To prevent this happening, the 'true' measurements may be used (see section three).

Both horizontal and vertical lines have height (above the baseline), depth (below the baseline) and width. The height and depth of the horizontal line gives the thickness of the line, while height and depth give the length of a vertical line, but do not change the thickness, e.g.

\hrule height 2pt depth 2pt width 16pt 

produces a thick horizontal line, while

\vrule height 8pt depth 8pt width 2pt

gives a thin, vertical line.

Baselines

Three commands are used to control the distance between two adjacent lines: \baselineskip, \lineskip and \lineskiplimit.

Unless the user is drawing diagrams, or using different sizes of font on a single line, the only command that is required for altering the spacing between lines is \baselineskip.

The baseline is the line on which all of the characters sit; it is the lowest point of the letter for those without tails. The distance between lines is measured from this point and is controlled by the command \baselineskip, the default value of which is 12pt.

Lines may be 'doublespaced' by the command \baselineskip=18pt.

If the value of \baselineskip causes the boxes made by two lines to be closer than the value \lineskiplimit apart then some extra 'glue', the value of \lineskip is applied.

The command \nointerlineskip prevents any glue being inserted between lines, and is most useful when drawing diagrams.

Last updated: December 1996 Last reviewed: October 2011