## Use and Troubleshoot LaTeX

LaTeX is a coding language for displaying math formulas and equations. LaTeX is officially pronounced luh-TEK.

LaTeX formulas can be placed inline ($x+3$) or in their own paragraph.

$x+3$

Go straight to Troubleshooting.

## Reading and Writing the Code

### Declaring your formula

To write a mathematical statement or equation using LaTeX (such as x+2=4), we need to open and close each with bracketed LaTeX tags, as shown below.

$x+2=4$

$x+2=4$

If you are typing text normally, you are said to be in text mode, but while you are typing within one of those mathematical environments, you are said to be in math mode, that has some differences compared to the text mode:

1. Most spaces and line breaks do not have any significance
2. Empty lines are not allowed. Only one paragraph per formula.
3. Each letter is considered to be the name of a variable and will be typeset as such. If you want to typeset normal text within a formula (normal upright font and normal spacing) then you have to enter the text using dedicated commands.

Observe the text in this expression.

$price=cost\times units produced + 35$

$price=cost\times units produced + 35$

There are two noticeable problems: there are no spaces between words or numbers, and the letters are italicized and more spaced out than normal. Both issues are simply artifacts of the maths mode, in that it treats it as a mathematical expression: spaces are ignored (LaTeX spaces mathematics according to its own rules), and each character is a separate element (so are not positioned as closely as normal text).

$\text{price}=\text{cost}\times\text{units produced} + 35$

gives:

$\text{price}=\text{cost}\times\text{units produced} + 35$

 With \text{}: $x\text{ or }\theta$ $x\text{ or }\theta$ Without \text{}: $x or\theta$ $x or\theta$
 With \text{}: $\text{C}_{6}\text{H}_{12}\text{O}_{6}$ $\text{C}_{6}\text{H}_{12}\text{O}_{6}$ Without \text{}: $C_{6}H_{12}O_{6}$ $C_{6}H_{12}O_{6}$

### Binary Operators

We can add binary operators that are not on the keyboard by typing the correct code. Here is a good list of symbols you might want to use.

$x\div 2 = 4$

$x\div 2 = 4$

$x = \pm {4}$

$x = \pm {4}$

$(A)\cup(B)$

$(A)\cup(B)$

### Other Operators

An operator is a function that is written as a word: e.g. trigonometric functions (sin, cos, tan), logarithms and exponentials (log, exp), limits (lim), as well as trace and determinant (tr, det). LaTeX has many of these defined as commands:

$\lim_{x \to \infty} \exp(-x) = 0$

$\lim_{x \to \infty} \exp(-x) = 0$

### Fractions, subscripts, superscripts

Braces, {}, allow you to apply LaTex operations to specific elements of your equation or statement. For example, you may want exponents, indexes, or to show an item crossed out.

$x^{2}=4$

$x^{2}=4$

$x_{2}=4$

$x_{2}=4$

$\cancel{5}x=4\times\cancel{5}$

$\cancel{5}x=4\times\cancel{5}$

We can also use braces format text within the equation. Without braces, text will be italicized in the equation.  Spaces between words can be placed within text braces without causing errors.

 With braces: $x\text{ or }\theta$ $x\text{ or }\theta$ Without braces: $x or\theta$ $x or\theta$
 With braces: $\text{C}_{6}\text{H}_{12}\text{O}_{6}$ $\text{C}_{6}\text{H}_{12}\text{O}_{6}$ Without braces: $C_{6}H_{12}O_{6}$ $C_{6}H_{12}O_{6}$

Braces also allow you to construct fractions. We need one set of braces to hold the numerator and one set to hold the denominator.

$\frac{x}{2}$

$\frac{x}{2}$

It is possible to nest braces, such as when a fraction contains exponents. Every opening brace must have an accompanying closing brace. Notice in the next example that we want exponents on the numerator or a fraction. The braces that create the fraction should be placed around the braces that create the exponent.

$\frac{x^{2}}{x}$

$\frac{x^{2}}{x}$

$\frac{x^{\frac{1}{2}}}{x^{\text{C}_{2}}}$

$\frac{x^{\frac{1}{2}}}{x^{\text{C}_{2}}}$

### Delimiters

Let’s say you want to use delimiters in your mathematical expression.  Many delimiters have special meaning in the LaTex context. We can use those symbols by adding slashes, as shown below. (Parentheses and brackets often require \left or \right.)

$\{4,5,6,7\}$

$\{4,5,6,7\}$

$\left(4,5,6,7\right)$

$\left(4,5,6,7\right)$

$\100$

$\100$

$42\%$

$42\%$

### Greek Letters

Greek letters are commonly used in mathematics, and they are very easy to create using LaTeX. You just have to type the name of the letter after a backslash. This tool only supports the lowercase greek letters.

$\alpha,\beta$

$\alpha,\beta$

