. 1
( 7)



>>

L TEX Tutorials
A
A PRIMER
Indian TEX Users Group
Trivandrum, India
2003 September
A
L TEX TUTORIALS ” A PRIMER
Indian TEX Users Group

EDITOR: E. Krishnan
COVER: G. S. Krishna




Copyright c 2002, 2003 Indian TEX Users Group
Floor III, SJP Buildings, Cotton Hills
Trivandrum 695014, India
http://www.tug.org.in


Permission is granted to copy, distribute and/or modify this document under the terms of the GNU
Free Documentation License, version 1.2, with no invariant sections, no front-cover texts, and no
back-cover texts. A copy of the license is included in the end.

This document is distributed in the hope that it will be useful, but without any warranty; without
even the implied warranty of merchantability or ¬tness for a particular purpose.

Published by the Indian TEX Users Group

Online versions of this tutorials are available at:
http://www.tug.org.in/tutorials.html
PREFACE


The ideal situation occurs when
the things that we regard as beau-
tiful are also regarded by other
people as useful.
” Donald Knuth


For us who wrote the following pages, TEX is something beautiful and also useful. We
enjoy TEX, sharing the delights of newly discovered secrets amongst ourselves and won-
dering ever a new at the in¬nite variety of the program and the ingenuity of its creator.
We also lend a helping hand to the new initiates to this art. Then we thought of extend-
ing this help to a wider group and The Net being the new medium, we started an online
tutorial. This was well received and now the Free Software Foundation has decided to
publish these lessons as a book. It is a ¬tting gesture that the organization which upholds
the rights of the user to study and modify a software publish a book on one of the earliest
programs which allows this right.

Dear reader, read the book, enjoy it and if possible, try to add to it.

The TUGIndia Tutorial Team




3
4
CONTENTS


The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
I.
What is L TEX? “ 7 • I.2 Simple typesetting “ 8 • I.3 Fonts “ 13 • I.4 Type size “ 15
A
I.1


The Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
II.
II.1 Document class “ 17 • II.2 Page style “ 18 • II.3 Page numbering “ 19 • II.4 Formatting
lengths “ 20 • II.5 Parts of a document “ 20 • II.6 Dividing the document “ 21 • II.7 What next?
“ 23


Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
III.
Introduction “ 27 • III.2 natbib “ 28
III.1


Bibliographic Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
IV.
IV.1 The BIBT X program “ 33 • IV.2 BIBT X style ¬les “ 33 • IV.3 Creating a bibliographic
E E
database “ 34


Table of contents, Index and Glossary . . . . . . . . . . . . . . . . . . . . . . 39
V.
Table of contents “ 39 • V.2 Index “ 41 • V.3 Glossary “ 44
V.1


Displayed Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
VI.
Borrowed words “ 47 • VI.2 Poetry in typesetting “ 48 • VI.3 Making lists “ 48 • VI.4 When
VI.1
order matters “ 51 • VI.5 Descriptions and de¬nitions “ 54


Rows and Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
VII.
Keeping tabs “ 57 • VII.2 Tables “ 62
VII.1


Typesetting Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
VIII.
The basics “ 77 • VIII.2 Custom commands “ 81 • VIII.3 More on mathematics “ 82 •
VIII.1
Mathematics miscellany “ 89 • VIII.5 New operators “ 101 • VIII.6 The many faces of
VIII.4
mathematics “ 102 • VIII.7 And that is not all! “ 103 • VIII.8 Symbols “ 103


Typesetting Theorems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
IX.
Theorems in L TEX “ 109 • IX.2 Designer theorems”The amsthm package “ 111 • IX.3
A
IX.1
Housekeeping “ 118


Several Kinds of Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
X.
X.1 LR boxes “ 119 • X.2 Paragraph boxes “ 121 • X.3 Paragraph boxes with speci¬c height “
122 • X.4 Nested boxes “ 123 • X.5 Rule boxes “ 123


Floats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
XI.
The figure environment “ 125 • XI.2 The table environment “ 130
XI.1



5
6 CONTENTS


Cross References in LTEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
A
XII.
Why cross references? “ 135 • XII.2 Let L TEX do it “ 135 • XII.3 Pointing to a page”the
A
XII.1
package varioref “ 138 • XII.4 Pointing outside”the package xr “ 140 • XII.5 Lost the keys? Use
lablst.tex “ 140


Footnotes, Marginpars, and Endnotes . . . . . . . . . . . . . . . . . . . . . . 143
XIII.
Footnotes “ 143 • XIII.2 Marginal notes “ 147 • XIII.3 Endnotes “ 148
XIII.1
TUTORIAL I


THE BASICS


A
WHAT IS L TEX?
I.1.

The short and simple answer is that LTEX is a typesetting program and is an extension
A

of the original program TEX written by Donald Knuth. But then what is a typesetting
program?
To answer this, let us look at the various stages in the preparation of a document
using computers.

The text is entered into the computer.
1.
The input text is formatted into lines, paragraphs and pages.
2.
The output text is displayed on the computer screen.
3.
The ¬nal output is printed.
4.

