5
Typesetting Mathematics

5.1 True Purpose of TeX

Donald Knuth created TeX for primarily typesetting Mathematics beautifully [6]. LaTeX includes all the capabilities of TeX in Mathematics typesetting, with an easier interface. Of course, LaTeX, being a full language, supports extension to the language, which is why there are many packages in CTAN.

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 in-text math, is produced by enclosing it between dollar signs $...$. Therefore if we want to produce:

The equation representing a straight line in Cartesian plane is of the form a x + b y + c = 0 , where a , b , c are constants.

we need to type:

latex
The equation representing a straight line in Cartesian plane is of the form $ax + by + c = 0$, where $a$, $b$, $c$ are constants.

Let’s see what is going on here.

First, note the text within dollars is typeset in italic . 1 1 To be a bit pedantic, it is called math italic . Again, even though we did not leave any spaces within a x + b y + c = 0 , TeX leaves spaces on either side of the addition signs ( + ) and the equality ( = ) sign.

On the other hand, even if we type $ax + by + c = 0$, the output would be the same

a x + b y + c = 0

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

latex
... where $a, b, c$ are constants.

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 a x + b y + c = 0 , where a , b , c 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,

Therefore either of the inputs shown below also produces the same output as above.

latex
The equation representing a straight line in the Cartesian plane is of the form \(ax+by+c=0\), where \(a\), \(b\), \(c\) are constants.

latex
The equation representing a straight line in the Cartesian plane is of the form \begin{math}ax+by+c=0\end{math}, where \begin{math} a \end{math}, \begin{math} b \end{math}, \begin{math} c \end{math} are constants.

Continuing on, suppose we want to display the equation 2 2 In this context, display means to put the equation in centre-stage and not inline. in the previous output as in

The equation representing a straight line in the Cartesian plane is of the form

a x + b y + c = 0

where a , b , c are constants.

This can be done by changing the input as follows:

latex
The equation representing a straight line in the Cartesian plane is of the form $$ \begin{equation} ax+by+c=0 \end{equation} $$ where $a$, $b$, $c$ are constants.

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 n > 2 , then there are no integers x , y , z for which

x n + y n = z n (5.1)

This was proved in 1994 by Andrew Wiles.

This is produced by the input

latex
In the seventeenth century, Fermat conjectured that if $n > 2$, then there are no integers $x$, $y$, $z$ for which % $$ x^n + y^n = z^n $$ % This was proved in 1994 by Andrew Wiles.

This shows that superscripts 3 3 mathematicians call them exponents are produced by the ^ 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 ( x m ) n = x m n .

we must type:

latex
It is easily seen that $(x^m)^n=x^{mn}$.

Instead of $x^{mn}$, if we type $x^mn$ we end up with x m n instead of the intended x m n in the output.

We can have superscripts of superscripts. 4 4 and mathematicians do need them for their interesting theorems and whatnot. For example let’s look at the following

Numbers of the form 2 2 n + 1 , where n is a natural number, are called Fermat numbers.

is produced by:

latex
Numbers of the form $2^{2^n}+1$, where $n$ is a natural number, are called Fermat numbers.

Please observe that we have grouped the superscript.

Now let us see how subscripts 5 5 a character (letter, number, or symbol) that is printed or written below the normal line of text, often slightly smaller than the surrounding text. are produced.

To get the following output:

The sequence ( x n ) defined by

x 1 = 1 , x 2 = 1 , x n = x n 1 + x n 2 ( n > 2 )

is called the Fibonacci sequence.

we need to type:

latex
The sequence $(x_n)$ defined by $$ x_1=1,\quad x_2=1,\quad x_n=x_{n-1}+x_{n-2}\;\;(n>2) $$ is called the Fibonacci sequence.

We can see, subscripts are produced by the _ character. Note how we insert spaces by the \quad command. 6 6 The 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 ( x n ) converges to a , then the sequence ( x n 2 ) converges to a 2

is produced by

latex
If the sequence $(x_n)$ converges to $a$, then the sequence $(x_n^2)$ converges to $a^2$

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:

latex
$$ x_m^n\qquad x^n_m\qquad {x_m}^n\qquad {x^n}_m $$

x m n x m n x m n x n m

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 x m n can be taught as x m n , whereas the box for x n m can be visualised as x m n

5.2.2 Roots

