## LaTeX: Typesetting Mathematics in LaTeX

Mathematics is just another one very good reason why students, researchers and scientists never think twice before using LaTeX. It will not be before a couple of years that word editors will be able to generate mathemtical forumlas, graphs and charts that are as easily managed as they are in LaTeX.

## Mathematics Environment

Because typesetting mathematics could be the most powerful aspect of LaTeX, mathematical context should be embedded within \begin{math} and \end{math} but any text within these will allow you no spaces, line breaks or empty lines unless they are derived logically from the mathematical expression or escaped using some special command like \, or \quad but still your text will appear in italics.

## Symbols

The most frequently refered to topic in typesetting mathematics is using special characters and symbols. In LaTeX, there's a command for each and every symbol that you could ever need. No need to memorize them, you get used to them by time and for reference there's a complete section in the Not So Short Introduction to LaTeX 2e, section 3.10. Try to notice throughout the tutorial, how LaTeX commands are plugged into the script to typeset your favourite symbols. Here's a very simple example:

\begin{displaymath} \textrm{and then the area } =\pi \cdot r^2 \qquad \forall r\in\mathbf{R} \land r\geq0 \end{displaymath}

## Grouping

Maybe have already figured out what's grouping in math mode, like it was done in the square root example on the previous page. Grouping is the same as you did with parentheses in primary school, except that it's done with the curly braces { } instead. In the example below we are interested in the square root of the whole (a+b) so we use the { }, avoiding to have the square root of a and then adding it to b.

$\sqrt{a+b} \neq \sqrt a+b$

## Self explanatory example

Sample of typesetting mathematics, the most important to notice are fractions, limits, exponents, logarithmic functions, squareroots and trignonmetric functions.

$\lim_{x \rightarrow 0} \frac{\sin x}{x} = \lim_{x \rightarrow 0} \frac{e^x-1}{x} = \lim_{x \rightarrow 0} \frac{\ln(1+x)}{x} = \lim_{n \rightarrow \infty} \sqrt[n]{n} = 1$

## Basic Mathematics

The most usefult in the example below are the underbrace (and equivalently you can use \overbrace) and the stackrel which enables you to stack a number of relations to express your mathematical forumla. Note that the code tabbing is only for clarity and readability but not by any means obligatory.

${\sigma}_1 = {\Big( (\underbrace{1 + 3 + 5 + \ldots + 27}_{196}) \cdot (\overline{\lambda + \Omega}) \Big)}^2 \stackrel{!}{\equiv}a\bmod b$

## Differentiation and Integration

$f'(x)= 4x^{(4-1)}+ \frac{d(x^2)}{dx}\cos(x^2) - \frac{d(\ln x)}{dx}e^x - \ln x\frac{d(e^x)}{dx} + 0$

$f(x)= \int f'(x) = x^4 + \sin(x^2) - \ln(x)e^x + 7$

## Summations

$\sum_{i=0}^{n}i^p = \frac{(n+1)^{p+1}}{p+1} + \sum_{k=1}^{p}\frac{B_k}{p-k+1}\cdot{}^{p}C_k\cdot(n+1)^{p-k+1}$

## Vectors

$\vec R = \overrightarrow{OA} + \overrightarrow{AB} = \overleftarrow{BO}$

## Trignometric Functions

$\tan \frac{A}{2} = \pm \sqrt{\frac{1-\cos A}{1+\cos A}} = \frac{\sin A}{1+\cos A} = \frac{1-\cos A}{\sin A} = \frac{1}{\cot \frac{A}{2}}$

$f(x)= \int f'(x) = x^4 + \sin(x^2) - \ln(x)e^x + 7$

## Linear Algebra

$\mathbf{X} = \left( \begin{array}{ccc} \sin x & \tanh \theta & \beta \\ -1 & 2x+3y & 1 \end{array} \right) \left( \begin{array}{cc} 3 & \arccos \gamma \\ 2 & 1 \\ 1 & 0 \end{array} \right) =\left( \begin{array}{cc} 5 & 1 \\ 4 & \log_{2}8 \end{array} \right)$

## Multivalued Functions

$f(x) = \left\{ \begin{array}{ll} \sin x & 0 < x < \frac{\pi}{2} \\ \cos x & \frac{\pi}{2} \leq x \leq \pi \\ undefined & otherwise \end{array} \right.$

## Wrapping up

Attention! This tutorial is only the tip of the iceberg of LaTeX mathematical capabilities. If you are an advanced mathematician or physicist you are highly recommended to checkout the AMS (American Mathematical Society) extension to LaTeX. It should be normally provided with your TeX distribution.

## Conclusion

Typesetting basic mathematics in LaTeX is as easy as typesetting normal text. On contrary to your old editor, you can express any mathematical context whatsoever on LaTeX. This tutorial has taken a more "show me how" approach via examples, so it is better for you to check the output you are looking for from within the examples and then check its code. In some cases, guessing could be better than anything else. For example, if you like the \underbrace but only wish you could have it over the text instead, that's it try out \overbrace, or if \omega gives you a lower letter for the greek omega, why not try \Omega ? Pretty predictable, isn't it ?

For your own convenience here is the math.tex and math.pdf.

## Coming up next

The next tutorial, will take you through the basics of bibTeX which helps in formatting the documents in a way simple enough for citations, reordering and referencing. A lot of the nice features of bibTeX will be discussed thoroughly in the next tutorial.