In most word processors all these operations are integrated into a single application
package. But a typesetting program like TEX is concerned only with the second stage
above. So to typeset a document using TEX, we type the text of the document and the
necessary formatting commands in a text editor (such as Emacs in GNU/Linux) and then
compile it. After that the document can be viewed using a previewer or printed using a
printer driver.
TEX is also a programming language, so that by learning this language, people can
write code for additional features. In fact LTEX itself is such a (large) collection of extra
A

features. And the collective effort is continuing, with more and more people writing extra
packages.

A small example
I.1.1.

Let us see LTEX in action by typesetting a short (really short) document. Start your
A

favorite text editor and type in the lines below exactly as shown
\documentclass{article}
\begin{document}
This is my \emph{first} document prepared in \LaTeX.
\end{document}

Be especially careful with the \ character (called the backslash) and note that this is
different from the more familiar / (the slash) in and/or and save the ¬le onto the hard
disk as myfile.tex. (Instead of myfile you can use any name you wish, but be sure to
have .tex at the end as the extension.) The process of compiling this and viewing the
output depends on your operating system. We describe below the process of doing this
in GNU/Linux.

7
8 THE BASICS
I.


At the shell prompt type

latex myfile

You will see a number of lines of text scroll by in the screen and then you get the prompt
back. To view the output in screen, you must have the X Window running. So, start X if
you have not done so, and in a terminal window, type

xdvi myfile

A window comes up showing the output below

This is my ¬rst document prepared in LTEX.
A




Now let us take a closer look at the source ¬le (that is, the ¬le you have typed).
The ¬rst line \documentclass{article} tells LTEX that what we want to produce is an
A

article. If you want to write a book, this must be changed to \documentclass{book}.
The whole document we want to typeset should be included between \begin{document}
and \end{document}. In our example, this is just one line. Now compare this line in the
source and the output. The ¬rst three words are produced as typed. Then \emph{first},
becomes ¬rst in the output (as you have probably noticed, it is a common practice to
emphasize words in print using italic letters). Thus \emph is a command to LTEX to A

typeset the text within the braces in italic1 . Again, the next three words come out without
any change in the output. Finally, the input \LaTeX comes out in the output as LTEX.
A

Thus our source is a mixture of text to be typeset and a couple of LTEX commands
A

\emph and \LaTeX. The ¬rst command changes the input text in a certain way and the
second one generates new text. Now call up the ¬le again and add one more sentence
given below.
This is my \emph{first} document prepared in \LaTeX. I typed it
on \today.

What do you get in the output? What new text does the command \today generate?

Why LTEX?
A
I.1.2.

So, why all this trouble? Why not simply use a word processor? The answer lies in the
motivation behind TEX. Donald Knuth says that his aim in creating TEX is to beautifully
typeset technical documents especially those containing a lot of Mathematics. It is very
dif¬cult (sometimes even impossible) to produce complex mathematical formulas using a
word processor. Again, even for ordinary text, if you want your document to look really
beautiful then LTEX is the natural choice.
A



SIMPLE
I.2. TYPESETTING

We have seen that to typeset something in LTEX, we type in the text to be typeset together
A

with some LTEX commands. Words must be separated by spaces (does not matter how
A

many) and lines maybe broken arbitrarily.
The end of a paragraph is speci¬ed by a blank line in the input. In other words,
whenever you want to start a new paragraph, just leave a blank line and proceed. For
example, the ¬rst two paragraphs above were produced by the input
1 This is not really true. For the real story of the command, see the section on fonts.
9
SIMPLE
I.2. TYPESETTING


We have seen that to typeset something in \LaTeX, we type in the
text to be typeset together with some \LaTeX\ commands.
Words must be separated by spaces (does not matter how many)
and lines maybe broken arbitrarily.

The end of a paragraph is specified by a \emph{blank line}
in the input. In other words, whenever you want to start a new
paragraph, just leave a blank line and proceed.

Note that the ¬rst line of each paragraph starts with an indentation from the left
margin of the text. If you do not want this indentation, just type \noindent at the start
of each paragraph for example, in the above input, \noindent We have seen ... and
\noindent The end of ... (come on, try it!) There is an easier way to suppress para-
graph indentation for all paragraphs of the document in one go, but such tricks can wait.

Spaces
I.2.1.

You might have noticed that even though the length of the lines of text we type in a
paragraph are different, in the output, all lines are of equal length, aligned perfectly on
the right and left. TEX does this by adjusting the space between the words.
In traditional typesetting, a little extra space is added to periods which end sentences
and TEX also follows this custom. But how does TEX know whether a period ends a
sentence or not? It assumes that every period not following an upper case letter ends a
sentence. But this does not always work, for there are instances where a sentence does
end in an upper case letter. For example, consider the following

Carrots are good for your eyes, since they contain Vitamin A. Have you ever seen a rabbit
wearing glasses?

The right input to produce this is
Carrots are good for your eyes, since they contain Vitamin A\@. Have
you ever seen a rabbit wearing glasses?

Note the use of the command \@ before the period to produce the extra space after the
period. (Remove this from the input and see the difference in the output.)
On the other hand, there are instances where a period following a lowercase letter
does not end a sentence. For example

The numbers 1, 2, 3, etc. are called natural numbers. According to Kronecker, they were made
by God; all else being the work of Man.