To put it simply, square-roots are produced by the \sqrt argument. Therefore $\sqrt{2}$ produces 2 . This command has an optional argument to produce other roots. As an example:

Which is greater 5 4 or 4 5 ?

is produced by

latex
Which is greater $\sqrt[4]{5}$ or $\sqrt[5]{4}$?

The horizontal line above the root 7 7 called vinculum by mathematicians who like to think they are better than engineers. elongates to accommodate the enclosed text. For example, $\sqrt{x+y}$ produces x + y . Also, you can produce nested roots as in

The sequence

2 2 , 2 2 2 2 , 2 3 2 2 + 2 , 2 4 2 2 + 2 + 2 + 2 ,

converge to π .

by typing

latex
The sequence $$ 2\sqrt{2}\,,\quad 2^2\sqrt{2-\sqrt{2}}\,,\quad 2^3 \sqrt{2-\sqrt{2+\sqrt{2}}}\,,\quad 2^4\sqrt{2- \sqrt{2+\sqrt{2+\sqrt{2+\sqrt{2}}}}}\,,\;\ldots $$ converge to $\pi$.

The \ldots command above produces …, the three dots indicating indefinite continuation, called ellipsis (more about them later). The command \, produces a “thinspace” 8 8 as opposed to a thickspace produced by \;, 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. 9 9 an operator that operates on two operands. An operand is a value or a variable on which an operator performs an operation. The term “binary” indicates that these operators specifically take two operands. For example, consider the following

For real numbers x and y , define an operation by

x y = x + y x y

This operation is associative.

latex
For real numbers $x$ and $y$, define an operation $\circ$ by $$ x\circ y = x+y-xy $$ 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 x and y , define an operation by

x y = x 2 + y 2

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:

latex
For real numbers $x$ and $y$, define an operation $\Box$ by $$ x\Box y = x^2+y^2 $$

you will only get

For real numbers x and y , define an operation by

x y = x 2 + y 2

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:

latex
For real numbers $x$ and $y$, define an operation $\Box$ by $$ x\mathbin\Box y=x^2+y^2 $$

For real numbers x and y , define an operation by

x y = x 2 + y 2

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 x ρ y iff x y is a rational number.

by typing

latex
Define the relation $\rho$ on the set of real numbers by $x\mathrel\rho y$ iff $x-y$ is a rational number.

5.3 Custom Commands

We have seen that LaTeX produces mathematics 10 10 along with other stuff by means of “commands”. The interesting thing is that we can build our own commands using the ones available.

For example, suppose that the following expression ( x 1 , x 2 , , x n ) occurs too frequently in a document. If we now write:

latex
\newcommand{\vect}{(x_1,x_2,\dots,x_n)}

Then we can type $\vect$ anywhere after wards to produce ( x 1 , x 2 , , x n ) as in

latex
We often write $x$ to denote the vector $\vect$.

to get

We often write x to denote the vector ( x 1 , x 2 , , x n ) .

The best place to keep such “newcommands” is the preamble, 11 11 The place before \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 ( x 1 , x 2 , , x n ) with $\vect$ vects, but how about ( y 1 , y 2 , , y n ) or ( z 1 , z 2 , , z n ) ? Do we have to define new commands for each of these? No, as we can also define commands with variable arguments as well. Therefore, if we change our definition of \vect to:

