Skip to main content
Chemistry LibreTexts

4.5: Adding and Editing Equations

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Our adding equations video tutorial on YouTube:

    Equations in LibreTexts are handled by the MathJax add-on (based on LaTeX). This page contains guidelines and references on how to use this system. It is fairly straight-forward for anyone who has ever worked with code (markup).

    Inline vs. Displaymode Equations

    To add an equation, authors have two choices: either (1) inline or (2) display. The difference is demonstrated here:

    An inline equation looks like this, \(E=mc^2,\) and is meant to be read with the paragraph. An equation that is presented in display mode looks like this


    with the equation taking up the entire line. Note that the displaystyle equation is automatically numbered.

    To invoke an inline equation add \( \backslash( \) and \(\backslash)\) around the LaTeX code (discussed below). To invoke the display mode add \(\backslash[\) and \(\backslash]\) around the LaTeX code. The code can be somewhat complicated and must be formulated properly or the MathJax add-on will not render the equation (or will do so improperly). Examples of MathJax code, including some useful templates, can be found at the bottom of this page.

    Mathpix: The Tool you Can't Live Without

    MathJax is a little overwhelming at first but thankfully there is a tool that makes it super easy called MathPix Snip.

    • Download the tool from and install it on your computer
    • When you need to transfer an equation press ctrl+alt+m and select the equation that you want to copy.
    • Use the first line that doesn't have any environment coding and add the \( or \[ for inline or display mode environment manually.
    • If the snipper got a few details wrong you can edit the code and check that it renders before copying it over
    • If it is a complicated equation zoom in on it using your browser before using the tool. If it still doesn't work consider snipping the equation in several parts.

    Intrapage Numbering and Referencing of Equations

    The MathJax system is ideal for referencing equations on a page. Equations in displaymode (i.e., used with \[ \] delimiters) are automatically numbered, inline equations (using \( \) delimiters) are not. If you want to reference a displayed equation you give it a label by writing \label{name} after the equation but before \]. For example, the following code

     \[ E =mc^2 \label{Einstein} \] See equation \ref{Einstein} 

    renders as

    \[ E =mc^2 \label{Einstein} \] See equation \ref{Einstein}

    If you do not want a display equation to be numbered you can use \nonumber after the equation (and drop the label text since that is unneeded.

     \[ E =mc^2 \nonumber\]

    renders as

    \[ E =mc^2 \nonumber\]

    Interpage Numbering and Referencing of Equations

    Interpage referencing is a bit more complicated. The best option currently involves HTML rather than MathJax.

    • Source page: This is the page you want to link to. Once you edit the page, place your cursor at a place you wish to create a link. Then select Elements on the menu and choose the Anchor option. You can use it like you would \label in LaTeX/MathJax. It adds a little flag that is visible when in Edit mode.
    • Reference page: This is the page on which you wish to place a link to an anchor on another page. Go to this page and open the edit view. Highlight text you want to be a link. Go to Elements menu again and click Link (there is also a button on the blue WYSIWYG editor bar for this). Select the source page and at the bottom entry titled "Jump to anchor or section", you will see the text you used for the label on the source page. Save this link and save the page.

    If the equation shows up just under the floating blue bar, you can move the anchor to the paragraph before to make it display as desired (small issues until we get it fixed).

    When editing math pages

    • Be sure to use the escape character \(\backslash\) in front of all trigonometric functions (\( \sin x, \cos x, \tan x,\)) natural logarithms (\(\ln x\)), etc. Then leave a space between the function and its argument unless there is a parentheses there. For example, \( \backslash\text{sin}\,\text{x}\) or \( \backslash\text{sin}(\text{x})\) (rendering as \( \sin x \) and \( \sin (x) \), respectively). If you don't do this, the results may look like this: \( sinx, cosx, \sinx, lnx, \lnx\).
    • Use the escape character \(\backslash\) in front of "lim" for limits.
    • If limits, integrals or sigma notation (sums) are to be used as part of inline mathematics, be sure to add \(\backslash\text{displaystyle}\) as the first commands of these inline math expressions. Here is what a limit should look like when rendered correctly: \(\displaystyle \lim_{x \to 0} \frac{\sin x}{x}\), and incorrectly: \(lim_{x \to 0} \frac{\sin x}{x}.\)
    • Display mode mathematics will never need \(\backslash\text{displaystyle}\).
    • Do not use \(\backslash\text{displaystyle}\) unless it is helpful for making one of the above mathematical notations render nicely.
    • To obtain larger fractions in an inline setting like \(\dfrac{2x}{x^2 + 1}\) instead of small ones like \(\frac{2x}{x^2 + 1}\), use \(\backslash\text{dfrac}\) instead of using \(\backslash\text{displaystyle}\) with \(\backslash\text{frac}\) which would have the same effect, but is overkill unless the \(\backslash\text{displaystyle}\) is needed for another reason like those listed above.
    • When using display mode mathematics between \(\backslash[\) and \(\backslash]\), consider whether the equation is an important result that may be referred to later in the text or not. By default display mode mathematics lines will be aut\nonumbered. If the equation is not a main result, it should typically not be numbered, so you will need to insert a \(\backslash\text{n\nonumber}\) at the end of it but within the expression.
    • Do not use any extra commands, like \(\backslash\text{mathrm}\), in front of every instance of math in a page to try to get text to look a certain way. There should be a better way to get the desired effect.
    • When editing integrals, please use a spacing element before the differential. For example, \(\backslash\text{displaystyle }\backslash\text{int x^2 }\backslash,\text{dx}\).

    Other examples to learn MathJax/Latex from


    Table 1: Subscripts, superscripts, integrals
    Feature Syntax How it looks rendered
    Superscript a^2 \(a^2\)
    Subscript a_2 \(a_2\)
    Grouping a^{2+2} \(a^{2+2}\)
    a_{i,j} \(a_{i,j}\)
    Combining sub & super x_2^3 \(x_2^3\)
    Preceding and/or Additional sub & super \sideset{_1^2}{_3^4}\prod_a^b \(\sideset{_1^2}{_3^4}\prod_a^b\)
    {}_1^2\!\Omega_3^4 \({}_1^2\!\Omega_3^4\)
    Stacking \overset{\alpha}{\omega} \(\overset{\alpha}{\omega}\)
    \underset{\alpha}{\omega} \(\underset{\alpha}{\omega}\)
    \overset{\alpha}{\underset{\gamma}{\omega}} \(\overset{\alpha}{\underset{\gamma}{\omega}}\)
    \stackrel{\alpha}{\omega} \(\stackrel{\alpha}{\omega}\)
    Derivative (forced PNG) x', y, f', f\!  
    Derivative (f in italics may overlap primes in HTML) x', y, f', f \(x', y'', f', f''\)
    Derivative (wrong in HTML) x^\prime, y^{\prime\prime} \(x^\prime, y^{\prime\prime}\)
    Derivative (wrong in PNG) x\prime, y\prime\prime \(x\prime, y\prime\prime\)
    Derivative dots \dot{x}, \ddot{x} \(\dot{x}, \ddot{x}\)
    Underlines, overlines, vectors \hat a \ \bar b \ \vec c \(\hat a \ \bar b \ \vec c\)
    \overrightarrow{a b} \ \overleftarrow{c d} \ \widehat{d e f} \(\overrightarrow{a b} \ \overleftarrow{c d} \ \widehat{d e f}\)
    \overline{g h i} \ \underline{j k l} \(\overline{g h i} \ \underline{j k l}\)
    Arrows A \xleftarrow{n+\mu-1} B \xrightarrow[T]{n\pm i-1} C \( A \xleftarrow{n+\mu-1} B \xrightarrow[T]{n\pm i-1} C\)
    Overbraces \overbrace{ 1+2+\cdots+100 }^{5050} \(\overbrace{ 1+2+\cdots+100 }^{5050}\)
    Underbraces \underbrace{ a+b+\cdots+z }_{26} \(\underbrace{ a+b+\cdots+z }_{26}\)
    Sum \sum_{k=1}^N k^2 \(\sum_{k=1}^N k^2\)
    Sum (force \displaystyle for inline use) \displaystyle \sum_{k=1}^N k^2 \(\displaystyle \sum_{k=1}^N k^2\)
    Product \prod_{i=1}^N x_i \(\prod_{i=1}^N x_i\)
    Product (force \displaystyle for inline use) \displaystyle \prod_{i=1}^N x_i \(\displaystyle \prod_{i=1}^N x_i\)
    Coproduct \coprod_{i=1}^N x_i \(\coprod_{i=1}^N x_i\)
    Coproduct (force \displaystyle for inline use) \displaystyle \coprod_{i=1}^N x_i \(\displaystyle \coprod_{i=1}^N x_i\)
    Limit \lim_{n \to \infty}x_n \(\lim_{n \to \infty}x_n\)
    Limit (force \displaystyle for inline use) \displaystyle \lim_{n \to \infty}x_n \(\displaystyle \lim_{n \to \infty}x_n\)
    Integral \int\limits_{-N}^{N} e^x\, dx \(\int\limits_{-N}^{N} e^x\, dx\)
    Integral (force \displaystyle for inline use) \displaytstyle \int\limits_{-N}^{N} e^x\, dx \(\displaystyle \int\limits_{-N}^{N} e^x\, dx\)
    Double integral \iint\limits_{D} \, dx\,dy \(\iint\limits_{D} \, dx\,dy\)
    Triple integral \iiint\limits_{E} \, dx\,dy\,dz \(\iiint\limits_{E} \, dx\,dy\,dz\)
    Quadruple integral \iiiint\limits_{F} \, dx\,dy\,dz\,dt \(\iiiint\limits_{F} \, dx\,dy\,dz\,dt\)
    Path integral \oint\limits_{C} x^3\, dx + 4y^2\, dy \(\oint\limits_{C} x^3\, dx + 4y^2\, dy\)
    Intersections \bigcap_1^{n} p \(\bigcap_1^{n} p\)
    Unions \bigcup_1^{k} p \(\bigcup_1^{k} p\)
    Cancelling factors \dfrac{\cancel{(x-3)}(x+5)}{\cancel{(x-3)} \(\dfrac{\cancel{(x-3)}(x+5)}{\cancel{(x-3)}}\)
    Table 2: Fractions, matrices, multilines
    Feature Syntax How it looks rendered
    Fractions \frac{2}{4}=0.5 \(\frac{2}{4}=0.5\)
    Small Fractions \tfrac{2}{4} = 0.5 \(\tfrac{2}{4} = 0.5\)
    Large (normal) Fractions \dfrac{2}{4} = 0.5 \(\dfrac{2}{4} = 0.5\)
    Large (nested) Fractions \cfrac{2}{c + \cfrac{2}{d + \cfrac{2}{4}}} = a \(\cfrac{2}{c + \cfrac{2}{d + \cfrac{2}{4}}} = a\)
    Binomial coefficients \binom{n}{k} \(\binom{n}{k}\)
    Small Binomial coefficients \tbinom{n}{k} \(\tbinom{n}{k}\)
    Large (normal) Binomial coefficients \dbinom{n}{k} \(\dbinom{n}{k}\)
      x & y \\
      z & v 
    \(\begin{matrix} x & y \\ z & v \end{matrix}\)
      x & y \\
      z & v 
    \(\begin{vmatrix} x & y \\ z & v \end{vmatrix}\)
      x & y \\
      z & v
    \(\begin{Vmatrix} x & y \\ z & v \end{Vmatrix}\)
      0      & \cdots & 0      \\
      \vdots & \ddots & \vdots \\ 
      0      & \cdots & 0
    \(\begin{bmatrix} 0 & \cdots & 0 \\ \vdots & \ddots & \vdots \\ 0 & \cdots & 0\end{bmatrix} \)
      x & y \\
      z & v
    \(\begin{Bmatrix} x & y \\ z & v \end{Bmatrix}\)
      x & y \\
      z & v 
    \(\begin{pmatrix} x & y \\ z & v \end{pmatrix}\)
    \bigl( \begin{smallmatrix}
      a&b\\ c&d
    \end{smallmatrix} \bigr)
    \( \bigl( \begin{smallmatrix} a&b\\ c&d \end{smallmatrix} \bigr) \)
    Case distinctions
    f(n) = 
      n/2,  & \mbox{if }n\mbox{ is even} \\
      3n+1, & \mbox{if }n\mbox{ is odd} 
    \(f(n) = \begin{cases} n/2, & \mbox{if }n\mbox{ is even} \\ 3n+1, & \mbox{if }n\mbox{ is odd} \end{cases} \)
    Multiline equations (use * for n\nonumber)

    [4pt] or [5pt], etc., are used to space between lines
     f(x) & = (a+b)^2 \\[4pt]
          & = a^2+2ab+b^2
    \( \begin{align*} f(x) & = (a+b)^2 \\[4pt]
    &= a^2+2ab+b^2 \end{align*} \)
    Multiline equations with explanations
     f(x) &= (a+b)^2 & &
     \text{Original binomial squared}
     &= a^2+2ab+b^2 & &\text{Expand.}
    \( \begin{align*} f(x) & = (a+b)^2 & & \text{Original binomial squared}\\[5pt]
    &= a^2+2ab+b^2 & & \text{Expand.} \end{align*} \)
    Multiline equations (must define number of colums used ({lcr}) (should not be used unless needed)
      z        & = & a \\
      f(x,y,z) & = & x + y + z  
    \(\begin{array}{lcl} z & = & a \\ f(x,y,z) & = & x + y + z \end{array}\)
    Multiline equations (more)
      z        & = & a \\
      f(x,y,z) & = & x + y + z     
    \(\begin{array}{lcr} z & = & a \\ f(x,y,z) & = & x + y + z \end{array}\)
    Breaking up a long expression so that it wraps when necessary
    <math>f(x) \,\!</math>
    <math>= \sum_{n=0}^\infty a_n x^n </math>
    <math>= a_0+a_1x+a_2x^2+\cdots</math>

    \(f(x) \,\!\)\(= \sum_{n=0}^\infty a_n x^n \)\(= a_0 +a_1x+a_2x^2+\cdots\)

    Simultaneous equations
        3x + 5y +  z \\
        7x - 2y + 4z \\
       -6x + 3y + 2z 
    \(\begin{cases} 3x + 5y + z \\ 7x - 2y + 4z \\ -6x + 3y + 2z \end{cases}\)
    Long Division
    \(\require{enclose} \begin{array}{r}x+\phantom{0}4\hspace{.5em}\\[-3pt] x+5\enclose{longdiv}{x^2+\phantom{00}9x+20\phantom{0}}\\[-3pt] \underline{{\color{red}-}x^2+({\color{red}-}5x)}\hspace{2.1em}\\[-3pt] 4x+20\hspace{.5em}\\[-3pt] \underline{{\color{red}-}4x+({\color{red}-}20)}\\[-3pt] 0\hspace{.33em}\end{array}\)
    Synthetic Division
    {\begin{array}{c}-2\\ \\ \\
     \\[0pt] \end{array}}\\[1pt]
     & \\[2pt]& \end{align*}}\!\!
    4 & 10 & -6 & -20\\
    & -8 & -4 & 20 \\
    \hline 4 & 2& -10 & 0
    \({\begin{array}{c}-2\\ \\ \\ \end{array}}{\begin{align*}&\\[0pt]&{\begin{array}{r|}\\[0pt] \\[0pt] \end{array}}\\[1pt]& \\[2pt]& \end{align*}}\!\!
    4 & 10 & -6 & -20\\
    & -8 & -4 & 20 \\
    \hline 4 & 2& -10 & 0

    Chemistry Package

    The Libretexts libraries have also installed the mhchem, a tool for writing beautiful chemical equations easily. The syntax for this powerful add-on can be found here:

    Contributors and Attributions

    4.5: Adding and Editing Equations is shared under a CC BY 1.3 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?