mathaddons.com


math expressions
made easy


Many outstanding resources for TEX and LATEX exist. However, many of these resources are much more comprehensive than what is actually necessary for most users to get started. Consequently, potential new users are often turned away by the justifiable perception of a very steep learning curve.

That is not the approach of this guide. We feel TEX's math capabilities are actually rather intuitive and can and should be used by anyone having a need to create math content.

Rather than attempt to be thorough, this guide is instead going to attempt to get a complete TEX novice up and running with TEX's math syntax relatively quickly by just explaining a few key concepts. This way, users can learn how to make many types of base constructs quickly, and anything else the user needs could be done on an as-needed basis by consulting other resources.

TEX's most significant symbols: \ and { }
The backslash character tells TEX something special is about to happen. Generally, this falls into two categories: some sort of new environment (such as a fraction or radical, discussed later), or a special math character (generally those not on a standard keyboard). We discuss this latter use here.

For special characters, the user immediately follows the backslash with the corresponding TEX name (or abbreviation). While these are sometimes easy enough to guess (for example, the vast majority of Greek letters are just their name, in either lowercase of uppercase format, as desired), consulting a reference for first time use is common. Thankfully, most symbol names are sufficiently intuitive that they are easy to remember once known. For example ÷, ±, ≈, and ≠ would be \div, \pm, \approx, and \neq, respectively. One really convenient way to figure out the code you need is to simply draw it on this site. (Thanks to colleague James Cook for making me aware of this).

The curly braces group expressions together as we will see in the next few sections. Because of this special functionality, if desiring curly braces to appear in the math expression, one must use \{ and \}: the backslash denotes a special character, in this case special only because TEX is already using that symbol for something else. Note that, similarly, \% is necessary to create a visible % sign, as TEX otherwise uses % to denote code commenting (which is not particularly useful for our applications).

Fractions
The construct to create a fraction is
\frac{numerator}{denominator}
Of course, fractions can appear within fractions, and this is where the curly brace grouping makes that very simple, if desired. We will see a specific example of a fraction in our next section.

Radicals
The construct for a radical is \sqrt{radicand}. If we desire a root with a different index (say, 3 for a cube root), we use \sqrt[index]{radicand} (note the square braces on the index).

Subscripts and superscripts
A subscript (or lower limit on sums and integrals) is denoted with the underscore symbol _ . The subscript must be enclosed in curly braces unless it is just a single character (such as 0). The superscipt behaves similarly, but is denoted with the caret symbol ^ . As an example of the radical, the fraction, and the superscript (and their interaction), let us present the code for one of the most well-known mathematical expressions, the quadratic formula:

x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}



A couple of points are worth mentioning. First, spaces, as long as they do not cause ambiguity in a symbol's label, can be used however the user desires. In other words, TEX does its own thing with regard to spacing; whether spaces surrounded the \pm expression above or not, the appearance of the math expression would have been the same. Second, overuse of curly braces is also, in a sense, acceptable. For example, in the above expression, one could have instead used b^{2} and the behavior would have been exactly the same (of course, had the exponent been, say, 20 instead of 2, curly braces would have been necessary due to the presence of more than a single character).

Trigonometric, logarithmic, and other such functions
By default, when one types a letter in TEX's math mode, TEX treats it as if it is a variable, typically italicizing and spacing it accordingly. Of course, we do not generally see sin, ln, or max in italics, as they are not variables. To generate these non-italicized letters just use \sin, \ln, and \max, respectively. Other functions behave similarly.

Integrals and summations
As integrals and summations largely just combine concepts already developed, providing some examples is likely the most helpful approach possible. However, one note on the final term in the integrals is warranted. Usually in mathematical typesetting there is a small gap preceding the differential. The \, (backslash-comma) is the special "character" that generates this small space. We will start with an example using just about every construct discussed thus far, with a couple of symbols not yet mentioned.

\int_{-\infty}^\infty \frac{1}{\sqrt{2\pi\sigma^2}} e^{-\frac{(x-\mu)^2}{2\sigma^2}} \, dx=1



And a summation...

\sum_{k=0}^\infty r^k, |r| < 1



Matrices
While typing matrices by hand is fairly tedious and error prone, thankfully there is a convenient online tool that makes the process far simpler.

LaTeX Matrix Generator

The process is largely self-explanatory, with the only real challenge being knowing which type of matrix one wants (and selecting it from a dropdown menu). Essentially, each of the different types has different punctuation surrounding the matrix:

matrix: no surrounding punctuation
pmatrix: parentheses ( )
bmatrix: square brackets [ ]
Bmatrix: curly braces { }
vmatrix: vertical lines | |
Vmatrix: double vertical lines || ||

Unfortunately, augmented matrices are a somewhat more complicated beast beyond both the matrix generator and the scope of this guide, though they are certainly possible.

\left, \right, and split functions
One final construct is sufficiently common to warrant mention; plus it has an interesting secondary application. While parentheses, square brackets, and curly braces are all commonly used in math expressions to provide grouping, unlike normal text (where the size of each is constant), their sizes can vary greatly dependent on what they contain. For example, the parentheses surrounding a fraction would typically be larger than the parentheses surrounding a single line expression.

By default, TEX will use just a regular size. However, to activate TEX's automatic sizing, one simply needs to place \left and \right with the corresponding symbols. This is likely best presented with an example.

Suppose we wish to create a matrix with parentheses around it. Of course, we could just use pmatrix.

\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}




But suppose that, for some reason, we do not wish to use pmatrix (making an augmented matrix could be one such reason). If we only put "basic" parentheses around this regular (no punctuation) matrix, we get the following:

(\begin{matrix}
a & b \\
c & d
\end{matrix})




Clearly, this does not look proper. However, if we attach the \left and \right commands to their respective parentheses, TEX will automatically adjust the size of the parentheses to fit everything that is between them, in this case, the matrix.

\left(\begin{matrix}
a & b \\
c & d
\end{matrix}\right)




Clearly, this is the behavior we desire.

The \left and \right commands along with matrices can be used to create one other common type of expression: a split function. We should note that there are other, likely superior, methods for creating split functions. However, this method is sufficiently effective in most instances, and relies almost entirely on concepts already developed.

To create a split function, we will treat the part after the left curly brace as a two column matrix, the first column describing the behavior and the second column describing the relevant domain for that behavior. We will enclose this matrix in curly braces, but, of course, we actually only want one. Because \left and \right must appear in pairs, we let the left one be a curly brace and use a period for the second. The period tells TEX to just draw nothing. We conclude with a final example.

|x|=\left\{\begin{matrix}
x, & x\geq 0 \\
-x, & x<0
\end{matrix}\right.