To produce this (without extra space after etc.) the input should be
The numbers 1, 2, 3, etc.\ are called natural numbers. According to
Kronecker, they were made by God;all else being the works of Man.

Here, we use the command \ (that is, a backslash and a space”here and elsewhere, we
sometimes use to denote a space in the input, especially when we draw attention to the
space).
There are other situations where the command \ (which always produce a space in
the output) is useful. For example, type the following line and compile it.
I think \LaTeX is fun.
10 THE BASICS
I.




You get

I think LTEXis fun.
A



What happened to the space you typed between \LaTeX and is? You see, TEX gobbles up
all spaces after a command. To get the required sequence in the output, change the input
as
I think \LaTeX\ is fun.

Again, the command \ comes to the rescue.

Quotes
I.2.2.

Have you noticed that in typesetting, opening quotes are different from closing quotes?
Look at the TEX output below

Note the difference in right and left quotes in ˜single quotes™ and “double quotes”.

This is produced by the input
Note the difference in right and left quotes in ˜single quotes™
and ˜double quotes™™.

Modern computer keyboards have a key to type the symbol ` which produces a left quote
in TEX. (In our simulated inputs, we show this symbol as ˜.) Also, the key ™ (the usual
˜typewriter™ quote key, which also doubles as the apostrophe key) produces a left quote
in TEX. Double quotes are produced by typing the corresponding single quote twice. The
˜usual™ double quote key " can also be used to produce a closing double quote in TEX.
If your keyboard does not have a left quote key, you can use \lq command to produce
it. The corresponding command \rq produces a right quote. Thus the output above can
also be produced by
Note the difference in right and left quotes in \lq single
quotes\rq\ and \lq\lq double quotes\rq\rq.

(Why the command \ after the ¬rst \rq?)

Dashes
I.2.3.

In text, dashes are used for various purposes and they are distinguished in typesetting by
their lengths; thus short dashes are used for hyphens, slightly longer dashes are used to
indicate number ranges and still longer dashes used for parenthetical comments. Look at
the following TEX output

X-rays are discussed in pages 221“225 of Volume 3”the volume on electromagnetic waves.

This is produced from the input
X-rays are discussed in pages 221--225 of Volume 3---the volume on
electromagnetic waves.

Note that a single dash character in the input - produces a hyphen in the output, two
dashes -- produces a longer dash (“) in the output and three dashes --- produce the
longest dash (”) in the output.
11
SIMPLE
I.2. TYPESETTING


Accents
I.2.4.

Sometimes, especially when typing foreign words in English, we need to put different
types of accents over the letters. The table below shows the accents available in LTEX.
A

Each column shows some of the accents and the inputs to generate them.

` ´ ˆ ˜
o o o o
\˜o \™o \ˆo \˜o
¯ ™ ¨
o o o c
¸
\=o \.o \"o \c c
˜ ˇ ˝
o o o o
\u o \v o \H o \d o
.
o oo
\b o \t oo
¯
The letters i and j need special treatment with regard to accents, since they should not
have their customary dots when accented. The commands \i and \j produce dot-less i
and j as ± and j. Thus to get

´ ´
El esta aqu´
±

you must type
\™{E}l est\™{a} aqu\™{\i}

Some symbols from non-English languages are also available in LTEX, as shown in
A

the table below:

“ ’ ¦ Æ
\oe \OE \ae \AE
\aa \AA
ø ˜ ‚ Ł
\o \O \l \L
ß \ss
¡ ¿
!˜ ?˜


Special symbols
I.2.5.

We have see that the input \LaTeX produces LTEX in the output and \ produces a space.
A

Thus TEX uses the symbol \ for a special purpose”to indicate the program that what
follows is not text to be typeset but an instruction to be carried out. So what if you
want to get \ in your output (improbable as it may be)? The command \textbackslash
produces \ in the output.
Thus \ is a symbol which has a special meaning for TEX and cannot be produced by
direct input. As another example of such a special symbol, see what is obtained from the
input below
Maybe I have now learnt about 1% of \LaTeX.

You only get

Maybe I have now learnt about 1

What happened to the rest of the line? You see, TEX uses the per cent symbol % as the
comment character; that is a symbol which tells TEX to consider the text following as
˜comments™ and not as text to be typeset. This is especially useful for a TEX programmer
to explain a particularly sticky bit of code to others (and perhaps to himself). Even for
ordinary users, this comes in handy, to keep a ˜to do™ list within the document itself for
example.
But then, how do you get a percent sign in the output? Just type \% as in
12 THE BASICS
I.


Maybe I have now learnt about 1\% of \LaTeX.
The symbols \ and % are just two of the ten charcaters TEX reserves for its internal
use. The complete list is
˜#$%ˆ&_\{}
We have seen how TEX uses two of these symbols (or is it four? Did not we use { } in
one of our examples?) The use of others we will see as we proceed.
Also, we have noted that \ is produced in the output by the command \textbackslash
and % is produced by \%. What about the other symbols? The table below gives the inputs
to produce these symbols.

˜ &
\textasciitilde \&
# \# \_
$ \
\$ \textbackslash
% {
\% \{
ˆ }
\textasciicircum \}

