next up previous
Next: Document Structure Up: Mathematics Previous: Mathematics

Basic Math

In general, quality typeset mathematics looks quite a bit different than plain typeset text. LATEX will take care of most of the little details--such as the amount of space to leave around a plus sign--for you. Since LATEX decides on the proper spacing, it completely ignores spaces in math mode. (If you are in math mode and want to include some regular text with regular spacing, you can use the \text command. The parameter of this command is typeset as regular text.) You can also use the ``\ '' command (backslash followed by a space) in math mode for a space that won't be ignored. And there are a few commands for adding smaller amounts of space in math mode: \, and \;.

Mathematical operators such as $ +$, $ -$, $ *$, $ /$, $ <$, $ =$, and $ >$ will behave as you expect in math mode. Set braces in math mode, as in regular text mode, must be types as \{ and \}. The Greek letters are specified by commands that are the same as the name of the letter: \alpha, \beta, \gamma, \delta, \epsilon, \theta, and \gamma will output $ \alpha$, $ \beta$, $ \gamma$, $ \delta$, $ \epsilon$, $ \theta$, and $ \gamma$, for example. Capitalized Greek letters use capitalized commands so that $ \Sigma$ and $ \Phi$ are typed as \Sigma and \Phi. There are many commands that produce special mathematical characters. A sample is shown in this table:

\le $ \le$ \ge $ \ge$ \ne $ \ne$
\to $ \to$ \cup $ \cup$ \cap $ \cap$
\in $ \in$ \subset $ \subset$ \emptyset $ \emptyset$
\wedge $ \wedge$ \vee $ \vee$ \lnot $ \lnot$
\forall $ \forall$ \exists $ \exists$ \oplus $ \oplus$
\rightarrow $ \rightarrow$ \Rightarrow $ \Rightarrow$ \therefore % latex2html id marker 745
$ \therefore$
\infty $ \infty$ \partial $ \partial$ \approx $ \approx$

Subscripts and superscripts are specified using the special characters _ and ^. These commands act like commands whose parameters are put into the subscript and superscript positions. For example, $a_{i}$ is typeset as $ a_i$, while $x^{17}$ yields $ x^{17}$. You can combine subscripts and superscripts: $x_{i}^{n}$ comes out as $ x_i^n$. (Note that you can omit the { and } around the parameter if the parameter consists of a single character. However, be aware that if you type $x^17$, you will get $ x^17$ because only the 1 is in the superscript.) Subscripts and superscripts can be complicated and can even include other levels of scripting. So, you can have $ x_{b^2+a_i^j}$, which is typed as $x_{b^2+a_i^j}$.

To take the square root of something, use \sqrt, which applies the square root sign to its parameter. For example, type $\sqrt{x^2+1}$ to get $ \sqrt{x^2+1}$. The \frac command takes two parameters and makes them into a fraction in which the first parameter is the numerator and the second is the denominator. So, $\frac{n+1}{n}$ will give $ \frac{n+1}{n}$. \frac is the first example we've encountered that looks different in display math mode. Typing $$\frac{n+1}{n}$$ will give the displayed fraction

$\displaystyle \frac{n+1}{n}$

in which the characters are much larger. In some cases, you would like to have some in-line math look like displayed math. You can get this effect by adding the \displaystyle command. So, you can get $\displaystyle \frac{n+1}{n}$ by typing $\displaystyle\frac{n+1}{n}$. Similarly, you can use \textstyle to force display mode math to be rendered in the style of in-line math.

The summation, product, and integral signs are written as \sum, \prod, and \int. Subscripts and superscripts work in a special way with these symbols to add the usual ``decorations'' at the top and bottom of the symbol. For example, $$\sum_{n=1}^{\infty}\,\frac{x^n}{n!}=e^{x}$$ is rendered as

$\displaystyle \sum_{n=1}^{\infty}\,\frac{x^n}{n!}=e^{x}$

Rendered as in-line math, this would be $ \sum_{n=1}^{\infty}\,\frac{x^n}{n!}=e^{x}$. This is one case where I definitely prefer to use display style.

The names of mathematical functions such as sin and ln should properly not be in italics. LATEX defines commands for many function names so that they can be typeset properly. So, for example, you should type \sin(x) to get $ \sin(x)$. Certain commands, such as \lim, use subscripts in the same way as the \sum command. For example, $$\lim_{x\to\infty}x^{-x}=0$$ gives

$\displaystyle \lim_{x\to\infty}e^{-x}=0$

Mathematics makes extensive use of bracketing symbols such as (, ), [, ], {, }, $ \vert$, and $ \vert$. (The $ \{$$ \}$, and $ \vert$ are typed as \{, \} and \|. You can only use | and \| in math mode.) All these symbols should change size according to the size of the stuff inside the brackets. LATEX uses the commands \left and \right to make bracketing symbols that will change size. These commands are used with bracketing symbols: \left(, \right], \left\{, \right\|. \left and \right must always occur as a pair, although the type of bracketing symbol on the left and right don't have to match. LATEX will choose the appropriate size of the brackets.3

There are many other, more sophisticated aspects of mathematical typing. Some of these are provided by LATEX environments. I give one example here. If you want to learn more, you will have to consult a reference. The array environment can be used to typeset arrays. An array environment begins with something like \begin{array}{ccc}. The ``ccc'' says that the array will have three columns and that the items of the array will be centered in each column. Replace a c with an l or an r to get left- or right-justified items. The end of the array is marked with \end{array}. In the array environment, lines of the array are separated by \\, and the items on a line are separated by &. The array is not automatically enclosed in parentheses. Use \left( and \right) to get that effect. Here is an array example:


Input Output
$ \vcenter{\halign{\strut ... $ \left(
\begin{array}{ccccc}
x_{11}& x_{12}& \cdots& x_{1n}\\
x_{21}& x_{22}& ...
...\vdots& \vdots&& \vdots\\
x_{m1}& x_{m2}& \cdots& x_{mn}\\
\end{array}\right)$

This array uses \cdots and \vdots to represent groups of three dots. These commands are treated just like other array items. The blank space in the middle of the array is an empty item. Note that in the source code this blank item is indicated by two &'s with nothing between them.


next up previous
Next: Document Structure Up: Mathematics Previous: Mathematics
David Eck 2003-10-21