How to Fix “Missing $ Inserted” at \end{align}
At a glance
- 1. Check earlier lines
The reported line is often where LaTeX noticed the problem, not where the mistake began.
- 2. Remove extra delimiters
Content inside align is already in math mode; remove dollar signs around expressions there.
- 3. Check structure
Match each begin command with the right end command, and look for unmatched math delimiters or braces.
- 4. Test a minimal file
Compile a short example with amsmath, then add your original lines back until the error returns.
A “Missing $ inserted” message pointing to \end{align} usually means LaTeX encountered invalid math-mode syntax somewhere before that line. The closing command is often where the problem becomes visible, rather than where it began.
The first thing to check is whether you put $...$ inside an align environment. The environment already puts its contents in math mode, so those extra dollar signs can disrupt LaTeX’s parsing. If that is not the cause, check for an unmatched $ earlier in the document, mismatched environment names, and unbalanced braces.
Why align does not need dollar signs
The align and align* environments, provided by the amsmath package, are display-math environments. Write mathematical expressions directly inside them. Use & to mark the alignment point, commonly before an equals sign, and \\ to start a new row.
This is a valid minimal example:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
f(x) &= x^2 + 1, \\
g(x) &= 2x - 3.
\end{align}
\end{document}
The dollar signs in this example are absent from the aligned equations because align supplies the math mode. The environment numbers each row by default. Use align* instead of align if you want an unnumbered display.
Remove dollar signs inside align
This version is incorrect:
\begin{align}
f(x) &= $x^2 + 1$ \\
\end{align}
The $ signs try to switch math mode while LaTeX is already processing an aligned math display. That can confuse the parser and lead to an error reported at \end{align} or nearby. Write the equation without the delimiters:
\begin{align}
f(x) &= x^2 + 1 \\
\end{align}
If a row includes ordinary words, put them in \text{...} rather than wrapping the expression in dollar signs:
\begin{align}
f(x) &= x^2 + 1 && \text{for } x > 0.
\end{align}
The \text command is provided by amsmath and lets you include text within a math expression.
Check the lines before the error
When removing inner dollar signs does not fix the problem, inspect the source above the reported line. Look for a $ that opens math mode but never closes it, or an accidental $ that closes math mode too early. Also check braces: a missing } or an extra { can make later commands behave unexpectedly.
Make sure the environment names match exactly. For example, \begin{align*} must end with \end{align*}, not \end{align}. A mismatch often produces a different environment error, but it is still worth checking when editing equation code.
If the error began after adding a line, temporarily remove that line and compile again. Then restore it in smaller pieces. This helps identify the first piece of syntax that causes the problem, rather than making changes at the reported \end{align} and guessing.
Common mistakes
- Adding
$...$around an equation inalign: Remove the dollar signs; the environment already provides math mode. - Treating the error location as the cause: Read several lines above
\end{align}. LaTeX may only detect the problem when it reaches the environment boundary. - Using
alignwithout loadingamsmath: Add\usepackage{amsmath}to the preamble. Without it, LaTeX will report that the environment is undefined; that is a separate error from a missing dollar sign. - Mixing display environments: Do not put
aligninsideequation,\[...\], or another display-math environment. Use one display environment, not nested ones. - Confusing alignment markers with ordinary text: In
align,&marks alignment columns. For words in a formula, use\text{...}; do not place prose in the alignment structure without considering how&and\\are interpreted.
A quick debugging procedure
- Find the first error in the LaTeX log, not just the final message. Later errors may be consequences of the first one.
- Search the affected equation and the lines immediately before it for
$,\[, or\]that do not belong. - Confirm every
\begin{...}has its matching\end{...}and that braces are balanced. - Compile the minimal example above, then add parts of your equation back until the error reappears.
This approach is more reliable than inserting a dollar sign at the location LaTeX names: doing so may hide the symptom while leaving the original syntax error in place.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.