You can see that except for three, all special symbols are produced by preceding them
with a \. Of the exceptional three, we have seen that \˜ and \ˆ are used for producing
accents. So what does \\ do? It is used to break lines. For example,
This is the first line.\\ This is the second line
produces

This is the ¬rst line.
This is the second line

We can also give an optional argument to \\ to increase the vertical distance between the
lines. For example,
This is the first line.\\[10pt]
This is the second line
gives

This is the ¬rst line.

This is the second line

Now there is an extra 10 points of space between the lines (1 point is about 1/72nd of an
inch).

Text positioning
I.2.6.

We have seen that TEX aligns text in its own way, regardless of the way text is formatted
in the input ¬le. Now suppose you want to typeset something like this

The TEXnical Institute


Certi¬cate

This is to certify that Mr. N. O. Vice has undergone a course at this institute
and is quali¬ed to be a TEXnician.

The Director
The TEXnical Institute

This is produced by
13
FONTS
I.3.


\begin{center}
The \TeX nical Institute\\[.75cm]
Certificate
\end{center}
\noindent This is to certify that Mr. N. O. Vice has undergone a
course at this institute and is qualified to be a \TeX nician.
\begin{flushright}
The Director\\
The \TeX nical Institute
\end{flushright}

Here, the commands
\begin{center} ... \end{center}

typesets the text between them exactly at the center of the page and the commands
\begin{flushright} ... \end{flushright}

typesets text ¬‚ush with the right margin. The corresponding commands
\begin{flushleft} ... \end{flushleft}

places the enclosed text ¬‚ush with the left margin. (Change the flushright to flushleft
and see what happens to the output.)
These examples are an illustration of a LTEX construct called an environment, which
A

is of the form
\begin{name} ... \end{name}

where name is the name of the environment. We have seen an example of an environment
at the very beginning of this chapter (though not identi¬ed as such), namely the document
environment.

FONTS
I.3.

The actual letters and symbols (collectively called type) that LTEX (or any other typeset-
A

ting system) produces are characterized by their style and size. For example, in this book
emphasized text is given in italic style and the example inputs are given in typewriter
bigger type. A set of types of a particular style
style. We can also produce smaller and
and size is called a font.

Type style
I.3.1.

In LTEX, a type style is speci¬ed by family, series and shape. They are shown in the table
A

I.1.
Any type style in the output is a combination of these three characteristics. For exam-
ple, by default we get roman family, medium series, upright shape type style in a LTEX A

output. The \textit command produces roman family, medium series, italic shape type.
Again, the command \textbf produces roman family, boldface series, upright shape type.
We can combine these commands to produce a wide variety of type styles. For exam-
ple, the input
\textsf{\textbf{sans serif family, boldface series, upright shape}}
\textrm{\textsl{roman family, medium series, slanted shape}}
14 THE BASICS
I.



Table I.1:

COMMAND
STYLE
roman \textrm{roman}




FAMILY
sans serif \textsf{sans serif}
typewriter \texttt{typewriter}
medium \textmd{medium}

SERIES
boldface \textbf{boldface}
upright \textup{upright}
italic
SHAPE



\textit{italic}
slanted \textsl{slanted}
\textsc{small cap}
SMALL CAP




produces the output shown below:

sans serif family, boldface series, upright shape
roman family, medium series, slanted shape


Some of these type styles may not be available in your computer. In that case, LTEX A

gives a warning message on compilation and substitutes another available type style
which it thinks is a close approximation to what you had requested.
We can now tell the whole story of the \emph command. We have seen that it usually,
that is when we are in the middle of normal (upright) text, it produces italic shape. But if
the current type shape is slanted or italic, then it switches to upright shape. Also, it uses
the family and series of the current font. Thus
\textit{A polygon of three sides is called a \emph{triangle} and a
polygon of four sides is called a \emph{quadrilateral}}

gives

A polygon of three sides is called a triangle and a polygon of four sides is called a quadrilateral

while the input
\textbf{A polygon of three sides is called a
\emph{triangle} and a polygon of four sides is called a
\emph{quadrilateral}}

produces

A polygon of three sides is called a triangle and a polygon of four sides is called a quadrilateral


Each of these type style changing commands has an alternate form as a declaration.
For example, instead of \textbf{boldface} you can also type {\bfseries boldface} to
get boldface. Note that that not only the name of the command, but its usage also is
different. For example, to typeset
15
TYPE
I.4. SIZE



By a triangle, we mean a polygon of three sides.

if you type
By a \bfseries{triangle}, we mean a polygon of three sides.

you will end up with

By a triangle, we mean a polygon of three sides.

Thus to make the declaration act upon a speci¬c piece of text (and no more), the decla-
ration and the text should be enclosed in braces.
The table below completes the one given earlier, by giving also the declarations to
produce type style changes.
COMMAND DECLARATION
STYLE
\textup{upright} {\upshape upright}
upright
SHAPE




\textit{italic} {\itshape italic}
italic
\textsl{slanted} {\slshape slanted}
slanted
SMALL CAP \textsc{small cap} {\scshape small cap}
\textmd{medium} {\mdseries medium}
medium
FAMILY SERIES




\textbf{boldface} {\bfseries boldface}
boldface
\textrm{roman} {\rmfamily roman}
roman
\textsf{sans serif} {\sffamily sans serif}
sans serif
typewriter \texttt{typewriter} {\ttfamily typewriter}

