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.

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.

If your document is mainly text but you need to insert some mathematical symbols from time to time, it is more convenient to leave out the \begin{math} and \end{math} and embrace your mathematical symbols with $

No need to ask, the contrary is also possible. If you are deriving a mathematical proof for example and you wish to just add a sentence, you would rather do it with the \begin{math} and \end{math} and prevent TeX from eating up your spaces and linebreaks using \textrm{...}

\section{Mathematics Basics} You can just write your normal text and then plugin some mathematical symbol like $x^2$ using the dollar signs. \newline \begin{math} x^2 = 4\textrm{ and since we're only interested in the +ve value, then }x = 2 \end{math}

You have probably noticed that the equations went right into the line, ofcourse witth a mathematics book for example you would like to get your neat equations each on a separate line and in centred fashion. If this is what you are looking for, then it should be better to use the \begin{displaymath} and \end{displaymath} instead of the normal \begin{math} or even better between \[ and \]

Solving the following quadratic equation: \[ x^2 - 5x + 6 = 0 \] \[ (x-2)(x-3)=0 \] \[ \textrm{then either }x=2 \,or\,x=3 \]

It is also rather frequent that you will need to enumarate your equations for later reference, it is quite simple and you just do it once and forget about updating the reference, it's LaTeX!

\begin{equation} \label{eq:relativity} E=mc^2 \end{equation} and given that $c = 299,792,458 m/sec$ we can substitue in Einstein's equation provided in \ref{eq:relativity} we can finally conclude our computation.

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}

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

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

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

\[ 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 \]

\[ \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} \]

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

\[ \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 \]

\[ \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) \]

\[ 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. \]

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.

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.

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.

RenewSession