Icon for parent category 'Writing'

Math Environments I

As usual, the math side of LaTeX has two major parts: environments and commands.

The environments tell LaTeX: “hey, we want to go into math mode now” They also define some crucial overall functionality and layout to use in that mode.

The commands are only used to align everything properly while in math mode. They also help gain more control over the look and fine details.

This chapter and the next are about the environments. Every math formula you’ll ever use needs to start with one of these. This first chapter explains the “core” environments. Some other environments must be inside a core one and can’t stand on their own. You’ll clearly see that happen in the examples of the next chapter.

The rest of the course is pretty much enirely about the commands. Remember they need to be placed inside a certain core environment—I won’t mention it again! If you forget it, LaTeX will often throw an undecipherable error and stop compiling.

The core math environments are: math, displaymath, equation and array.

Math

The math environment starts inline math mode. This means it’s placed in line with the regular text within the paragraph, as part of it, instead of adding a blank line and starting a new block below the text.

It can be started with one of the following three (equivalent) syntaxes:

1\(\) 
2
3$$ 
4
5\begin{math}\end{math}
1Juan fetched some $H_{2}O$, and did $a^2 + b^2 = c^2$, and created a unicorn!
Code left > output right
Code left > output right

Displaymath

The displaymath environment starts math mode on a new line. (So it is not inline, something we usually call block.) It also centres the equation. It is started with one of these (equivalent) syntaxes:

1\[\] 
2
3\begin{displaymath}\end{displaymath}
1Einstein's famous formula, \[ E = mc^2 \] has become an important cornerstone of modern physics
Code left > output right
Code left > output right

Equation

The equation environment does the same as the previous environment, but also adds the equation number in the right margin. All equations are automatically numbered by LaTeX, starting from 1. (This is a counter you can, of course, influence.)

The syntax is:

1\begin{equation}\end{equation}
1\begin{equation}
2    E = mc^2
3\end{equation} Formula 1 was one of Einstein's most important formulas.
Code left > output right
Code left > output right
Remark

The star variation, equation*, is exactly the same as the displaymath environment. It’s just what you prefer typing.

Why number equations? It allows you to use labels and references—just as with tables and figures—to easily refer back to specific equations. For this, use the \label{label} and \eqref{label} commands.

1\begin{equation}
2    E = mc^2\label{eq:Relativity}
3\end{equation} 
4
5Formula \eqref{eq:Relativity} was one of Einstein's most important formulas.
Code left > output right
Code left > output right

Multiple equations can be put within the same math environment. This automatically means you can have multiple labels within the environment, each corresponding with the equation on the current line.

Array

The array environment creates a table. But, unlike the regular tabular environment, all cells are automatically put into math mode. Of course, you could recreate the effect by starting math mode in every cell individually, but using this environment is much cleaner and faster.

The syntax is:

1\[     
2    \begin{array}{columns}         
3        item1 & item2 & item3 \\        
4        % …     
5    \end{array} 
6\]

Because cells are all in math mode, the types of columns you can use are restricted. The only options are: l (left), c (center), r (right) and | (vertical line).

1\[
2    \begin{array}{llll}
3        2 &+& 2 & = 4 \\
4        2 &+& 2 & = 0
5    \end{array}
6\]
Code left > output right
Code left > output right
Continue with this course
Support me and this website!

Want to support me?

Buy one of my projects. You get something nice, I get something nice.

Donate through a popular platform using the link below.

Simply giving feedback or spreading the word is also worth a lot.