Mathematical Equations in LaTeX

LaTeX provides a feature of special editing tool for scientific tool for math equations in LaTeX. In this article, you will learn how to write basic equations and constructs in LaTeX, about aligning equations, stretchable horizontal lines, operators and delimiters, fractions and binomials.

Mathematical modes

For writing math equations in LaTeX, there are two writing modes: the inline mode and the display mode. The inline mode is used to write formulas that are part of the text and the display mode is used to write expressions that are not part of the text and hence are put on different lines. The inline mode uses one of the delimiters: \ ( \), $ $ or \begin \end and the display mode has two versions: numbered and unnumbered. To print equations in display mode one these delimiters are used: \[ \], $$ $$, \begin \end or \begin \end .

How to write mathematical notations in LaTeX?

There are three ways to write a math equation in LaTeX and they are described as follows:

1. Inline: An inline expression occurs in the middle of the text. For producing an inline expression, the math expression should be written between the dollar sign ($). For example, $E=mc^2 will give E=mc^2.

2. Equation: Mathematical expressions that are given in a line are known as expressions. These are basically placed on the centre of the page and the equations are important ones that deserve to be highlighted. The inline expression shall be put in between \[ and \].

3. Display style: The command \displaystyle is used to get a full sized inline expression.

Writing basic constructs of math in LaTeX

A formula is made up by combining various constructs. Some of them are explained below:

1. Arithmetic Operations:

2. Binomial Coefficients:

3. Ellipses:

The other variants for \dots command are \dotsc for an ellipse followed by comma, \dotsb for an ellipse followed by a binary operation, \dotsm if followed by multiplication, \dotsi for an ellipse with integral and \dotso for an “other” ellipse.

4. Integral:

5. Roots:

Writing single equation

 \documentclass \usepackage[utf8] \usepackage \begin \begin \label E = \end The equation \ref states mass equivalence relationship. \end

Output of the above code

line-LaTeX-img

Aligning Equations

We use the equation environment to wrap our equation or we can use equation if we want it to be numbered. The environment split is used inside an equation environment to split the equation into smaller pieces which will be aligned accordingly.

 \documentclass \usepackage[utf8] \usepackage \begin \begin \label \begin A & = \frac<\pi r^2> \\ & = \frac \pi r^2 \end \end \end

Output of the above code

line-LaTeX-img

Displaying long equations

The equations that utilise more than one line use multiline environment. We use a double backslash to set the point where equation has to be broken. The first line is aligned to the left and the second line is aligned to the right. We use * to determine whether the equation has to be numbered or not.

 \documentclass \usepackage[utf8] \usepackage \begin \begin p(x) = x^8+x^7+x^6+x^5\\ - x^4 - x^3 - x^2 - x \end \end

Output of the above code

line-LaTeX-img

Aligning several equations

We use the align environment with * for determining whether the equation is numbered or not.

 \documentclass \usepackage[utf8] \usepackage \begin \begin a+b & a-b & (a+b)(a-b)\\ x+y & x-y & (x+y)(x-y)\\ p+q & p-q & (p+q)(p-q) \end \end

Output of the above code

line-LaTeX-img

Grouping and Centering Equations

Math equation in LaTeX provides three stretchable lines/arrows that appear above or below the equation: braces, bars and arrows. The \overbrace command places a brace above the expression (or variables) and the command \underbrace places a brace below the expression. The command \overline and \underline places a line above or below the expression. The command \overleftarrow and \overrightarrow places an arrow above or below the expression. The expression has to be written between curly brackets.

 \documentclass \usepackage[utf8] \usepackage \begin \begin (a+b)=a^2+b^2+2ab \\ (a-b)=a^2+b^2-2ab \end \end

Output of the above code

line-LaTeX-img

Parenthesis or Brackets

Parenthesis and brackets are very common in a mathematical equation. We can amend the size of a bracket in math equations in LaTeX.

 \documentclass \usepackage[utf8] \usepackage \begin \[ \left \< \begin 1 & 5 & 8 \\ 0 & 2 & 4 \\ 3 & 3 & -8 \end \right \> \] \end

Output of the above code

line-LaTeX-img

Size of the brackets can be changed as described below

line-LaTeX-img

Operators

There are various types of operators like trigonometrical functions, logarithms and others which are written using special functions.

 \documentclass \usepackage[utf8] \usepackage \begin \[ \sin^2(a)+\cos^2(a) = 1 \] \end

Output of the above code

line-LaTeX-img

The operators that take parameters are written in a special way. For example, in a limit equation, the limit declaration includes a subscript.

 \documentclass \usepackage[utf8] \usepackage \begin \[ \lim_ \frac \] This operator changes when used alongside text \( \lim_ (x-h) \). \end

Output of the above code

line-LaTeX-img

The user can define or personalise his operator by using the command \DeclareMathOperator which takes two parameters, the first one is the name of the new operator and the second one is the text to be displayed. If the operator uses subscripts then the command \DeclareMathOperator* is used.

Fractions and Binomials

Fractions and binomial coefficients of math equations in LaTeX are written using the \frac and \binom command respectively.

 \documentclass \usepackage[utf8] \usepackage \begin \[ \binom = \frac \] \end

Output of the above code

line-LaTeX-img

We use the \frac command to display fractions. The expression between the first pair of brackets is the numerator and in the second is the denominator. The text size of the fraction changes according to the text near it. You can also set the text size of the fraction manually by using the command \displaystyle.

 \documentclass \usepackage[utf8] \usepackage \begin \[ f(x)=\frac \ \ \textrm \ \ f(x)=\textstyle\frac \] \end

Output of the above code

line-LaTeX-img

Fractions can be nested to obtain complex expressions. The command \cfrac displays nested fractions without changing the text size. An example of it is given below:

 \documentclass \usepackage[utf8] \usepackage \begin \[ \frac>>> \] \end

Output of the above code