These declaration names can also be used as environment names. Thus to type-
set a long passage in, say, sans serif, just enclose the passage within the commands
\begin{sffmily} ... \end{sffamily}.


TYPE
I.4. SIZE

Traditionally, type size is measured in (printer) points. The default type that TEX pro-
duces is of 10 pt size. There are some declarations (ten, to be precise) provided in LTEX
A

for changing the type size. They are given in the following table:

size
{\tiny size} {\large size}
size

size
{\scriptsize size} {\Large size}
size

size
{\footnotesize size} {\LARGE size}
size

size
size {\small size} {\huge size}

size
size {\normalsize size} {\Huge size}

Note that the \normalsize corresponds to the size we get by default and the sizes form
an ordered sequence with \tiny producing the smallest and \Huge producing the largest.
Unlike the style changing commands, there are no command-with-one-argument forms
for these declarations.
We can combine style changes with size changes. For example, the “certi¬cate” we
typed earlier can now be ˜improved™ as follows
\begin{center}
{\bfseries\huge The \TeX nical Institute}\\[1cm]
{\scshape\LARGE Certificate}
16 THE BASICS
I.


\end{center}

\noindent This is to certify that Mr. N. O. Vice has undergone a
course at this institute and is qualified to be a \TeX nical Expert.

\begin{flushright}
{\sffamily The Director\\
The \TeX nical Institute}
\end{flushright}

and this produces



The TEXnical Institute
CERTIFICATE
This is to certify that Mr. N. O. Vice has undergone a course at this institute and is
quali¬ed to be a TEXnical Expert.

The Director
The TEXnical Institute
TUTORIAL II


THE DOCUMENT


DOCUMENT
II.1. CLASS

We now describe how an entire document with chapters and sections and other embellish-
ments can be produced with LTEX. We have seen that all LTEX ¬les should begin by spec-
A A

ifying the kind of document to be produced, using the command \documentclass{... }.
We™ve also noted that for a short article (which can actually turn out to be quite long!) we
write \documentclass{article} and for books, we write \documentclass{book}. There
are other document classes available in LTEX such as report and letter. All of them
A

share some common features and there are features speci¬c to each.
In addition to specifying the type of document (which we must do, since LTEX hasA

no default document class), we can also specify some options which modify the default
format.Thus the actual syntax of the \documentclass command is
\documentclass[options]{class}
Note that options are given in square brackets and not braces. (This is often the
case with LTEX commands”options are speci¬ed within square brackets, after which
A

mandatory arguments are given within braces.)

Font size
II.1.1.

We can select the size of the font for the normal text in the entire document with one of
the options
10pt 11pt 12pt
Thus we can say
\documentclass[11pt]{article}
to set the normal text in our document in 11 pt size. The default is 10pt and so this is the
size we get, if we do not specify any font-size option.

Paper size
II.1.2.

We know that LTEX has its own method of breaking lines to make paragraphs. It also has
A

methods to make vertical breaks to produce different pages of output. For these breaks
to work properly, it must know the width and height of the paper used. The various
options for selecting the paper size are given below:

11—8.5 in 20.7—21 in
letterpaper a4paper
14—8.5 in 21—14.8 in
legalpaper a5paper
10.5—7.25 in 25—17.6 in
executivepaper b5paper

Normally, the longer dimension is the vertical one”that is, the height of the page. The
default is letterpaper.

17
18 THE DOCUMENT
II.


Page formats
II.1.3.

There are options for setting the contents of each page in a single column (as is usual) or
in two columns (as in most dictionaries). This is set by the options
onecolumn twocolumn

and the default is onecolumn.
There is also an option to specify whether the document will be ¬nally printed on just
one side of each paper or on both sides. The names of the options are
oneside twoside

One of the differences is that with the twoside option, page numbers are printed on
the right on odd-numbered pages and on the left on even numbered pages, so that when
these printed back to back, the numbers are always on the outside, for better visibility.
(Note that LTEX has no control over the actual printing. It only makes the formats for
A

different types of printing.) The default is oneside for article, report and letter and
twoside for book.
In the report and book class there is a provision to specify the different chapters (we
will soon see how). Chapters always begin on a new page, leaving blank space in the
previous page, if necessary. With the book class there is the additional restriction that
chapters begin only on odd-numbered pages, leaving an entire page blank, if need be.
Such behavior is controlled by the options,
openany openright

The default is openany for reportclass (so that chapters begin on “any” new page)
and openright for the book class (so that chapters begin only on new right, that is, odd
numbered, page).
There is also a provision in LTEX for formatting the “title” (the name of the docu-
A

ment, author(s) and so on) of a document with special typographic consideration. In the
article class, this part of the document is printed along with the text following on the
¬rst page, while for report and book, a separate title page is printed. These are set by the
options
notitlepage titlepage

As noted above, the default is notitlepage for article and titlepage for report and
book. As with the other options, the default behavior can be overruled by explicitly
specifying an option with the documentclass command.
There are some other options to the documentclass which we will discuss in the rele-
vant context.

PAGE
II.2. STYLE

