5
Typesetting Mathematics
5.1 True Purpose of TeX
Donald Knuth created TeX for primarily typesetting Mathematics
Packages like amsmath are worth mentioning here as they enhance and refine these interfaces significantly.
5.2 Fundamentals
A mathematical expression occurring in running text, called
$...$
. Therefore if we want to produce:
The equation representing a straight line in Cartesian plane is of the form , where , , are constants.
we need to type:
Let’s see what is going on here.
First,
note
the
text
within
dollars
is
typeset
in
On
the
other
hand,
even
if
we
type $ax + by + c = 0$
,
the
output
would
be
the
same
TeX has its own spacing rules in math mode and knows to disregard user-given space.
To see another instance of this, change the last part of the code above to read
On first glance, it saves some typing. However, look at the output:
The equation representing a straight line in Cartesian plane is of the form , where are constants.
See the difference?
There are no spaces after the commas, though we had such spaces in the output. So TeX swallows spaces in math mode.
As
we
have
seen
in
these
examples,
dollar
signs ($..$
)
are
TeX way
of
distinguishing
mathematical
text.
LaTeX has
other
ways
also
of
doing
it,
-
using
\( ... \)
-
or
\begin{math} ... \end{math}
.
Therefore either of the inputs shown below also produces the same output as above.
Continuing on, suppose we want to
The equation representing a straight line in the Cartesian plane is of the form
where , , are constants.
This can be done by changing the input as follows:
Again $$...$$
is the TeX way of producing displayed math. LaTeX has the additional
constructs \[ ... \]
or \begin{displaymath} ... \end{displaymath}
also to do this.
5.2.1 Superscripts and Subscripts
Now let’s look at the text below:
In the seventeenth century, Fermat conjectured that if , then there are no integers , , for which
(5.1) |
This was proved in 1994 by Andrew Wiles.
This is produced by the input
This
shows
that
superscripts
^
symbol.
If
the
superscript
is
more
than
one
character
long,
be
careful
to
group
these
characters
properly.
Therefore to produce:
It is easily seen that .
we must type:
Instead of $x^{mn}$
, if we type $x^mn$
we end up with
instead of the intended
in the output.
We
can
have
superscripts
of
superscripts.
Numbers of the form , where is a natural number, are called Fermat numbers.
is produced by:
Please observe that we have grouped the superscript.
Now
let
us
see
how
subscripts
To get the following output:
The sequence defined by
is called the Fibonacci sequence.
we need to type:
We
can
see,
subscripts
are
produced
by
the _
character.
Note
how
we
insert
spaces
by
the \quad
command.
\;
in
math
mode
produces
what
is
known
as
a
“thickspace”.
Subscripts
of
subscripts
can
be
produced
as
in
the
case
of
superscripts
with
appropriate
grouping.
We can also have superscripts and subscripts together. For example:
If the sequence converges to , then the sequence converges to
is produced by
Again, we must be careful about the grouping (or the lack of it) when typesetting superscripts and subscripts together. The following inputs and the corresponding outputs showcases the problems one may encounter:
Information : Character Boxes
This has to do with the way TeX internally works to produce characters, producing “boxes” to fit the output characters. The box for can be taught as , whereas the box for can be visualised as
5.2.2 Roots
To
put
it
simply,
square-roots
are
produced
by
the \sqrt
argument.
Therefore $\sqrt{2}$
produces
.
This
command
has
an
optional
argument
to
produce
other
roots.
As
an
example:
Which is greater or ?
is produced by
The horizontal line above the root
$\sqrt{x+y}$
produces
. Also, you can produce nested roots as in
The sequence
converge to .
by typing
The \ldots
command
above
produces
…,
the
three
dots
indicating
indefinite
continuation,
called
ellipsis
(more
about
them
later).
The
command \,
produces
a
“thinspace”
\;
,
seen
earlier.
Why all this thin and thick spaces in the above input? Remove them and see the difference. A tastefully applied thinspace is what makes a mathematical expression typeset in TeX really beautiful.
The symbol
in the output produced by $\pi$
. It is a Greek letter named “pi”. Mathematicians often use letters of the Greek alphabet and a
multitude of other symbols in their work. A list of available symbols in LaTeX is given at the end of this chapter.
Note that certain symbols are marked to be not available in vanilla LaTeX, but only in certain packages.
5.2.3 Symbols in Mathematics
We have noted that TeX leaves some additional spaces around “binary operators” such as
and
.
The same is true for any symbol classified as a binary operator.
For real numbers and , define an operation by
This operation is associative.
Observe there are spaces surrounding the symbol in the output. On the other hand suppose we want the following output:
For real numbers and , define an operation by
The list of symbols show that the symbol
is produced by
but
that it is available only in the package
latexsym
or
amssymb
. So if we load one of these using the \usepackage
command and then type:
you will only get
For real numbers and , define an operation by
Notice the difference? There are
NO
spaces around
.
This is because, this symbol is
NOT
by default defined as a binary operator. But we can
ask TeX to consider this symbol as a binary operator by the command \mathbin
before \Box
as in:
For real numbers and , define an operation by
and this will produce the output shown first. This holds for Relations as well.
TeX leaves some space around "Relation" symbols and we can instruct TeX to consider
any symbol as a relation by the command \mathrel
. Therefore we can produce
Define the relation on the set of real numbers by iff is a rational number.
by typing
5.3 Custom Commands
We
have
seen
that
LaTeX produces
mathematics
For example, suppose that the following expression occurs too frequently in a document. If we now write:
Then
we
can
type $\vect$
anywhere
after
wards
to
produce
as
in
to get
We often write to denote the vector .
The
best
place
to
keep
such
“newcommands”
is
the
preamble,
\begin{environment}
,
so
that
we
can
use
them
anywhere
in
the
document.
Also,
it
will
be
easier
to
change
the
commands,
if
the
need
arises.
OK,
we
can
now
produce
with $\vect$
vects,
but
how
about
or
?
Do
we
have
to
define
new
commands
for
each
of
these?
No,
as
we
can
also
define
commands
with
\vect
to:
Then
we
can
use $\vect{x}$
to
produce
and $\vect{x}$
to
produce
and
so
on.
The
form
of
this
definition
calls
for
some
elaboration.
The [1]
in
the \newcommand
above
indicates
that
the
command
is
to
have
one
##1
?
Before
producing
the
output,
each
occurrence
of ##1
will
be
replaced
by
the
single
argument
we
supply
to \vect
in
the
input.
For
example,
the
input $\vect{a}$
will
be
changed
to $(a_1,a_2,\dots,a_n)$
at
some
stage
of
the
compilation.
We
can
also
define
commands
with
more
than
one
argument.
\vect
to
so
that
we
can
use $\vect{x}{n}$
to
produce
and $\vect{y}{p}$
to
produce
.
5.4 Additional Math
There are some many other features of typesetting math in LaTeX, but these have better implementations in the package amsmath which has some additional features as well. So, for the rest of the chapter the discussion will be with reference to this package and its derivatives.
All discussion below is under the assumption that the package
amsmath
has been loaded with the command \usepackage{amsmath}
.
5.4.1 Single Equations
In addition to the LaTeX commands for displaying math as discussed earlier, the
amsmath
also provides
the \begin{equation*} ... \end{equation*}
construct. Thus with this package loaded, the output
The equation representing a straight line in the Cartesian plane is of the form
where , , are constants.
can also be produced by
Why the *
after equation? Suppose we try it without the *
as:
we get:
The equation representing a straight line in the Cartesian plane is of the form
(5.2) |
where , , are constants.
This provides the equation with a
Ordinary text can be inserted inside an equation using the \text
command. Therefore we can get:
Thus for all real numbers we have
and so
from:
Note
the
use
of
dollar
signs
in
the
second \text
above
to
produce
mathematical
symbols
within \text
.
Sometimes
a
single
equation
maybe
too
long
to
fit
into
one
line.
This
is
produced
by
the
environment multline*
,
multline
can
be
used
for
equations
requiring
more
than
two
which produces:
By default, the multline
environment places the first line flush left, the last line flush right and the lines in between,
centered within the display. A better way to typeset the above multiline (not multline) equation is as follows.
This is done using the split environment as shown below.
Let’s understand what is going on here. First note that the split
environment cannot be used independently,
but only inside some equation structure such as equation. Unlike multline
, the split
environment provides for
alignment among the “split” lines (using the & character, as in tabular). Therefore in the above example, all the
signs are aligned and these in turn are aligned with a point a to the right of the
sign. It is also useful when the equation contains multiple equalities as in
which is produced by
5.4.2 Groups of Equations
A group of displayed equations can be typeset in a single go using the gather
environment. For example,
can be produced by
Now when several equations are to be considered one unit, the logically correct way of typesetting them is with some alignment. For example,
Thus , and satisfy the equations
This is obtained by using the align*
environment as shown below
We can add a short piece of text between the equations, without disturbing the alignment, using the \intertext
command. For example, the output
Thus , and satisfy the equations
We can also set multiple
Compare the following sets of equations
All that it needs are extra
We can also adjust the horizontal space between the equation columns. For example, Compare the sets of equations
gives
Compare the sets of equations
Perhaps a nicer way of typesetting the above is
Compare the following sets of equations
This cannot be produced by the equation structures discussed so far, because any of these environments takes up the entire width
of the text for its display, so that we cannot put anything else on the same line. So
amsmath
provides variants gathered
, aligned
and alignedat
which take up only the
Another often recurring structure in mathematics is a display like this
There is a special environment cases in amsmath to take care of these. The above example is in fact produced by
5.4.3 Numbered Equations
We have mentioned that each of the the
equation*
as in
produces
The equation representing a straight line in the Cartesian plane is of the form
(5.3) |
where , , are constants.
Why VIII.2 for the equation number? Well, this is Equation number 2 of Chap- ter VIII, isn’t it? If you want the section number also in the equation number, just give the command
We can also override the number L’IFX produces with one of our own design with the \tag
command as in
which gives
The equation representing a straight line in the Cartesian plane is of the form
(L) |
where , , are constants.
There is also a \tag*
command which typesets the equation label without parentheses. What about numbering alignment structures? Except
for split and aligned, all other alignment structures have unstarred forms which attach numbers to each aligned equation. For example,
gives:
Here is also, you can give a label of your own to any of the equations with the \tag
command. Be careful to give the \tag
before
the end of line character \\
though. (See what happens if you give a \tag
command after a \\
.) You can also
suppress the label for any equation with the \notag
command. These are illustrated in the sample input below:
which gives the following output
Thus , and satisfy the equations
What about split and aligned? As we have seen, these can be used only within some other equation structure. The numbering or the lack of it is determined by this parent structure. Thus
(5.6) |
5.5 Additional Commands
There are more things Mathematics than just equations. Let us look at how LaTeX and in particular, the amsmath package deals with them.
5.5.1 Matrices
VIII.4.1. Matrices Matrices are by definition numbers or mathematical expressions arranged in rows and columns. The amsmath has several environments for producing such arrays. For example
The system of equations
can be written in matrix terms as
Here, the matrix is invertible.
The system of equations \begin{align*} x+y-z & = 1\\ x-y+z & = 1\\ x+y+z & = 1 \end{align*} can be written in matrix terms as \begin{equation*} \begin{pmatrix} 1& 1&-1\\ 1&-1& 1\\ 1&1&1 \end{pmatrix} \begin{pmatrix} x\\ y\\ z \end{pmatrix} = \begin{pmatrix} 1\\ 1\\ 1 \end{pmatrix}. \end{equation*} Here, the matrix $\begin{pmatrix} 1& 1&-1\\ 1&-1& 1\\ 1&1&1 \end{pmatrix}$ is invertible.
Note that the environment pmatrix can be used within in-text mathematics or in displayed math. Why the p? There is indeed an environment matrix (without a p) but it produces an array <i>without</i> the enclosing parentheses (try it). If you want the array to be enclosed within square brackets, use bmatrix instead of pmatrix. Thus
Some mathematicians write matrices within parentheses as in while others prefer square brackets as in
is produced by
Some mathematicians write matrices within parentheses as in
There is also a vmatrix environment, which is usually used for determinants as in
The determinant is defined by
which is obtained from the input
There is a variant Vmatrix
which encloses the array in double lines. Finally, we have a Bmatrix environment which produces an
array enclosed within braces { }
. A row of dots in a matrix can be produced by the command \hdotsfour
. it
should be used with an argument specifying the number of columns to be spanned. For example, to get
A general matrix is of the form
we type
The command \hdotsfor
has also an optional argument to specify the spacing of dots.
5.5.2 Dots
In the above example, we used the command \dots
to produce a row of three
gives
Consider a finite sequence , its sum and product .
Here the dots in all the three
Consider a finite sequence , its sum and product .
with raised dots for addition and multiplication?
The above text is typeset by the input
Here:
-
\dotsc
stands for dots to be used with commas, -
\dotsb
for dots with binary operations (or relations), and -
\dotsm
for multiplication dots.
There is also a \dotsi
for dots with integrals as in
5.5.3 Delimiters
How do we produce something like
, the matrix is not invertible.
Here the
smallmatrix
. This
environment does
NOT
provide the enclosing
Why the \left|...\right|
and \left{...\right}
?
These commands \left
and \right
enlarge the delimiter following them to the size of the enclosed material. To see their ef- fect,
try typesetting the above example without these commands. The list of symbols at the end of the chapter gives a list of
delimiters that are available off the shelf. One interesting point about the \left
and \right
pair is that, though every \left
should be matched to a \right
, the delimiters to which they apply need not match. In par- ticular we can produce a single large
delimiter produced by \left
or \right
by matching it with a matching command followed by a period. For example,
is produced by
There are instances where the delimiters produced by \left
and \right
are too small or too large. For example,
gives
where the parentheses are all of the same size. But it may be better to make the outer ones a little larger to make the nesting visually apparent, as in
This is produced using the commands \bigl
and \bigr
before the outer parentheses as shown below:
This is produced using the commands \bigl
and \bigr
before the outer parentheses as shown below:
Apart from \bigl
and \bigr
there are \Bigl
, \biggl
and \Biggl
commands (and their r counterparts) which (in order) produce
delimiters of increasing size. (Experiment with them to get a feel for their sizes.) As another example, look at
For -tuples of complex numbers and of complex numbers
which is produced by:
Does not the output below look better?
For -tuples of complex numbers and of complex numbers
This one is produced by
Here the trouble is that the delimiters produced by \left
and \right
are a bit too large.
5.5.4 Putting One Over Another
Look at the following text
From the binomial theorem, it easily follows that if is an even number, then
We have fractions like and binomial coefficients like here and the common feature of both is that they have one mathematical expression over another.
Fractions are produced by the \frac
command which takes two \binom
command which also takes two
arguments, the “top” expression followed by the “bottom” one. Thus the the input for the above example is
You can see from the first paragraph above that the
\frac
and \binom
are smaller in text than in display.
This default behavior has to be modified sometimes for nicer looking output. For example, consider the following output
Since converges to , there exists a positive integer such that
The second output is produced by the input:
Note the use of the command \tfrac
to produce a smaller fraction. (The first output is produced by
the usual \frac
command.) There is also command \dfrac
to produce a display style (larger size)
fraction in text. Thus the sentence after the first example in this (sub)section can be typeset as
We have fractions like and ...
by the input
As can be guessed, the original output was produced by \frac
. Similarly, there are commands \dbinom
(to produce display style binomial coefficients) and \tbinom
(to produce text style binomial coefficients).
There is also a \genfrac
command which can be used to produce custom fractions. To use it, we will have to specify six
- 1.
- The left delimiter to be used-note that must be specified as {
- 2.
- The right delimiter-again, to be specified as }
- 3.
- The thickness of the horizontal line between the top expression and the bottom expression. If it is not specified, then it defaults to the ’normal’ thickness. If it is set as 0pt then there will be no such line at all in the output.
- 4.
-
The
size
of
the
output-this
is
specified
as
an
integer
0,
1,
2
or
3,
greater
values
cor-
responding
to
smaller
sizes.
(Technically
these
values
correspond
to
\displaystyle
,\textstyle
,\scriptstyle
and\scriptscriptstyle
.) - 5.
- The top expression
- 6.
- The bottom expression
Thus instead of \tfrac{1}{2}
we can also use \genfrac{}{}{}{1}{1}{2}
and instead of \dbinom{n}{r}
, we can also use \genfrac{(}{)}{0pt}{0}{1}{2}
(but there is hardly any reason for doing so). More seriously, suppose we want to produce:
The Christoffel symbol of the second kind is related to the Christoffel symbol of the first kind by the equation
If such expressions are frequent in the document, it would be better to define ’newcom mands’ for them and use them instead of \genfrac
every time as in the following input (which produces the same output as above). Therefore we can write the above expression as:
\newcommand{\chsfk}[2]{\genfrac{[}{]}{0pt}{}{#1}{#2}} \newcommand{\chssk}[2]{\genfrac{\{}{\}}{0pt}{}{#1}{#2}} The Christoffel symbol $\genfrac{\{}{\}}{0pt}{}{ij}{k}$ of the second kind is related to the Christoffel symbol $\genfrac{[}{]}{0pt}{}{ij}{k}$ of the first kind by the equation \begin{equation*} \chssk{ij}{k}=g^{k1}\chsfk{ij}{1}+g^{k2}\chsfk{ij}{2} \end{equation*}
While on the topic of fractions, we should also mention the \cfrac
command used to typeset continued fractions. For example, to get
5.5.5 Putting Symbols Over or Under
The table at the end of this chapter gives various math mode accents such as $\hat{a}$
to produce
and $\dot{a}$
to
produce
. But what
if one needs
or
?
The commands \overset
and \underset
come to the rescue. Thus $\overset{\circ}{a}$
produces
and $\underset{\circ}{a}$
produces
.
Basic LaTeX provides the commands \overrightarrow
and \overleftarrow
also to put (extensible) arrows
over symbols, as can be seen from the table. The
amsmath
package also provides the commands \underrightarrow
and \underleftarrow
to put (extensible) arrows below mathematical expressions.
Speaking of arrows,
amsmath
provides the commands \xrightarrow
and \xleftarrow
which produces
arrows which can accommodate long texts as superscripts or subscripts. Thus we can produce:
Thus we see that
which is generated from:
Note how the mandatory arguments of the first and last arrows are left empty to produce arrows with no superscripts. These commands also allow an optional argument (to be typed inside square brackets), which can be used to produce subscripts. For example
gives:
Thus we get
By the way, would not it be nicer to make the two middle arrows the same width? This can be done by changing the command for the third arrow (the one from B) as shown below:
which produces:
Thus we get
where the lengths of the two arrows are almost the same. There are indeed ways to make the lengths exactly the same, but we will talk about it in another chapter.
Mathematical symbols are also attached as
gives the output:
Euler not only proved that the series converges, but also that
Note that in display, the sum symbol is larger and the limits are put at the bottom and top (instead of at the sides,which is usually the case for subscripts and superscripts). If you want the same type of symbol (size, limits and all) in text also, simply change the line
to
and we will get:
Euler not only proved that the series converges, but also that
(Note that this also changes the size of the fraction. What would you do to keep it small?) On the other hand, to make the
displayed operator the same as in the text, add the command \textstyle
before the \sum
within the equation. What if you only
want to change the position of the limits but not the size of the operator in text? Then change the command $\sum_{n=1}^\infty\frac{1}{n^2}$
to $\sum_\limits{n=1}^\infty\frac{1}{n^2}$
and this will produce the output given below.
Euler not only proved that the series converges, but also that
On the other hand, if you want side-set limits in display type \nolimits
after the \sum
within the equation as in
All these are true for other operators classified as “Variable-sized symbols”,except integrals. Though the integral symbol in display is larger, the position of the limits in both text and display is on the side as can be seen from the output below
Thus and so by definition,
which is produced by:
5.6 New Operators
Mathematical text is usually typeset in
$\log$
, $\sin$
, $\lim$
and so on. The
symbols classified as "Log-like symbols" in the table at the end of this chapter shows such functions which are predefined in LaTeX.
Having read thus far, it may be no surprise to learn that we can define our own "operator names" which receive this special typographic treatment.
This is done by the \DeclareMathOperator
command. Thus if the operator cl occurs frequently in the document, you can make the declaration
5.7 Fonts for Mathematics
We have noted that most mathematics is typeset in italics typeface and some mathematical operators are typeset in an upright fashion. There may be need for additional typefaces as in typesetting vectors in boldface.
In addition to these, several other math alphabets are available in various packages. Note that the command \mathbf
produces only roman boldface and not math italic boldface. Sometimes you may need boldface math
italic, for example to typeset vectors. For this, amsmath provides the \boldsymbol
command. Thus we can get
In this case, we define
from the input
If the document contains several occurrences of such symbols, it is better to make a new definition such as
and then use $\vect{a}$
to produce a and
to produce b and so on. the additional advantage of this approach is that if you change your mind later and
want vectors to be typeset with arrows above them as \vec{a}
, then all you need is to change the \boldsymol
part of the definition of \vect
to \overrightarrow
and the change will be effected throughout the document.
Now if we change the input of the above example as
In this case, we define
then we get the output
Note
that
now
the
symbols
and
are
also
in
boldface
.
Thus \boldsymbol
makes
bold
every
math
symbol
in
its
scope.
Recently, the International Standards Organization (ISO) has established the recognised typesetting standards in mathematics. Some of the points in it are,
-
Simple variables are represented by italic letters as a, x.
-
Vectors are written in boldface italic as a, x.
-
Matrices may appear in sans serif as in A, X.
-
The special numbers e, i and the differential operator d are written in upright roman.
The first point is the default in LaTeX and we have seen how the second point can be implemented. To fulfil the last point, it is enough if we define something like:
and then use \mathrm{e}
for e and \mathrm{i}
for i and \mathrm{diff}x
for
.
Third point can be implemented using \mathsf
but it is a bit difficult if we need them to be in
\mathsfs1
by the command in the preamble.
and use it to define a command \matr
to typeset matrices in this font by:
so that $\matr A$
produces A. We end this chapter with a list of common list of symbols in LaTeX. This
is by no means an exhaustive list as the list can be extended either by the user of by use of packages.
Symbol | Command | Symbol | Command | Symbol | Command |
\leq
|
\exists
|
\forall
|
|||
\geq
|
\in
|
\square
|
|||
\neq
|
\subset
|
\angle
|
|||
\nleq
|
\subseteq
|
\Theta
|
|||
\ngeq
|
\varnothing
|
\Pi
|
|||
\cong
|
\cap
|
\Gamma
|
|||
\equiv
|
\cup
|
\Delta
|
|||
\sim
|
\setminus
|
\Omega
|
|||
\approx
|
\wedge
|
\Sigma
|
|||
\doteqdot
|
\vee
|
\alpha
|
|||
\times
|
\Rightarrow
|
\beta
|
|||
\cdot
|
\rightarrow
|
\epsilon
|
|||
\ast
|
\mapsto
|
\zeta
|
|||
\div
|
$ | \$
|
\eta
|
||
\pm
|
& | \&
|
\kappa
|
||
\mp
|
% | \%
|
\lambda
|
||
\bigcirc
|
\backslash
|
\mu
|
|||
\oplus
|
\sharp
|
\xi
|
|||
\otimes
|
\partial
|
\rho
|
|||
\propto
|
90^\circ
|
\tau
|
|||
\cdots
|
\parallel
|
\phi
|
|||
\dots
|
\bot
|
\psi
|
|||
\because
|
\triangle
|
\pi
|
|||
\therefore
|
\nabla
|
\theta
|
|||
\delta
|
\gamma
|
\omega
|
|||
\sigma
|
\infty
|
f\;$\prime$
|
|||
\int
|
\oint
|
\mathbb{Z}
|
|||
\mathbb{R}
|
\mathbb{Q}
|
\sqrt[3]{2}
|
|||
\frac{2}{3}
|
\lceil x \rceil
|
\lfloor x \rfloor
|