Skip to content
Get started

Fix "Missing $ inserted" in LaTeX

This error means LaTeX found something that only works in math mode while it was typesetting normal text. You will learn how to spot it and put the math where it belongs.

./main.tex:3: Missing $ inserted.
l.3 The energy is E = mc^

LaTeX stopped at the end of the l.3 line, so the problem is the ^ just before the break.

  • A superscript ^ or subscript _ in normal text.
  • A math command such as \alpha, \frac or \sum in normal text.
  • An underscore in a word, a file name or a URL, for example my_file.tex.
  • A blank line inside display math (\[ … \] or equation), which ends math mode early.
main.tex (broken)
\documentclass{article}
\begin{document}
The energy is E = mc^2 for a particle at rest.
\end{document}

Wrap the formula in $ … $ for inline math, or \[ … \] for a displayed formula:

main.tex (fixed)
\documentclass{article}
\begin{document}
The energy is $E = mc^2$ for a particle at rest.
\end{document}

If you meant a literal underscore in text, write \_ instead, for example my\_file.tex. For file names and URLs, \texttt{…} with \_, or \url{…} from the url or hyperref package, also works.

The error summary in the Output panel shows the hint “A math-only command or symbol (like ^, _ or \alpha) is outside math. Wrap it in $…$.”

In the editor toolbar, Inline math inserts $…$ and Display math inserts \[…\]. You can also press Ctrl+M (Cmd+M on Mac) for inline math. See Keyboard shortcuts.

Not on Luzbase yet? It compiles LaTeX in your browser and links each error to its line, often with the fix. Start writing free.