Tx · LaTeX & TikZ

How to Fix “Missing } Inserted” in an align* Environment

Published By the 9to5Science editorial team

At a glance

  1. 1. Check the first error

    Read the first LaTeX error and inspect the reported line plus the few lines before it.

  2. 2. Match braces and commands

    Check every opening brace and the arguments of commands such as \frac, \sqrt, and \text.

  3. 3. Check alignment syntax

    Use & to mark alignment points and \\ to end rows; do not wrap align* in dollar signs.

  4. 4. Compile a small example

    Temporarily reduce the equation, then restore pieces until the error returns.

The LaTeX message ! Missing } inserted. means TeX reached a point where it expected a closing brace or otherwise could not make sense of the current group. In an align* environment, the cause is often an unmatched { in an equation or an incomplete argument to a command such as \frac or \text. The line named in the log is a clue, not necessarily the exact location of the mistake.

The align* environment comes from the amsmath package. It is already a math environment, so you should not put $...$, \[...\], or another display-math environment around it.

What the error means

TeX uses braces to group text and to delimit many command arguments. For example, \frac{a}{b} has two braced arguments. If one opening brace is never matched, TeX may continue reading later material as part of that argument. Depending on where TeX detects the problem, it may try to recover by inserting a closing brace, producing this message; an unclosed argument can instead lead to a runaway-argument or end-of-file diagnostic. The error can appear on a later line because TeX may not realize the input is malformed until it encounters a command, alignment marker, or end of environment that cannot be interpreted in the current context. Look at the reported line and the preceding lines, especially where a command argument begins.

Check braces and command arguments

Count opening and closing braces in the affected expression. Each { should have a matching } unless it is escaped as a literal brace with \{ or \}. Also check that each command has all of its required arguments:

  • \frac{numerator}{denominator} needs two arguments.
  • \sqrt{expression} needs one argument; an optional index goes in square brackets, as in \sqrt[3]{x}.
  • \text{words} needs its closing brace before the next part of the equation.

For example, this line is missing the closing brace for \text:

\begin{align*}
  f(x) &= x^2 + \text{a constant
\end{align*}

Correct it by closing the argument:

\begin{align*}
  f(x) &= x^2 + \text{a constant}
\end{align*}

If you intend to show curly braces as mathematical symbols rather than group content, escape them: write \{ and \}. A literal brace should not be used as an unescaped grouping character.

Verify the align* structure

In align*, & identifies the point where rows should line up, and \\ ends a row. A typical two-line derivation is:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align*}
  (x+1)^2 &= x^2 + 2x + 1 \\
          &= x(x+2) + 1
\end{align*}
\end{document}

This complete example compiles with a standard LaTeX installation. Each row has one alignment point, before the equals sign. The second row begins with & so its equals sign lines up with the first one. The first row ends with \\; the final row normally does not need one.

An incorrect number of alignment markers usually produces an alignment-related error rather than Missing } inserted, but alignment syntax can make an existing brace mistake harder to spot. Check that an & is intended as a column separator. To print an ampersand in text, use \&.

A reliable debugging method

  1. Start with the first error in the compiler log. Later messages may be consequences of the first one.
  2. Inspect the affected row and the rows immediately before it. Find every command that begins an argument and make sure its braces close.
  3. Temporarily remove part of the equation or replace it with a short expression. If the smaller version compiles, add the removed material back in small pieces.
  4. Check for an accidental $, \[, or nested math environment around align*. The environment itself switches into display math.
  5. Recompile after each change. This confirms whether the edit fixed the cause or merely moved the reported error.

A minimal test is often more useful than scanning a long document. Copy the suspect equation into a small file with \documentclass{article}, \usepackage{amsmath}, and a document environment. This also helps separate an equation error from unrelated problems elsewhere in the file.

Common mistakes

  • Fixing only the line named in the log. The missing brace may be several lines earlier, where a command argument began.
  • Adding a brace without checking its scope. A closing brace in the wrong place can make the current error disappear while changing the meaning of the equation.
  • Putting align* inside \\[...\\] or $...$. align* is already a display-math environment.
  • Using & for a printed ampersand. Use \\& for the symbol in ordinary text; reserve bare & for alignment.
  • Assuming every problem in an alignment is a brace problem. If the braces are balanced, inspect command names, special characters, and whether an environment was opened and closed correctly.

If the brace count and alignment structure look right, check the commands in the failing row and read a few more lines of the log for context. TeX’s recovery message describes what it tried to do, not always the precise edit you need.

References

  1. The amsmath package
  2. LaTeX2e: An unofficial reference manual

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.