# 6: Adding and Editing Equations

- Page ID
- 135346

The equations in the LibreTexts are handled by the MathJax add-on (based on LaTex). Below are some details to help out. There are references below to how to use this system, but it is generally straight forward to anyone ever working 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

\[E=mc^2\]

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 is more complicated and must be formulated properly or the MathJax addon will not render the equation (or will do so improperly). To see examples of what this code looks like go to this page:

### 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 https://mathpix.com/ 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.

### Numbering and referencing of equations

Equations in displaymode are automatically numbered, inline equations 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.

### 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 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 autonumbered. If the equation is not a main result, it should typically not be numbered, so you will need to insert a \(\backslash\text{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:

- http://en.wikibooks.org/wiki/LaTeX/Mathematics
- This link http://www.codecogs.com/latex/eqneditor.php(external link) is an online WYSIWYG LaTeX editor that creates math expressions using templates. The LaTeX is automatically written and a preview is displayed. Just copy the code and paste it. Be sure to enclose the LaTeX in dollar signs ($).
- http://en.wikibooks.org/wiki/LaTeX/Mathematics
- http://www.artofproblemsolving.com/W...LaTeX:Commands
- http://www.tex.ac.uk/tex-archive/inf...symbols-a4.pdf
- http://www.suluclac.com/Wiki+MathJax+Syntax
- http://www.mathjax.org/community/mathjax-in-use/
- http://www.mathjax.org/demos/
- http://www.mathjax.org/demos/tex-samples/

**DO NOT USE EXTERNAL SITES LIKE http://www.codecogs.com/latex TO RENDER THE EQUATION FOR YOU VIA PROVIDING AN IMAGE FILE.**