Abstract
In some of the quizzes and exams for this course, you will be typing mathematics. I will expect your mathematics to be both correct and readable. You have a couple of options. One is to use the “equation editor” built in to the quiz tool, which is similar to the equation editor you may have used in most ordinary word processing software.
Another is to type your mathematics in TeX notation. Because this is a plain-text format, it may be faster to work with than the fussy select-click-type-click-type… of equation editors. And if you are doing a derivation or proof consisting of multiple lines of mathematics, each one just slightly changed from the one preceding, you will probably find the ability to freely copy-and-paste expressions invaluable.
TeX is a typesetting program invented, well before word processing became common-place, by pioneering computer scientist Donald Knuth. With its emphasis on high-quality output and on support for mathematics, it remains popular in the mathematical sciences despite decades of development of word processing software that is, arguably, easier to use.
Even if you have no intention, however, of running the TeX program or any of its spin-offs (LaTeX, AMS-TeX, ConTeX,etc.), the TeX notation for mathematics stands as one of the best-known and most widely supported ways to type mathematics into a plain-text file for later automated typesetting.
Mathematics may be typeset in an inline fashion by placing the mathematics between \(
and \)
. For example \(x+y\)
yields $x + y$.
Mathematics may be typeset in a display fashion inside \[
and \]
, usually set off in a separate paragraph. So, if I type
\[ x = y + 1 \]
it is rendered as
\[ x = y + 1 \]
There are some mathematical expressions that will be rendered differently in inline and display mode. For example, the expressions $\sum_{i=1}^{n} x_i$ and
\[ \sum_{i=1}^{n} x_i \]
position the summation limits differently based upon whether I surround the expressions with \(
…\}
or \[
…\]
.
Both inline and display expressions can be typed across multiple lines, but will be grouped together as necessary. I can type, for example
\[ x =
y + 1 \]
and it will render as
\[x = y + 1 \]
There are six special characters in TeX math expressions:
^
is used to indicate a superscript. For example x^2
becomes $x^2$._
is used to indicate a subscript. For example x_i
becomes $x_i$.
You might think, “Well, I can do that in HTML or in just about any rich text editor.” But consider the combination of the two, quite common in mathematics, such as x_i^2
, which renders as $x_i^2$, not as xi2.
The curly brackets {
and }
are used for grouping mathematical expressions.
Look at the difference between x_i+1
, rendering as $x_i+1$, and x_{i+1}
, rendering as $x_{i+1}$.
The %
is used to indicate that the rest of the line is a comment. For example
\[ x + y = y + x % addition is cummutative
\]
renders as
\[ x + y = y + x % addition is cummutative \]
Finally, the backslash \
indicates that characters are losing their normal “meaning” and taking on something new.
For example, the square brackets are perfectly useful characters: [1, 3, 5]
rendering as $[1 ,3, 5]$, but with a backslash in front, they introduce a line of display mode math: \[
1, 3, 5\]
rendering as \[1 ,3, 5\].
Similarly, the “normal” meaning of {
and }
is grouping as shown above. But if we want to talk about sets, we can add a backslash: \\{ x_{i,j} \\}
renders as $\{ x_{i,j} \}$.
The most common use of \
will be to introduce “commands” for math that can’t be represented with a single character. This is often done together with { }
grouping. For example, $\sqrt{n}$ is typed as \sqrt{n}
.
The arithmetic operators function much as you would expect: a * b + c / (d - e)
renders as $a * b + c / (d - e)$.
One refinement is available for division. The \frac
command typesets division in a vertical style:
\frac{a * b + c}{(d - e)}
renders as $\frac{a * b + c}{(d - e)}$.
Open this page in a separate window. Try to reproduce each of the following expressions (don’t forget to surround them in \(
and \)
):
(Use \pm
for the plus-or-minus and \sqrt{
…}
to get the square root.)
LaTeX | Renders As | meaning |
---|---|---|
x \wedge y |
$x \wedge y$ | and |
x \vee y |
$x \vee y$ | or |
\neg x |
$\neg x$ | not |
LaTeX | Renders As | meaning |
---|---|---|
x < y |
$x < y$ | less than |
x > y |
$x > y$ | greater than |
x = y |
$x = y$ | equal to |
x \neq y |
$x \neq y$ | not equal to |
x \leq y |
$x \leq y$ | less than or equal to |
x \geq y |
$x \geq y$ | greater than |
A special note about the relational operators. If you are typing math into a program designed to embed mathematics into HTML web pages, you may face a problem due to the face that “<” and “>” are reserved characters in HTML. In that case, you may find that you need to type them like this: x < y
and x > y
.
Math symbols, particularly operators, can vary considerably in height. TeX has several “resizable” operators that not only tend to be taller than most characters, they can grow and shrink depending on context.
The most common of these are summation and product:
LaTeX | Renders As | meaning |
---|---|---|
\sum_i^n x_i |
$\sum_i^n x_i$ | summation |
\prod_i^n x_i |
$\prod_i^n x_i$ | product |
When you start writing large operators and vertical fractions into longer expression, the parentheses and grouping characters can start to look a little wimpy. For example
\[ \sum_{i=0}^n (x_i + i) = (\sum_{i=0}^n x_i) + (\sum_{i=0}^n i) = (n \bar{x}) + (\frac{n(n+1)}{2}) \]
\[ \sum_{i=0}^n (x_i + i) = (\sum_{i=0}^n x_i) + (\sum_{i=0}^n i) = (n \bar{x}) + (\frac{n(n+1)}{2}) \]
The parentheses in the above example look pretty awful. What we have is mathematically correct, but it’s not pretty.
You can request resizable parentheses or brackets by putting \left
and \right
in front of them.
\[ \sum_{i=0}^n (x_i + i) = \left(\sum_{i=0}^n x_i \right) + \left(\sum_{i=0}^n i\right) = (n \bar{x}) + \left(\frac{n(n+1)}{2}\right) \]
\[ \sum_{i=0}^n (x_i + i) = \left(\sum_{i=0}^n x_i \right) + \left(\sum_{i=0}^n i\right) = (n \bar{x}) + \left(\frac{n(n+1)}{2}\right) \]
which certainly looks a lot better.
Every \left
should be followed by a \right
, though the brackets don’t have to match. \left(0, 10\right]
, rendering as $\left(0, 10\right]$, is perfectly legal.
If you want to have a left or right bracket that appears to be unmatched, you can use ‘.’ as the bracket character.
That’s how we get expressions like
\[ i(n) = \left\{ \begin{array}{ll} n/2 & \mbox{if n is even} \\
(-n-1) & \mbox{if n is odd} \\ \end{array} \right. \]
but we need a few more tricks before we can write all of that.
Let’s look at that line “n/2 if n is even” all by itself. If we do that as math:
\[ n/2 if n is even \]
we get a mess:
\[ n/2 if n is even \]
That’s because, normally, when we write characters next to one another, we mean them to represent the product of those single-character variables. Even just the word “if”, entered in math as \(if\)
, will be rendered as $if$, because TeX assumes that by “if” we really mean “$i$ multiplied by $f$”.
Even when you put spaces inside your expression, the typesetter swallows those up in order to show what it thinks you meant by that expression.
If we need to put normal text words inside mathematics, there’s a special command, \mbox
, used to indicate that something is actually text.
\[ n/2 \mbox{ if n is even} \]
\[ n/2 \mbox{ if n is even} \]
You can arrange things into array-like structures with the array
environment:
\begin{array}
and end with \end{array}
.\begin{array}
, you indicate the number of coluns you need and whether the elements in each column should be left-justified, centered, or right-justified by a list of ‘l’, ‘c’, and ‘r’ characters.\begin{array}
and end with \end{array}
, type your entries, separating entries within the same row by &
and separatign the rows with \\
.So, for example,
\[ \begin{array}{ll}
a & b \\
c & d \\
\end{array} \]
produces
\[ \begin{array}{ll} a & b \\ c & d \\ \end{array} \]
If that array looks a bit naked, we can give it some surrounding structure using the resizable bracketing we saw earlier:
\[ \left|
\begin{array}{ll}
a & b \\
c & d \\
\end{array}
\right| \]
produces
\[ \left| \begin{array}{ll} a & b \\ c & d \\ \end{array} \right| \]
and
\[ \left[
\begin{array}{ll}
a & b \\
c & d \\
\end{array}
\right] \]
produces
\[ \left[ \begin{array}{ll} a & b \\ c & d \\ \end{array} \right] \]
Returning to an earlier example
\[ \begin{array}{ll}
n/2 & \mbox{if n is even} \\
(-n-1) & \mbox{if n is odd} \\
\end{array} \]
yields
\[ \begin{array}{ll} n/2 & \mbox{if n is even} \\ (-n-1) & \mbox{if n is odd} \\ \end{array} \]
We can then put a large {
on the left and a large “nothing” on the right:
\[ left\\{ \begin{array}{ll}
n/2 & \mbox{if n is even} \\
(-n-1) & \mbox{if n is odd} \\
\end{array} \right. \]
yielding
\[ \left\{ \begin{array}{ll} n/2 & \mbox{if n is even} \\ (-n-1) & \mbox{if n is odd} \\ \end{array} \right. \]
And, finally, we can produce that full conditional expression I mentioned earlier:
\[ i(n) = \left\{ \begin{array}{ll}
n/2 & \mbox{if n is even} \\
(-n-1) & \mbox{if n is odd} \\
\end{array} \right. \]
yielding
\[ i(n) = \left\{ \begin{array}{ll} n/2 & \mbox{if n is even} \\ (-n-1) & \mbox{if n is odd} \\ \end{array} \right. \]
An ellipsis is a mark used to show that something has been omitted. The most common form of ellipsis is denoted by three periods arranged horizontally. In TeX, this is formed by \ldots
:
The natural numbers are \(0, 1, 2, \ldots\)
renders as “The natural numbers are $0, 1, 2, \ldots$”.
Within arrays, however, we can use \vdots
and \ddots
to suggest missing elements in a vertical or a diagonal (combined horizontal and vertical) direction.
\[ \left[\begin{array}{llll}
1 & 0 & \ldots & 0 \\
0 & 1 & \ldots & 0 \\
\vdots & \vdots & \ddots & \vdots \\
0 & 0 & \ldots & 1 \\
\end{array}\right] \]
renders as
\[ \left[\begin{array}{llll} 1 & 0 & \ldots & 0 \\ 0 & 1 & \ldots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \ldots & 1 \\ \end{array}\right] \]
Open this page in a separate window. Try to reproduce each of the following expressions (don’t forget to surround them in \(
and \)
):
You might want to bookmark that page for future use. It may be convenient to have a nice scratchpad handy.
During the semester, you will be entering text into Blackboard in answers to quizzes and exams and possibly in Forum postings. You have options, depending on what you need to do and how much you need to do.
You can find a discussion here.