LaTeX is a coding language for displaying math formulas and equations. LaTeX is officially pronounced luh-TEK.
LaTeX formulas can be placed inline ([latex]x+3[/latex]) or in their own paragraph.
[latex]x+3[/latex]
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.
[latex]x+2=4[/latex]
[latex]x+2=4[/latex]
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:
- Most spaces and line breaks do not have any significance
- Empty lines are not allowed. Only one paragraph per formula.
- 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.
[latex]price=cost\times units produced + 35[/latex]
[latex]price=cost\times units produced + 35[/latex]
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).
[latex]\text{price}=\text{cost}\times\text{units produced} + 35[/latex]
gives:
[latex]\text{price}=\text{cost}\times\text{units produced} + 35[/latex]
With \text{}: | [latex]x\text{ or }\theta[/latex] [latex]x\text{ or }\theta[/latex] |
Without \text{}: | [latex]x or\theta[/latex] [latex]x or\theta[/latex] |
With \text{}: | [latex]\text{C}_{6}\text{H}_{12}\text{O}_{6}[/latex] [latex]\text{C}_{6}\text{H}_{12}\text{O}_{6}[/latex] |
Without \text{}: | [latex]C_{6}H_{12}O_{6}[/latex] [latex]C_{6}H_{12}O_{6}[/latex] |
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.
[latex]x\div 2 = 4[/latex]
[latex]x\div 2 = 4[/latex]
[latex]x = \pm {4}[/latex]
[latex]x = \pm {4}[/latex]
[latex](A)\cup(B)[/latex]
[latex](A)\cup(B)[/latex]
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:
[latex]\lim_{x \to \infty} \exp(-x) = 0[/latex]
[latex]\lim_{x \to \infty} \exp(-x) = 0[/latex]
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.
[latex]x^{2}=4[/latex]
[latex]x^{2}=4[/latex]
[latex]x_{2}=4[/latex]
[latex]x_{2}=4[/latex]
[latex]\cancel{5}x=4\times\cancel{5}[/latex]
[latex]\cancel{5}x=4\times\cancel{5}[/latex]
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: | [latex]x\text{ or }\theta[/latex] [latex]x\text{ or }\theta[/latex] |
Without braces: | [latex]x or\theta[/latex] [latex]x or\theta[/latex] |
With braces: | [latex]\text{C}_{6}\text{H}_{12}\text{O}_{6}[/latex] [latex]\text{C}_{6}\text{H}_{12}\text{O}_{6}[/latex] |
Without braces: | [latex]C_{6}H_{12}O_{6}[/latex] [latex]C_{6}H_{12}O_{6}[/latex] |
Braces also allow you to construct fractions. We need one set of braces to hold the numerator and one set to hold the denominator.
[latex]\frac{x}{2}[/latex]
[latex]\frac{x}{2}[/latex]
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.
[latex]\frac{x^{2}}{x}[/latex]
[latex]\frac{x^{2}}{x}[/latex]
[latex]\frac{x^{\frac{1}{2}}}{x^{\text{C}_{2}}}[/latex]
[latex]\frac{x^{\frac{1}{2}}}{x^{\text{C}_{2}}}[/latex]
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.)
[latex]\{4,5,6,7\}[/latex]
[latex]\{4,5,6,7\}[/latex]
[latex]\left(4,5,6,7\right)[/latex]
[latex]\left(4,5,6,7\right)[/latex]
[latex]\$100[/latex]
[latex]\$100[/latex]
[latex]42\%[/latex]
[latex]42\%[/latex]
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.
[latex]\alpha,\beta[/latex]
[latex]\alpha,\beta[/latex]
Multiple-Line Equations
In order to build equations with multiple lines, we will need to start and end each equation with array tags much like the [latex]
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.
[latex]\begin{array}{c}x+2=4\end{array}[/latex]
[latex]\begin{array}{c}x+2=4\end{array}[/latex]
To add another line, we add \\
at the end of the first line, then type the next line.
[latex]\begin{array}{c}x+2=4 \\ x=2 \end{array}[/latex]
[latex]\begin{array}{c}x+2=4 \\ x=2 \end{array}[/latex]
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.
[latex]\begin{array}{c}x+2&\hfill =&\hfill 4 \\ x &\hfill =&\hfill 2 \end{array}[/latex]
[latex]\begin{array}{c}x+2&\hfill =&\hfill 4 \\ x &\hfill =&\hfill 2 \end{array}[/latex]
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
[latex]\begin{array}{c}x+2&\hfill =&\hfill 4 \\ \hfill x &\hfill =&\hfill 2 \end{array}[/latex]
[latex]\begin{array}{c}x+2&\hfill =&\hfill 4 \\ \hfill x &\hfill =&\hfill 2 \end{array}[/latex]
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.
[latex]\begin{array}{c}x+2&\hfill=&\hfill4 &\hfill \text{Subtract 2 on both sides.} \\ \hfill x &\hfill = &\hfill 2\end{array}[/latex]
[latex]\begin{array}{c}x+2&\hfill=&\hfill4 &\hfill \text{Subtract 2 on both sides.} \\ \hfill x &\hfill = &\hfill 2\end{array}[/latex]
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.)
[latex]\begin{cases}x+2=4 \\ x=2 \end{cases}[/latex]
[latex]\begin{cases}x+2 &\hfill = &\hfill 4 \\ \hfill x &\hfill =&\hfill 2 \end{cases}[/latex]
[latex]\begin{cases}x+2 &\hfill = &\hfill 4 \\ \hfill x &\hfill =&\hfill 2 \end{cases}[/latex]
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.
[latex]a=\begin{cases}x+2=4 \\ x=2 \end{cases}[/latex]
[latex]a=\begin{cases}x+2=4 \\ x=2 \end{cases}[/latex]
[latex]f\left(x\right)=\begin{cases}\theta^{5}-6 &\hfill = &\hfill x \hfill \\ \hfill \theta^{5} &\hfill = &\hfill x+6 \end{cases}[/latex]
[latex]f\left(x\right)=\begin{cases}\theta^{5}-6 &\hfill = &\hfill x \hfill \\ \hfill \theta^{5} &\hfill = &\hfill x+6 \end{cases}[/latex]
Troubleshooting Common Problems
- LaTeX not rendering
- Formula does not parse
- LaTeX code has a box around it
- Missing characters
- Other 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 (
[latex]
and[/latex]
) 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 / ([/latex]
), 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.
[latex]\frac{-b\pm\sqrt{b^{2}-4ac}}{2a}[/latex]
[latex]\frac{-b\pm\sqrt{b^{2}-4ac}}{2a}[/latex]
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.
[latex]\frac{-b\pm\sqrt{b^{2}-4ac}}{2a}[/latex]
[latex]\frac{-b\pm\sqrt{b^{2}-4ac}}{2a}[/latex]
- 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.
- If your equation is an array, did you remember to put
/end{array}
?
Missing Characters
[latex]\begin{array}{c}3x-4 &\hfill = &\hfill 2 \\ 3x &\hfill = &\hfill 6\\ x &\hfill = &\hfill 2\end{array}[/latex]
- Delete a space where each missing character sign is in the equation.
[latex]\begin{array}{c}3x-4 &\hfill = &\hfill 2 \\ 3x&\hfill = &\hfill 6\\ x&\hfill = &\hfill 2\end{array}[/latex]
[latex]\begin{array}{c}3x-4 &\hfill = &\hfill 2 \\ 3x&\hfill = &\hfill 6\\ x&\hfill = &\hfill 2\end{array}[/latex]
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
([latex]\cdot[/latex]) can be replaced with\times
([latex]\times[/latex]). ([latex]2\times2[/latex] instead of [latex]2\cdot2[/latex].)
More Information
For more in-depth information about using LaTeX, check WordPress’s LaTeX site.