Here are some basic ideas to make sure your code doesn't break on you and your equations look better:
\begin{}
\end{}
commands are matching. This is something where one small mistake can mess your whole piece of code up in a big way.\begin{equation*}
command without the amsmath
package).$$an equation here$$
) instead of \begin{equation}
.Good luck!
Simple, Inline Equations
You can do a simple inline equation by using $an equation here$
.
For example, you might do
$\lim\limits_{n \to \infty} \frac{1}{2^n} i\bar z$
which, if we put a little fake text around it, gives
Numbered, Centered Equations
When writing papers or other documents, it is sometimes preferable to have your equations centered and numbered, as opposed to in-line. Then, use the \begin{equation}
and \end{equation}
commands.
For example, if we use the code
\begin{equation}
\lim\limits_{n \to \infty} \frac{1}{2^n} i\bar z
\end{equation}
And add a little text around it, we get
You can remove the numbering of the equation by using \begin{equation*}
and \end{equation*}
.
For example, if we use the code
\begin{equation*}
\lim\limits_{n \to \infty} \frac{1}{2^n} i\bar z
\end{equation*}
and add a little text around it, we get
(though it should be noted you have to use the amsmath
package for this).
Sometimes, it can be difficult to find the mathematical symbol you need. There are several options here. The first (and quickest) is to use Detexify, where you draw the symbol you'd like, and it tries to find what you want, like as shown below:
Another option is to use the comprehensive LaTeX symbols list, which can be found here. If you are using the package unicode-math
this list of all supported symbols can be helpful. Another option is this website, which has common math symbols.
While standard LaTeX is all that is needed for most simple mathematical formulae and equations, sometimes more symbols and tools are needed. There are multiple packages available that will enhance your equations and provide you with more to work with. Three of the main packages are described below. Remember, to load a package, type \usepackage{package}
in your document preamble.
amsmath
The amsmath
package is an incredibly useful package. It is used to allow your equations to be centered but not numbered, as in \begin{equation*}
, it is used to create matrices (as described below) and it introduces many other useful commands, such as \overset
and \underset
, described below. The amsmath
package documentation can be found here.
mathtools
The mathtools
package builds off of the amsmath
package, adding further useful symbols and tools. It automatically loads the amsmath
package, so you do not need to load both in your document preamble. The mathtools
documentation can be found here.
amssymb
The amssymb
package provides many extra symbols that can be very handy for more complex equations. The amssymb
documentation can be found here.
Font packages
There are also various fonts you can use for your equations, as described on this question on the TeX stack exchange, for TeX, LaTeX, and friends.
This paper is a concise explanation of the different features provided by some packages as well as standard LaTeX; it is very helpful.
Some of the most common commands include:
\frac {numerator}{denominator}
. For square roots, use \sqrt[root]{number}
.\leq
gives the less than or equal to symbol, \geq
gives the greater than or equal to symbol, \neq
gives the not equal symbol, \sum
gives the summation symbol, \partial
gives the partial derivative symbol, \nabla
gives the Laplacian operator, \times
gives the cross product or multiplication symbol, \cdot
gives the dot product or multiplication symbol, and \int
gives the integral symbol.\rightarrow
and \leftarrow
give right and left arrows, respectively.\%
as the percent symbol is normally used for comments.x^2
, or, for longer superscripts, x^{2x}
. To do a subscript, you can type x_a
, or, for longer subscripts, x_{ab}
.\boldmath{...}
to make your math symbols bold. Other options are given at this TeX.SX question. Math symbols are automatically italicized; if you don't want this to be true, make your equation text as described below.\infty
.\int
, and then use the \limits
command. An example is \int\limits_{\infty}
or \int\limits^{\infty}
. Then, for normal cases, you can do \overset{top}{normal}
or \underset{bottom}{normal}
. This can be very useful for doing vectors. For example, you might do \overset{\rightarrow}{x}
The amsmath
package is need for overset
and underset
.\{
or \}
to get curly braces.\usepackage{amsmath}
in the preamble, and then type \text{...}
.\quad
between the two items you want to separate (for example, you might have $2x \quad cos
).Let's say you cannot find the symbol you need anywhere. You can create a custom symbol. For example, the code
\documentclass{article}
\usepackage{graphicx,amsmath,amssymb}
\DeclareRobustCommand{\diamondtimes}{%
\mathbin{\text{\rotatebox[origin=c]{45}{$\boxplus$}}}%
}
\begin{document}
$a\diamondtimes b$
\end{document}
creates and calls a symbol, giving
This is a simpler example; it merely has to rotate an already existent symbol. However, you can create more complex symbols.
This section is in the process of being expanded.
Matrices
You must always use the amsmath
package if you are going to use the following commands. There are four main types of matrix, as shown in the code below:
\begin{matrix}
a & b \\
c & d
\end{matrix}
\quad
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
\quad
\begin{bmatrix}
a & b \\
c & d
\end{bmatrix}
\quad
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
\quad
\begin{Vmatrix}
a & b \\
c & d
\end{Vmatrix}
This code produces
There are a couple important things to note about this:
equation
, equation*
, or $...$
environment - the bmatrix
command is not a math environment on its own.x_{11}
), then put a &
, and then write the next element. For multiple rows, at the end of each row put \\
(you do not have to do this for the last row). It is fairly similar to a table in this.