Having decided on the overall appearance of the document through the \documentclass
command with its various options, we next see how we can set the style for the individual
pages. In LTEX parlance, each page has a “head” and “foot” usually containing such
A

information as the current page number or the current chapter or section. Just what goes
where is set by the command
\pagestyle{...}

where the mandatory argument can be any one of the following styles
plain empty headings myheadings

The behavior pertaining to each of these is given below:
19
PAGE
II.3. NUMBERING


plain The page head is empty and the foot contains just the page number, cen-
tered with respect to the width of the text. This is the default for the
article class if no \pagestyle is speci¬ed in the preamble.
empty Both the head and foot are empty. In particular, no page numbers are
printed.
headings This is the default for the book class. The foot is empty and the head
contains the page number and names of the chapter section or subsection,
depending on the document class and its options as given below:
CLASS OPTION LEFT PAGE RIGHT PAGE
one-sided ” chapter
book, report
two-sided chapter section
one-sided ” section
article
two-sided section subsection
myheadings The same as headings, except that the ˜section™ information in the head
are not predetermined, but to be given explicitly using the commands
\markright or \markboth as described below.

Moreover, we can customize the style for the current page only using the command
\thispagestyle{style}

where style is the name of one of the styles above. For example, the page number may
be suppressed for the current page alone by the command \thispagestyle{empty}. Note
that only the printing of the page number is suppressed. The next page will be numbered
with the next number and so on.

Heading declarations
II.2.1.

