2
Looking at the Basics
2.1 The Process of LaTeX
For those who chose to skip the introduction chapter and just want to get into the heart of the topic, LaTeX is a typesetting program and is an extension of the original program TeX written by Donald Knuth.
To answer this, let us look at the various stages in the preparation of a document using computers.
- 1.
-
The text is
entered into the computer by the user or some script. - 2.
-
The input text is
formatted into lines, paragraphs and pages. - 3.
-
The output text is
displayed on the computer screen. - 4.
-
The final output is
printed .
For
word
processors
TeX is also a full
-
Drawing scientific diagrams,
-
Doing mathematical calculations,
-
Automating document creation,
-
Embedding lua-script, and
-
Generating slides.
In fact LaTeX itself has a significant collection of extra features, and the collective effort is continuing, with more and more people writing extra packages.
2.1.1 A Small Example
Let
us
see
LaTeX in
action
by
typesetting
a
short
document.
We
will
start
with
our
text
editor
Be very careful with the \ character (called the backslash). We use this character to denote something is a command and is different from / (called slash)
Once
you
have
written
the
text,
save
the
file
onto
the
hard
disk
as
myfile.tex.
At
the
shell
prompt,
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
A window comes up showing the output below
This
is
my
Now
let
us
take
a
closer
look
at
the
source
file
.tex
file
.
The
first
line \documentclass{article}
tells
LaTeX that
what
we
want
to
produce
is
an
article.
If we want to write a book, this must be changed to \documentclass{book}
. We will look into these a bit later.
The whole document we want to typeset should be included between \begin{document}
and \end{document}
. Think of this as a wrapper which contains all the text we
want
to print out to the user.
Any part which is before \begin{environment}
is called the
preamble
.
Looking
back
to
our
example,
this
is
just
one
\emph{first}
,
becomes
\emph
is
a
command
to
LaTeX to
typeset
the
text
within
the
braces
in
Following
this,
the
next
three
words
come
out
without
any
change
in
the
output.
Finally,
the
input \LaTeX
comes
out
in
the
output
as
LaTeX.
Therefore,
as
we
see,
our
source
is
a
mixture
of
text
to
be
typeset
and
a
couple
of
LaTeX commands \emph
and \LaTeX
.
The
first
command
changes
the
input
text
in
a
certain
way
and
the
second
one
generates
new
text.
Now call up the file again and add one more sentence given below.
What
do
you
get
in
the
output?
What
new
text
does
the
command \today
generate?
2.1.2 What is the Point of LaTeX
So, why all this trouble and why not simply use a word processor?
The
answer
lies
in
the
motivation
behind
LaTeXḊonald
Knuth
says
that
his
aim
in
creating
LaTeX is
to
If you want your document to look really
2.2 Basics of Typesetting
We
have
seen
that
to
typeset
something
in
LaTeX,
we
type
in
the
text
to
be
typeset
together
with
some
commands.
Words
must
be
separated
by
spaces
The
end
of
a
paragraph
is
specified
by
a
\noindent 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. \noindent 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.
If
you
noticed
the
first
line
of
each
paragraph
starts
without
an
indentation
from
the
left
margin
of
the
text.
This
is
caused
by
the
command \noindent
.
To
allow
indentation,
simply
remove
the
command.
There is an easier way to suppress paragraph indentation for all paragraphs of the document in one go, but such tricks can wait.
2.2.1 The Use of Spaces
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. LaTeX does this by adjusting the space between the words.
In traditional typesetting, a little extra space is added to periods which end sentences and LaTeX also follows this custom. But how does LaTeX 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
We
use
the
command \@
before
the
period
to
produce
the
extra
space
after
the
period.
On the other hand, there are instances where a period following a lowercase letter does not end a sentence. For example [20]:
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:
Here,
we
use
the
command
\.
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:
We get:
I think LaTeXis fun.
What happened to the space we typed between LaTeX and is?
You see, LaTeX 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.
2.2.2 Quotations
Have you noticed that in typesetting, opening quotes are different from closing quotes?
Look at the LaTeX output below:
This is produced by the input
Note the difference in right and left quotes in ‘single quotes’ and “double quotes”.
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.
2.2.3 Dashes
In text, dashes are used for various purposes and they are distinguished in typesetting by their lengths;
-
Short dashes are used for hyphens,
-
Longer dashes are used to indicate number ranges and still longer dashes used for parenthetical comments.
Let’s have a 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:
Please observe that:
-
one dash (
-
) produces a hyphen in the output (-), -
two dashes (
--
) produces a longer dash in the output (–), -
three dashes (
---
) produce the longest dash (—) in the output.
2.2.4 Accents
Sometimes,
especially
when
typing
foreign
words
in
English,
or
just
writing
documents
in
non-english,
we
need
to
put
different
types
of
Each column shows some of the accents and the inputs to generate them.
ó | \'o
|
ó | \'o
|
ô | \^o
|
õ | \~o
|
---|---|---|---|---|---|---|---|
ō | \=o
|
ȯ | \.o
|
ö | \"o
|
c | \c c
|
o | \u o
|
o | \v o
|
o | \H o
|
o | \d o
|
o¯ | \b o
|
oo | \t oo
|
The letters i and j need special treatment with regard to accents, since they should not have their customary dots when accented.
\i
and
\j
produce
dot-less
i
and
j
as
and
.
Él está aquí
we need to type:
Some symbols from non-English languages are also available in LaTeX, as shown in the table below:
œ | \oe
|
Œ | \oe
|
æ | \ae
|
Æ | \AE
|
---|---|---|---|---|---|---|---|
a | \aa
|
A | \AA
|
||||
\o
|
\o
|
\l
|
\L
|
||||
ß | \ss
|
||||||
¡ | !`
|
¿ | ?`
|
2.2.5 Special Symbols
We
have
seen
that
input \LaTeX
produces
LaTeX in
the
output
and \
produces
a
space.
Therefore,
TeX uses
the
symbol
\ for
a
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?
As
you
have
notices
\ is
a
symbol
which
has
a
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
a percent sign in the output? Just type \%
as in
which would give us:
Maybe I have now learnt about 1% of LaTeX.
The symbols \ and % are just two
We have seen how LaTeX uses two of these symbols and 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.
Output | Command | Output | Command |
---|---|---|---|
~ | \textasciitilde
|
& | \&
|
# | \#
|
_ | \_
|
$ | \$
|
\ | \textbackslash
|
% | \%
|
{ | \{ |
^ | \textasciicircum
|
} | \} |
As we can see from the aforementioned table that except for three \\
do?
It is used to break lines.
For example,
produces
This is the first line. This is the second line
We can also give an
\\
to i
ncrease the vertical distance
between the lines. For example,
gives
This is the first line. This is the second line
Now
there
is
an
extra
10
points
of
space
between
the
lines.
1pt
)
is
about
th
of
an
inch.
2.2.6 Position of Text
We
have
seen
up
to
now,
that
LaTeX aligns
text
in
Management Centre Innsbruck Mechatronics Welcomes You!
This is to certify that you have chosen to become great engineers by the time your degree is finished!!
The Lecturer D. T. McGuiness
Which is produced by the following command:
Let’s have a look at the comments. Here, the commands:
typesets the text between them exactly at the center of the page and the commands
typesets text flush with the right margin. The corresponding commands
places
the
enclosed
text
flush
with
the
flushright
to flushleft
and
see
what
happens
to
the
output.
These
examples
are
an
illustration
of
a
LaTeX construct
called
an
where
document
environment.
2.3 Fonts
The
actual
letters
and
symbols
typewriter
style.
We
can
also
produce
smaller and
bigger type.
A set of types of a particular style and size is called a font.
2.3.1 Type Style
In LaTeX, a type style is specified by family, series and shape. They are shown in the Table ??
Style | Command | |
---|---|---|
Family | roman | \textrm{roman}
|
sanf serif | \textsf{sans serif}
|
|
typewriter | \texttt{typewriter}
|
|
Series | medium | \textmd{medium}
|
boldface | \textbf{boldface}
|
|
Shape | upright | \textup{upright}
|
|
\textit{italic}
|
|
slanted | \textsl{slanted}
|
|
|
\textsc{small cap}
|
Any type style in the output is a combination of these three \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 example, the input:
which produces the following output:
sans serif family, boldface series, upright shape roman family, medium series, slanted shape
It may be possible that some of these type styles may NOT be available in your computer. In that case, LATEX 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
whereas the following input:
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
\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:
By a triangle , we mean a polygon of three sides.
if we were to write:
we would get:
By a triangle, we mean a polygon of three sides.
Therefore
to
make
the
declaration
act
upon
a
specific
piece
of
text,
Style | Command | Declaration | |
---|---|---|---|
Family | roman | \textrm{roman}
|
{\rmfamily roman}
|
sanf serif | \textsf{sans serif}
|
{\sffamily sans serif}
|
|
typewriter | \texttt{typewriter}
|
{\ttfamily typewriter}
|
|
Series | medium | \textmd{medium}
|
{\mdseries medium}
|
boldface | \textbf{boldface}
|
{\bfseries boldface}
|
|
Shape | upright | \textup{upright}
|
{\upshape upright}
|
|
\textit{italic}
|
{\itshape italic}
|
|
slanted | \textsl{slanted}
|
{\slshape slanted}
|
|
|
\textsc{small cap}
|
{\scshape small cap}
|
These declaration names can also be used as environment names. Therefore to typeset a long passage in, say, sans serif, just enclose the passage within the commands:
2.4 Type Size
Traditionally,
type
size
is
measured
in
(printer)
points.
The
default
type
that
TeX produces
is
of
Size | Command | Size | Command |
---|---|---|---|
size | \tiny size
|
size | \large size
|
size | \scriptsize size
|
size | \Large size
|
size | \footnote size
|
size | \LARGE size
|
size | \small size
|
size | \huge size
|
size | \normalsize size
|
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.