latex
\newcommand{\vect}[1]{(#1_1,#1_2,\dots,#1_n)}

Then we can use $\vect{x}$ to produce ( x 1 , x 2 , , x n ) and $\vect{x}$ to produce ( a 1 , a 2 , , a n ) 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) (variable) argument. What about the ##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. 12 12 the maximum number is 9. Therefore, for example, if the document contains not only ( x 1 , x 2 , , x n ) , ( y 1 , y 2 , , y n ) and so on, but ( x 1 , x 2 , , x m ) , ( y 1 , y 2 , , y p ) also, then we can change our definition of \vect to

latex
\newcommand{\vect}[2]{(#1_1,#1_2,\dotsc,#1_#2)}

so that we can use $\vect{x}{n}$ to produce ( x 1 , x 2 , , x n ) and $\vect{y}{p}$ to produce ( y 1 , y 2 , , y p ) .

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

a x + b y + c = 0

where a , b , c are constants.

can also be produced by

latex
The equation representing a straight line in the Cartesian plane is of the form \begin{equation*} ax+by+c=0 \end{equation*} where $a$, $b$, $c$ are constants.

Why the * after equation? Suppose we try it without the * as:

latex
The equation representing a straight line in the Cartesian plane is of the form \begin{equation} ax+by+c=0 \end{equation} where $a$, $b$, $c$ are constants.

we get:

The equation representing a straight line in the Cartesian plane is of the form

a x + b y + c = 0 (5.2)

where a , b , c are constants.

This provides the equation with a number . We will discuss equation numbering in some more detail later on. For the time being, we just note that for any environment name with a star we discuss here, the unstarred version provides the output with numbers.

Ordinary text can be inserted inside an equation using the \text command. Therefore we can get:

Thus for all real numbers x we have

x | x | and x | x |

and so

x | x | for all x in R .

from:

latex
Thus for all real numbers $x$ we have \begin{equation*} x\le|x|\quad\text{and}\quad x\ge|x| \end{equation*} and so \begin{equation*} x\le|x|\quad\text{for all $x$ in $R$}. \end{equation*}

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. 13 13 or sometimes even two lines. Look at the one below:

( a + b + c + d + e ) 2 = a 2 + b 2 + c 2 + d 2 + e 2 + 2 a b + 2 a c + 2 a d + 2 a e + 2 b c + 2 b d + 2 b e + 2 c d + 2 c e + 2 d e

This is produced by the environment multline*, 14 14 Note the spelling carefully. It is NOT multiline. as shown below.

latex
\begin{multline*} (a+b+c+d+e)^2=a^2+b^2+c^2+d^2+e^2\\ +2ab+2ac+2ad+2ae+2bc+2bd+2be+2cd+2ce+2de \end{multline*}

multline can be used for equations requiring more than two (2) lines, but without tweaking, the results are not very satisfactory. For example, the input:

latex
\begin{multline*} (a+b+c+d+e+f)^2=a^2+b^2+c^2+d^2+e^2+f^2\\ +2ab+2ac+2ad+2ae+2af\\ +2bc+2bd+2be+2bf\\ +2cd+2ce+2cf\\ +2de+2df\\ +2ef \end{multline*}

which produces:

( a + b + c + d + e + f ) 2 = a 2 + b 2 + c 2 + d 2 + e 2 + f 2 + 2 a b + 2 a c + 2 a d + 2 a e + 2 a f + 2 b c + 2 b d + 2 b e + 2 b f + 2 c d + 2 c e + 2 c f + 2 d e + 2 d f + 2 e f

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.

( a + b + c + d + e + f ) 2 = a 2 + b 2 + c 2 + d 2 + e 2 + f 2 + 2 a b + 2 a c + 2 a d + 2 a e + 2 a f + 2 b c + 2 b d + 2 b e + 2 b f + 2 c d + 2 c e + 2 c f + 2 d e + 2 d f + 2 e f

This is done using the split environment as shown below.

latex
\begin{equation*} \begin{split} (a+b+c+d+e+f)^2 & = a^2+b^2+c^2+d^2+e^2+f^2\\ &\quad +2ab+2ac+2ad+2ae+2af\\ &\quad +2bc+2bd+2be+2bf\\ &\quad +2cd+2ce+2cf\\ &\quad +2de+2df\\ &\quad +2ef \end{split} \end{equation*}

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

( a + b ) 2 = ( a + b ) ( a + b ) = a 2 + a b + b a + b 2 = a 2 + 2 a b + b 2

which is produced by

latex
\begin{equation*} \begin{split} (a+b)^2 & = (a+b)(a+b)\\ & = a^2+ab+ba+b^2\\ & = a^2+2ab+b^2 \end{split} \end{equation*}

5.4.2 Groups of Equations

A group of displayed equations can be typeset in a single go using the gather environment. For example,

( a , b ) + ( c , d ) = ( a + c , b + d ) ( a , b ) ( c , d ) = ( a c b d , a d + b c )

can be produced by

latex
\begin{gather*} (a,b)+(c,d)=(a+c,b+d)\\ (a,b)(c,d)=(ac-bd,ad+bc) \end{gather*}

Now when several equations are to be considered one unit, the logically correct way of typesetting them is with some alignment. For example,

Thus x , y and z satisfy the equations

x + y z = 1 x y + z = 1

This is obtained by using the align* environment as shown below

latex
Thus $x$, $y$ and $z$ satisfy the equations \begin{align*} x+y-z & = 1\\ x-y+z & = 1 \end{align*}

We can add a short piece of text between the equations, without disturbing the alignment, using the \intertext command. For example, the output

Thus x , y and z satisfy the equations

x + y z = 1 x y + z = 1 and by hypothesis x + y + z = 1

latex
Thus $x$, $y$ and $z$ satisfy the equations \begin{align*} x+y-z & = 1\\ x-y+z & = 1\\ \intertext{and by hypothesis} x+y+z & =1 \end{align*}

We can also set multiple columns of aligned equations side by side as in:

Compare the following sets of equations

cos 2 x + sin 2 x = 1 cosh 2 x sinh 2 x = 1 cos 2 x sin 2 x = cos 2 x cosh 2 x + sinh 2 x = cosh 2 x

All that it needs are extra & ’s to separate the columns as can be sen from the input Compare the following sets of equations

latex
Compare the following sets of equations \begin{align*} \cos^2x+\sin^2x & = 1 & \cosh^2x-\sinh^2x & = 1\\ \cos^2x-\sin^2x & = \cos 2x & \cosh^2x+\sinh^2x & = \cosh 2x \end{align*}

We can also adjust the horizontal space between the equation columns. For example, Compare the sets of equations

latex
Compare the sets of equations \begin{align*} \cos^2x+\sin^2x & = 1 &\qquad \cosh^2x-\sinh^2x & = 1\\ \cos^2x-\sin^2x & = \cos 2x &\qquad \cosh^2x+\sinh^2x & = \cosh 2x \end{align*}

gives

Compare the sets of equations

cos 2 x + sin 2 x = 1 cosh 2 x sinh 2 x = 1 cos 2 x sin 2 x = cos 2 x cosh 2 x + sinh 2 x = cosh 2 x

Perhaps a nicer way of typesetting the above is

Compare the following sets of equations

cos 2 x + s i n 2 x = 1 cos 2 x sin 2 x = cos 2 x and cosh 2 x sinh 2 x = 1 cosh 2 x + sinh 2 x = cosh 2 x

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 actual width of the contents for their display. Thus the above example is produced by the input

latex
Compare the following sets of equations \begin{equation*} \begin{aligned} \cos^2x+sin^2x & = 1\\ \cos^2x-\sin^2x & = \cos 2x \end{aligned} \qquad\text{and}\qquad \begin{aligned} \cosh^2x-\sinh^2x & = 1\\ \cosh^2x+\sinh^2x & = \cosh 2x \end{aligned} \end{equation*}

Another often recurring structure in mathematics is a display like this

| x | = { x if x 0 x if x 0

There is a special environment cases in amsmath to take care of these. The above example is in fact produced by

latex
\begin{equation*} |x| = \begin{cases} x & \text{if $x\ge 0$}\\ -x & \text{if $x\le 0$} \end{cases} \end{equation*}

5.4.3 Numbered Equations

We have mentioned that each of the the starred equation environments has a corresponding unstarred version, which also produces numbers for their displays. Therefore our very first example of displayed equations with equation instead of equation* as in

latex
The equation representing a straight line in the Cartesian plane is of the form \begin{equation} ax+by+c=0 \end{equation} where $a$, $b$, $c$ are constants.

produces

The equation representing a straight line in the Cartesian plane is of the form

a x + b y + c = 0 (5.3)

where a , b , c 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

latex
\numberwithin{equation}{section}

We can also override the number L’IFX produces with one of our own design with the \tag command as in

latex
The equation representing a straight line in the Cartesian plane is of the form \begin{equation} ax+by+c=0\tag{L} \end{equation} where $a$, $b$, $c$ are constants.

which gives

The equation representing a straight line in the Cartesian plane is of the form

a x + b y + c = 0 (L)

where a , b , c 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,

latex
\begin{align} x+y-z & = 1\\ x-y+z & = 1 \end{align}

gives:

x + y z = 1 (5.4) x y + z = 1 (5.5)

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:

latex
Thus $x$, $y$ and $z$ satisfy the equations \begin{align*} x+y-z & = 1\ntag\\ x-y+z & = 1\notag\\ \intertext{and by hypothesis} x+y+z & =1\tag{H} \end{align*}

which gives the following output

Thus x , y and z satisfy the equations

x + y z = 1 x y + z = 1 and by hypothesis x + y + z = 1 (H)

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

latex
\begin{equation} \begin{split} (a+b)^2 & = (a+b)(a+b)\\ & = a^2+ab+ba+b^2\\ & = a^2+2ab+b^2 \end{split} \end{equation}

( a + b ) 2 = ( a + b ) ( a + b ) = a 2 + a b + b a + b 2 = a 2 + 2 a b + b 2 (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

x + y z = 1 x y + z = 1 x + y + z = 1

can be written in matrix terms as

( 1 1 1 1 1 1 1 1 1 ) ( x y z ) = ( 1 1 1 ) .

Here, the matrix ( 1 1 1 1 1 1 1 1 1 ) is invertible.

latex
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 ( a b c d ) while others prefer square brackets as in [ a b c d ]

is produced by

latex
Some mathematicians write matrices within parentheses as in $ \begin{pmatrix} a & b\\ c&d \end{pmatrix} $ while others prefer square brackets as in $ \begin{bmatrix} a & b\\ c&d \end{bmatrix} $

Some mathematicians write matrices within parentheses as in

There is also a vmatrix environment, which is usually used for determinants as in

The determinant | a b c d | is defined by

| a b c d | = a d b c

which is obtained from the input

latex
The determinant $ \begin{vmatrix} a & b\\ c & d \end{vmatrix} $ is defined by \begin{equation*} \begin{vmatrix} a & b\\ c & d \end{vmatrix} =ad -bc \end{equation*}

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 m × n matrix is of the form

( a 1 1 a 1 2 a 1 n a 2 1 a 2 2 a 2 n . . . . . . . . . . . . . . . . . . . . . a m 1 a m 2 a m n )

we type

latex
A general $m\times n$ matrix is of the form \begin{equation*} \begin{pmatrix} a_{11} & a_{12} & \dots & a_{1n}\\ a_{21} & a_{22} & \dots & a_{2n}\\ \hdotsfor{4}\\ a_{m1} & a_{m2} & \dots & a_{mn} \end{pmatrix} \end{equation*}

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 (3) dots. This can be used in other contexts also. For example,

latex
Consider a finite sequence $X_1,X_2,\dots$, its sum $X_1+X_2+\dots$ and product $X_1X_2\dots$.

gives

Consider a finite sequence X 1 , X 2 , , its sum X 1 + X 2 + and product X 1 X 2 .

Here the dots in all the three (3) contexts are along the “baseline” of the text. Isn’t it better to typeset this as

Consider a finite sequence X 1 , X 2 , , its sum X 1 + X 2 + and product X 1 X 2 .

with raised dots for addition and multiplication?

The above text is typeset by the input

latex
Consider a finite sequence $X_1,X_2,\dotsc$, its sum $X_1+X_2+\cdotb$ and product $X_1X_2\dotsm$.

Here:

There is also a \dotsi for dots with integrals as in

A 1 A 2 A n f

5.5.3 Delimiters

How do we produce something like

| a h g h b f g f c | = 0 , the matrix ( a h g h b f g f c ) is not invertible.

Here the small in-text matrices are produced by the environment smallmatrix. This environment does NOT provide the enclosing delimiters , which we must supply as in

latex
$ \left|\begin{smallmatrix} a & h & g\\ h & b & f\\ g&f&c \end{smallmatrix}\right| =0 $, the matrix $ \left(\begin{smallmatrix} a & h & g\\ h & b & f\\ g&f&c \end{smallmatrix}\right) $ is not invertible.

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,

u x = v y u y = v x } Cauchy-Riemann Equations

is produced by

latex
\begin{equation*} \left. \begin{aligned} u_x & = v_y\\ u_y & = -v_x \end{aligned} \right\} \quad\text{Cauchy-Riemann Equations} \end{equation*}

There are instances where the delimiters produced by \left and \right are too small or too large. For example,

latex
\begin{equation*} (x+y)^2-(x-y)^2=\left((x+y)+(x-y)\right)\left((x+y)-(x-y)\right)=4xy \end{equation*}

gives

( x + y ) 2 ( x y ) 2 = ( ( x + y ) + ( x y ) ) ( ( x + y ) ( x y ) ) = 4 x y

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

( x + y ) 2 ( x y ) 2 = ( ( x + y ) + ( x y ) ) ( ( x + y ) ( x y ) ) = 4 x y

This is produced using the commands \bigl and \bigr before the outer parentheses as shown below:

latex
\begin{equation*} (x+y)^2-(x-y)^2=\bigl((x+y)+(x-y)\bigr)\bigl((x+y)-(x-y)\bigr)=4xy \end{equation*}

This is produced using the commands \bigl and \bigr before the outer parentheses as shown below:

( x + y ) 2 ( x y ) 2 = ( ( x + y ) + ( x y ) ) ( ( x + y ) ( x y ) ) = 4 x y

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 n -tuples of complex numbers ( x 1 , x 2 , , x n ) and ( y 1 , y 2 , , y n ) of complex numbers

( k = 1 n | x k y k | ) 2 ( k = 1 n | x k | ) ( k = 1 n | y k | )

which is produced by:

latex
For $n$-tuples of complex numbers $(x_1,x_2,\dotsc,x_n)$ and $(y_1,y_2,\dotsc,y_n)$ of complex numbers \begin{equation*} \left(\sum_{k=1}^n|x_ky_k|\right)^2\le \left(\sum_{k=1}^{n}|x_k|\right)\left(\sum_{k=1}^{n}|y_k|\right) \end{equation*}

Does not the output below look better?

For n -tuples of complex numbers ( x 1 , x 2 , , x n ) and ( y 1 , y 2 , , y n ) of complex numbers

( k = 1 n | x k y k | ) 2 ( k = 1 n | x k | ) ( k = 1 n | y k | )

This one is produced by

latex
For $n$-tuples of complex numbers $(x_1,x_2,\dotsc,x_n)$ and $(y_1,y_2,\dotsc,y_n)$ of complex numbers \begin{equation*} \biggl(\sum_{k=1}^n|x_ky_k|\biggr)^2\le \biggl(\sum_{k=1}^{n}|x_k|\biggr)\biggl(\sum_{k=1}^{n}|y_k|\biggr) \end{equation*}

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 n is an even number, then

1 n 1 1 2 + n 2 1 2 2 n n 1 1 2 n 1 = 0

We have fractions like 1 2 n 1 and binomial coefficients like n 2 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 (2) arguments, the numerator followed by the denominator and the binomial coefficients are produced by the \binom command which also takes two arguments, the “top” expression followed by the “bottom” one. Thus the the input for the above example is

latex
From the binomial theorem, it easily follows that if $n$ is an even number, then \begin{equation*} 1-\binom{n}{1}\frac{1}{2}+\binom{n}{2}\frac{1}{2^2}-\dotsb -\binom{n}{n-1}\frac{1}{2^{n-1}}=0 \end{equation*}

You can see from the first paragraph above that the size of the outputs of \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 ( x n ) converges to 0 , there exists a positive integer p such that

| x n | < 1 2 for all n p

The second output is produced by the input:

latex
Since $(x_n)$ converges to $0$, there exists a positive integer $p$ such that \begin{equation*} |x_n|<\tfrac{1}{2}\quad\text{for all $n\ge p$} \end{equation*}

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 1 2 n 1 and ...

by the input

latex
We have fractions like $\dfrac{1}{2^{n-1}}$ and ...

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 (6) things:

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 i j k of the second kind is related to the Christoffel symbol i j k of the first kind by the equation

i j k = g k 1 i j 1 + g k 2 i j 2

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:

latex
\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

4 π = 1 + 1 2 2 + 3 2 2 + 5 2 2 +

latex
\begin{equation*} \frac{4}{\pi}=1+\cfrac{1^2}{2+ \cfrac{3^2}{2+ \cfrac{5^2}{2+\dotsb}}} \end{equation*}

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 a or a ?

The commands \overset and \underset come to the rescue. Thus $\overset{\circ}{a}$ produces a and $\underset{\circ}{a}$ produces a .

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

0 A f B g C 0

which is generated from:

latex
Thus we see that \begin{equation*} 0\xrightarrow{} A\xrightarrow{f} B\xrightarrow{g} C\xrightarrow{} 0 \end{equation*}

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

latex
Thus we get \begin{equation*} 0\xrightarrow{} A\xrightarrow[\text{monic}]{f} B\xrightarrow[\text{epi}]{g} C\xrightarrow{} 0 \end{equation*}

gives:

Thus we get

0 A monic f B epi g C 0

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:

latex
Thus we get \begin{equation*} 0\xrightarrow{} A\xrightarrow[\text{monic}]{f} B\xrightarrow[\hspace{7pt}\text{epi}\hspace{7pt}]{g} C\xrightarrow{}0 \end{equation*}

which produces:

Thus we get

0 A monic f B epi g C 0

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 limits to such large operators as sum ( Σ ), product ( Π ) set union ( ), set intersection ( ) and so on. The limits are input as subscripts or superscripts, but their positioning in the output is different in text and display. For example, the input

latex
Euler not only proved that the series $\sum_{n=1}^\infty\frac{1}{n^2}$ converges, but also that \begin{equation*} \sum_{n=1}^\infty\frac{1}{n^2}=\frac{\pi^2}{6} \end{equation*}

gives the output:

Euler not only proved that the series n = 1 1 n 2 converges, but also that

n = 1 1 n 2 = π 2 6

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

latex
$\sum_{n=1}^\infty\frac{1}{n^2}$

to

latex
$\displaystyle\sum_{n=1}^\infty\frac{1}{n^2}$

and we will get:

Euler not only proved that the series n = 1 1 n 2 converges, but also that

n = 1 1 n 2 = π 2 6

(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 n = 1 1 n 2 converges, but also that

n = 1 1 n 2 = π 2 6

On the other hand, if you want side-set limits in display type \nolimits after the \sum within the equation as in

latex
Euler not only proved that the series $\sum_{n=1}^\infty\frac{1}{n^2}$ converges, but also that \begin{equation*} \sum\nolimits_{n=1}^\infty\frac{1}{n^2}=\frac{\pi^2}{6} \end{equation*}

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 lim x 0 x sin x x d x = π 2 and so by definition,

0 sin x x d x = π 2

which is produced by:

latex
Thus $\lim\limits_{x\to\infty}\int_0^x\frac{\sin x}{x}\,\mathrm{d}x =\frac{\pi}{2}$ and so by definition, \begin{equation*} \int_0^\infty\frac{\sin x}{x}\,\mathrm{d}x=\frac{\pi}{2} \end{equation*}

5.6 New Operators

Mathematical text is usually typeset in italics , and TeX follows this tradition. But certain functions in mathematics such as log , sin , lim and so on are traditionally typeset in roman. This is implemented in TeX by the use of commands like $\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

latex
\DeclareMathOperator{\cl}{cl}

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

a + b = c

from the input

latex
In this case, we define \begin{equation*} \boldsymbol{a}+\boldsymbol{b}=\boldsymbol{c} \end{equation*}

If the document contains several occurrences of such symbols, it is better to make a new definition such as

latex
\newcommand{\vect}[1]{\boldsymbol{#1}}

and then use $\vect{a}$ to produce a and a 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

a + b = c

then we get the output

latex
In this case, we define \begin{equation*} \boldsymbol{a+b=c} \end{equation*}

Note that now the symbols + and = are also in boldface . Thus \boldsymbol makes bold every math symbol in its scope. 15 15 provided the bold version of that symbol is available in the current math font There is another reason for tweaking the math fonts.

Recently, the International Standards Organization (ISO) has established the recognised typesetting standards in mathematics. Some of the points in it are,

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:

latex
\newcommand{\me}{\mathrm{e}} \newcommand{\mi}{\mathrm{i}} \newcommand{\diff}{\mathrm{d}}

and then use \mathrm{e} for e and \mathrm{i} for i and \mathrm{diff}x for d x . Third point can be implemented using \mathsf but it is a bit difficult if we need them to be in italic also. The solution is to create a new math alphabet, say, \mathsfs1 by the command in the preamble.

latex
\DeclareMathAlphabet{\mathsfsl}{OT1}{cmss}{m}{sl}

and use it to define a command \matr to typeset matrices in this font by:

latex
\newcommand{\matr}[1]{\ensuremath{\mathsfsl{#1}}}

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 9 0 90^\circ τ \tau
\cdots \parallel ϕ \phi
\dots \bot ψ \psi
\because \triangle π \pi
\therefore \nabla 𝜃 \theta
δ \delta γ \gamma ω \omega
σ \sigma \infty f f\;$\prime$
\int \oint \mathbb{Z}
\mathbb{R} \mathbb{Q} 2 3 \sqrt[3]{2}
2 3 \frac{2}{3} x \lceil x \rceil x \lfloor x \rfloor