As we mentioned above, in the page style myheadings, we have to specify the text to
appear on the head of every page. It is done with one of the commands
\markboth{left head{right head}
\markright{right head}

where left head is the text to appear in the head on left-hand pages and right head is the
text to appear on the right-hand pages.
The \markboth command is used with the twoside option with even numbered pages
considered to be on the left and odd numbered pages on the right. With oneside option,
all pages are considered to be right-handed and so in this case, the command \markright
can be used. These commands can also be used to override the default head set by the
headings style.
Note that these give only a limited control over the head and foot. since the general
format, including the font used and the placement of the page number, is ¬xed by LTEX.
A

Better customization of the head and foot are offered by the package fancyhdr, which is
included in most LTEX distributions.
A


PAGE
II.3. NUMBERING

The style of page numbers can be speci¬ed by the command
\pagenumbering{...}

The possible arguments to this command and the resulting style of the numbers are given
below:
20 THE DOCUMENT
II.


Indo-Arabic numerals
arabic
lowercase Roman numerals
roman
upper case Roman numerals
Roman
lowercase English letters
alph
uppercase English letters
Alph

The default value is arabic. This command resets the page counter. Thus for example, to
number all the pages in the ˜Preface™ with lowercase Roman numerals and the rest of the
document with Indo-Arabic numerals, declare \pagenumbering{roman} at the beginning
of the Preface and issue the command \pagestyle{arabic} immediately after the ¬rst
\chapter command. (The \chapter{...} command starts a new chapter. We will come
to it soon.)
We can make the pages start with any number we want by the command
\setcounter{page}{number}
where number is the page number we wish the current page to have.

FORMATTING
II.4. LENGTHS

Each page that LTEX produces consists not only of a head and foot as discussed above
A

but also a body (surprise!) containing the actual text. In formatting a page, LTEX uses
A

the width and heights of these parts of the page and various other lengths such as the
left and right margins. The values of these lengths are set by the paper size options and
the page format and style commands. For example, the page layout with values of these
lengths for an odd page and even in this book are separately shown below.
These lengths can all be changed with the command \setlength. For example,
\setlength{\textwidth}{15cm}
makes the width of text 15 cm. The package geometry gives easier interfaces to customize
page format.

PARTS
II.5. OF A DOCUMENT

We now turn our attention to the contents of the document itself. Documents (especially
longer ones) are divided into chapters, sections and so on. There may be a title part
(sometimes even a separate title page) and an abstract. All these require special typo-
graphic considerations and LTEX has a number of features which automate this task.
A


Title
II.5.1.

The “title” part of a document usually consists of the name of the document, the name
of author(s) and sometimes a date. To produce a title, we make use of the commands
\title{document name}
\author{author names}
\date{date text}

\maketitle
Note that after specifying the arguments of \title, \author and \date, we must issue the
command \maketitle for this part to be typeset.
By default, all entries produced by these commands are centered on the lines in which
they appear. If a title text is too long to ¬t in one line, it will be broken automatically.
However, we can choose the break points with the \\ command.
If there are several authors and their names are separated by the \and command, then
the names appear side by side. Thus
21
DIVIDING
II.6. THE DOCUMENT


\title{Title}
\author{Author 1\\
Address line 11\\
Address line 12\\
Address line 13
\and
Author 2\\
Address line 21\\
Address line 22\\
Address line 23}
\date{Month Date, Year}
produces


Title
Author 1 Author 2
Address line 11 Address line 21
Address line 12 Address line 22
Address line 13 Address line 23


Month Date, Year

If instead of \and, we use (plain old) \\, the names are printed one below another.
We may leave some of these arguments empty; for example, the command \date{ }
prints no date. Note, however, that if you simply omit the \date command itself, the
current date will be printed. The command
\thanks{footnote text}

can be given at any point within the \title, \author or \date. It puts a marker at this
point and places the footnote text as a footnote. (The general method of producing a
footnote is to type \footnote{footnote text} at the point we want to refer to.)
As mentioned earlier, the “title” is printed in a separate page for the document classes
book and report and in the ¬rst page of the document for the class article. (Also recall
that this behavior can be modi¬ed by the options titlepage or notitlepage.)

Abstract
II.5.2.

In the document classes article and report, an abstract of the document in special for-
mat can be produced by the commands
Abstract Text
\begin{abstract}
\end{abstract}
Note that we have to type the abstract ourselves. (There is a limit to what even LTEX can
A

do.) In the report class this appears on the separate title page and in the article class it
appears below the title information on the ¬rst page (unless overridden by the title page
option). This command is not available in the book class.

DIVIDING
II.6. THE DOCUMENT

A book is usually divided into chapters and (if it is technical one), chapters are divided
into sections, sections into subsections and so on. LTEX provides the following hierarchy
A
22 THE DOCUMENT
II.


of sectioning commands in the book and report class:
\chapter
\section
\subsection
\subsubsection
\paragraph
\subparagraph


Except for \chapter all these are available in article class also. For example, the
heading at the beginning of this chapter was produced by
\chapter{The Document}

and the heading of this section was produced by
\section{Dividing the document}

To see the other commands in action, suppose at this point of text I type
\subsection{Example}
In this example, we show how subsections and subsubsections
are produced (there are no subsubsubsections). Note how the
subsections are numbered.


\subsubsection{Subexample}
Did you note that subsubsections are not numbered? This is so in the
\texttt{book} and \texttt{report} classes. In the \texttt{article}
class they too have numbers. (Can you figure out why?)


\paragraph{Note}
Paragraphs and subparagraphs do not have numbers. And they have
\textit{run-in} headings.


Though named ˜˜paragraph™™ we can have several paragraphs of text
within this.


\subparagraph{Subnote}
Subparagraphs have an additional indentation too.

And they can also contain more than one paragraph of text.

We get

Example
II.6.1.

In this example, we show how subsections and subsubsections are produced (there are
no subsubsubsections). Note how the subsections are numbered.

Subexample
Did you note that subsubsections are not numbered? This is so in the book and report
classes. In the article class they too have numbers. (Can you ¬gure out why?)
Note Paragraphs and subparagraphs do not have numbers. And they have run-in head-
ings. Though named “paragraph” we can have several paragraphs of text within this.
Subnote Subparagraphs have an additional indentation too. And they can also con-
tain more than one paragraph of text.
23
WHAT
II.7. NEXT?


More on sectioning commands
II.6.2.

In the book and the report classes, the \chapter command shifts to the beginning of a
new page and prints the word “Chapter” and a number and beneath it, the name we have
given in the argument of the command. The \section command produces two numbers
(separated by a dot) indicating the chapter number and the section number followed
by the name we have given. It does not produce any text like “Section”. Subsections
have three numbers indicating the chapter, section and subsection. Subsubsections and
commands below it in the hierarchy do not have any numbers.
In the article class, \section is highest in the hierarchy and produces single number
like \chapter in book. (It does not produce any text like “Section”, though.) In this case,
subsubsections also have numbers, but none below have numbers.
Each sectioning command also has a “starred” version which does not produce num-
bers. Thus \section*{name} has the same effect as \section{name}, but produces no
number for this section.
Some books and longish documents are divided into parts also. LTEX also has a \part
A

command for such documents. In such cases, \part is the highest in the hierarchy, but it
does not affect the numbering of the lesser sectioning commands.
You may have noted that LTEX has a speci¬c format for typesetting the section head-
A

ings, such as the font used, the positioning, the vertical space before and after the heading
and so on. All these can be customized, but it requires some TEXpertise and cannot be
addressed at this point. However, the package sectsty provided some easy interfaces for
tweaking some of these settings.

WHAT
II.7. NEXT?

The task of learning to create a document in LTEX is far from over. There are other
A

things to do such as producing a bibliography and a method to refer to it and also at the
end of it all to produce a table of contents and perhaps an index. All these can be done
ef¬ciently (and painlessly) in LTEX, but they are matters for other chapters.
A
6
i
i 2
4
i
5
? ?
?
? Header
6
6
i
6 6
6




i
Margin
Body 7
Notes



i
9-
i-
 10

i
3- 




i
 -
8
i
11

? ?
Footer
6
 1i-


1 one inch + \hoffset 2 one inch + \voffset
3 \evensidemargin = 54pt 4 \topmargin = 18pt
5 \headheight = 12pt 6 \headsep = 18pt
7 \textheight = 609pt 8 \textwidth = 380pt
9 \marginparsep = 7pt 10 \marginparwidth = 115pt
11 \footskip = 25pt \marginparpush = 5pt (not shown)
\hoffset = 0pt \voffset = 0pt
\paperwidth = 597pt \paperheight = 845pt
6
i
i 2
4
i
5
? ?
?
? Header
6
6
i
6 6
6




i Margin
Body 7
Notes



i
9
-
i-
 10

i
3
-




i
 -
8
i
11

? ?
Footer
6
 1i-


1 one inch + \hoffset 2 one inch + \voffset
3 \oddsidemargin = 18pt 4 \topmargin = 18pt
5 \headheight = 12pt 6 \headsep = 18pt
7 \textheight = 609pt 8 \textwidth = 380pt
9 \marginparsep = 7pt 10 \marginparwidth = 115pt
11 \footskip = 25pt \marginparpush = 5pt (not shown)
\hoffset = 0pt \voffset = 0pt
\paperwidth = 597pt \paperheight = 845pt
26
TUTORIAL III


BIBLIOGRAPHY


INTRODUCTION
III.1.

Bibliography is the environment which helps the author to cross-reference one publica-
tion from the list of sources at the end of the document. LTEX helps authors to write a
A

well structured bibliography, because this is how LTEX works”by specifying structure.
A

It is easy to convert the style of bibliography to that of a publisher™s requirement,
without touching the code inside the bibliography. We can maintain a bibliographic data
base using the program BIBTEX. While preparing the articles, we can extract the needed
references in the required style from this data base. harvard and natbib are widely used
packages for generating bibliography.
To produce bibliography, we have the environment thebibliography1 , which is sim-
ilar to the enumerate environment. Here we use the command \bibitem to separate the
entries in the bibliography and use \cite to refer to a speci¬c entry from this list in the
document. This means that at the place of citation, it will produce number or author-year
code connected with the list of references at the end.
\begin{thebibliography}{widest-label}
\bibitem{key1}
\bibitem{key2}
\end{thebibliography}

The \begin{thebibliography} command requires an argument that indicates the
width of the widest label in the bibliography. If you know you would have between
10 and 99 citations, you should start with
\begin{thebibliography}{99}

You can use any two digit number in the argument, since all numerals are of the same
width. If you are using customized labels, put the longest label in argument, for example
\begin{thebibliography}{Long-name}. Each entry in the environment should start with

\bibitem{key1}

If the author name is Alex and year 1991, the key can be coded as ale91 or some
such mnemonic string2 . This key is used to cite the publication within the document text.
To cite a publication from the bibliography in the text, use the \cite command, which
takes with the corresponding key as the argument. However, the argument to \cite can
also be two or more keys, separated by commas.
environment need two compilations. In the ¬rst compilation it will generate ¬le with aux
1 Bibiliography

extension, where citation and bibcite will be marked and in the second compilation \cite will be replaced
by numeral or author-year code.
2 Key can be any sequence of letters, digits and punctuation characters, except that it may not contain a

comma (maximum 256 characters).


27
28 BIBLIOGRAPHY
III.


\cite{key1} \cite{key1,key2}

In bibliography, numbering of the entries is generated automatically. You may also add
a note to your citation, such as page number, chapter number etc. by using an optional
argument to the \cite command. Whatever text appears in this argument will be placed
within square brackets, after the label.
\cite[page˜25]{key1}

See below an example of bibliography and citation. The following code
It is hard to write unstructured and disorganised documents using
\LaTeX˜\cite{les85}.It is interesting to typeset one
equation˜\cite[Sec 3.3]{les85} rather than setting ten pages of
running matter˜\cite{don89,rondon89}.

\begin{thebibliography}{9}
\bibitem{les85}Leslie Lamport, 1985. \emph{\LaTeX---A Document
Preparation System---User™s Guide and Reference Manual},
Addision-Wesley, Reading.


\bibitem{don89}Donald E. Knuth, 1989. \emph{Typesetting Concrete
Mathematics}, TUGBoat, 10(1):31-36.


\bibitem{rondon89}Ronald L. Graham, Donald E. Knuth, and Ore
Patashnik, 1989. \emph{Concrete Mathematics: A Foundation for
Computer Science}, Addison-Wesley, Reading.
\end{thebibliography}


produces the following output:

It is hard to write unstructured and disorganised documents using LTEX [1]. It is interesting to
A

typeset one equation [1, Sec 3.3] rather than setting ten pages of running matter [2,3].

Bibliography
[1] Leslie Lamport, 1985. LTEX”A Document Preparation System”User™s Guide and Refer-
A

ence Manual, Addision-Wesley, Reading.
[2] Donald E. Knuth, 1989. Typesetting Concrete Mathematics, TUGBoat, 10(1):31-36.
[3] Ronald L. Graham, Donald E. Knuth, and Ore Patashnik, 1989. Concrete Mathematics:
A Foundation for Computer Science, Addison-Wesley, Reading.



III.2. NATBIB

The natbib package is widely used for generating bibliography, because of its ¬‚exible
interface for most of the available bibliographic styles. The natbib package is a re-
implementation of the LTEX \cite command, to work with both author“year and nu-
A

merical citations. It is compatible with the standard bibliographic style ¬les, such as
plain.bst, as well as with those for harvard, apalike, chicago, astron, authordate, and
of course natbib. To load the package; use the command.
\usepackage[options]{natbib}
29
III.2. NATBIB


Options for natbib
III.2.1.

(default) for round parentheses
round
for square brackets
square
for curly braces
curly
for angle brackets
angle
(default) to separate multiple citations with colons
colon
to use commas as separators
comma
(default) for author“year citations
authoryear
for numerical citations
numbers
for superscripted numerical citations, as in Nature
super
orders multiple citations into the sequence in which they

. 1
( 7)



>>