In order to build equations with multiple lines, we will need to start and end each equation with array tags much like the $ tags we have been using. The array tags are \begin{array} and \end{array}. We will also need to add a column tag {c} that indicates how many columns our array will have. In the example below, we only have one column, so our column tag has only one c inside the brackets. \begin{array}{c}x+2=4\end{array}$ $\begin{array}{c}x+2=4\end{array}$ To add another line, we add \\ at the end of the first line, then type the next line. $\begin{array}{c}x+2=4 \\ x=2 \end{array}$ $\begin{array}{c}x+2=4 \\ x=2 \end{array}$ Let’s say we want to make the equal signs of both lines match up. We can do this by adding hfill tags, or &\hfill, right before and after the character we want to align (usually an equal sign). Notice in the code below how the &\hfill tags sandwich the equal sign. $\begin{array}{c}x+2&\hfill =&\hfill 4 \\ x &\hfill =&\hfill 2 \end{array}$ $\begin{array}{c}x+2&\hfill =&\hfill 4 \\ x &\hfill =&\hfill 2 \end{array}$ We can move the x closer to the equal sign by adding an ampersand-less hfill tag in front of it, like so: \hfill x &\hfill = &\hfill $\begin{array}{c}x+2&\hfill =&\hfill 4 \\ \hfill x &\hfill =&\hfill 2 \end{array}$ $\begin{array}{c}x+2&\hfill =&\hfill 4 \\ \hfill x &\hfill =&\hfill 2 \end{array}$ We can add more hfill tags to make longer lines. A common use for this is to add instructions on how to solve the equation. $\begin{array}{c}x+2&\hfill=&\hfill4 &\hfill \text{Subtract 2 on both sides.} \\ \hfill x &\hfill = &\hfill 2\end{array}$ $\begin{array}{c}x+2&\hfill=&\hfill4 &\hfill \text{Subtract 2 on both sides.} \\ \hfill x &\hfill = &\hfill 2\end{array}$ You can also substitute “array” with “cases” to get a bracket encompassing all of the lines in your equation. (First code example is without hfill tags for easier reading; second code example is the code used for the display.) $\begin{cases}x+2=4 \\ x=2 \end{cases}$ $\begin{cases}x+2 &\hfill = &\hfill 4 \\ \hfill x &\hfill =&\hfill 2 \end{cases}$ $\begin{cases}x+2 &\hfill = &\hfill 4 \\ \hfill x &\hfill =&\hfill 2 \end{cases}$ It is possible to put other things in the equation outside of the array or case. As long as your code is within the LaTeX tags, it will be included in the equation. $a=\begin{cases}x+2=4 \\ x=2 \end{cases}$ $a=\begin{cases}x+2=4 \\ x=2 \end{cases}$ $f\left(x\right)=\begin{cases}\theta^{5}-6 &\hfill = &\hfill x \hfill \\ \hfill \theta^{5} &\hfill = &\hfill x+6 \end{cases}$ $f\left(x\right)=\begin{cases}\theta^{5}-6 &\hfill = &\hfill x \hfill \\ \hfill \theta^{5} &\hfill = &\hfill x+6 \end{cases}$ ## Troubleshooting Common Problems ### LaTeX Not Rendering If the LaTeX is not rendering, as in the picture above, run through this checklist. • Did you remember to put a LaTeX tag ( $ and $ ) at the beginning and end of your equation? Did you use the correct slash in the end tag? Remember that the closing LaTeX tag uses / (), while everything else in your equation uses \ (\theta).)
• There may be some extra HTML code messing up the LaTeX code. Cut and paste your LaTeX code without formatting (or “Paste and match style”) to remove any HTML code.
• Double-check all of your braces. Remember that every opening brace needs a closing brace somewhere. That can be difficult with very long or very complicated equations. It may help you to change the color of braces that go together to determine whether a brace is missing. (Just remember to undo your color changes before publishing because LaTeX cannot handle the HTML coding that causes color. See the checklist item above.)
We are missing a brace for the square root tag (\sqrt), pictured here as blue.

$\frac{-b\pm\sqrt{b^{2}-4ac}}{2a}$

$\frac{-b\pm\sqrt{b^{2}-4ac}}{2a}$

### Formula Does Not Parse

• In edit mode in Candela, select Utilities in the left menu of the screen, then click PB LaTeX.
Make sure KaTeX + MathJax is enabled.

### LaTeX Code Has a Box Around It

• Double-check all of your braces. Remember that every opening brace needs a closing brace somewhere. That can be difficult with very long or very complicated equations. It may help you to change the color of braces that go together to determine whether a brace is missing. (Just remember to undo your color changes before publishing because LaTeX cannot handle color.)
We have an extra brace, pictured here as purple. Either delete the extra brace or put an opening brace somewhere else in the equation.

$\frac{-b\pm\sqrt{b^{2}-4ac}}{2a}$

$\frac{-b\pm\sqrt{b^{2}-4ac}}{2a}$

• Check to see if there is a stray parenthesis in the code. Like brackets, every opening parenthesis needs a closing parenthesis. Make sure each parenthesis has a \left or \right tag. Example below.

$b+\left(5-3\right)$
• If your equation is an array, did you remember to put /end{array}?

### Missing Characters

$\begin{array}{c}3x-4 &\hfill = &\hfill 2 \\ 3x &\hfill = &\hfill 6\\ x &\hfill = &\hfill 2\end{array}$

• Delete a space where each missing character sign is in the equation.

$\begin{array}{c}3x-4 &\hfill = &\hfill 2 \\ 3x&\hfill = &\hfill 6\\ x&\hfill = &\hfill 2\end{array}$

$\begin{array}{c}3x-4 &\hfill = &\hfill 2 \\ 3x&\hfill = &\hfill 6\\ x&\hfill = &\hfill 2\end{array}$

### Other Problems

If you encounter a problem other than the ones shown above, run through this checklist.

• Did you remember to include closing tags (such as [/latex] or \end{array})?
• Do you have too many or too few braces?
• Do you have too many or too few parentheses? Remember that parentheses need the code \left( and \right).
• Did you use the correct slash? Remember that the closing LaTeX tag uses / ([/latex]), while everything else in your equation uses \ (\theta).
• Did you spell everything correctly? (\infty, not \infinity). Check what the correct code for a symbol is.
• If a particular symbol still isn’t rendering, it may be better to replace it with another symbol with the same meaning when possible. For example, \cdot ($\cdot$) can be replaced with \times ($\times$). ($2\times2$ instead of $2\cdot2$.)

## More Information

For more in-depth information about using LaTeX, check WordPress’s LaTeX site.