LaTeX error · Math mode

Missing $ inserted.

Quick answer

TeX found something that only works in math mode, such as _, ^, \alpha or \frac, while it was typesetting ordinary text, so it inserted a $ to switch into math. The usual culprit is an unescaped underscore in a file name or variable (data_2024.csv), or a formula typed without $...$. Wrap real math in $...$ and write a literal underscore as \_.

The error in the log

This is how the message appears in the .log file (and in the compile output). The line starting with l. is the line number where TeX noticed the problem; the real mistake is there or just before it.

! Missing $ inserted.
<inserted text> 
                $
l.5 The file is called data_
                            2024.csv and holds x^2 values.

Why it happens

  • An underscore or caret in text: file names, identifiers, URLs or e-mail addresses such as my_file.tex.
  • A math command in text: \alpha, \leq, \frac{1}{2} written without surrounding $.
  • A blank line inside $...$, \[...\] or an equation environment: the paragraph break ends math mode.
  • Math-only commands inside \text{...} or in a section title without $.

How to fix it

Escape characters that are meant as text (\_, \textasciicircum) and put every formula inside $...$ for inline math or \[...\] for display math. For long identifiers or paths, \texttt{data\_2024.csv} or the url package's \path{...} avoids escaping each character.

If the error points into an equation, look for an empty line inside it and delete it.

Broken: reproduces the error

\documentclass{article}

\begin{document}

The file is called data_2024.csv and holds x^2 values.

\end{document}

Try this in Octree — free LaTeX editor with AI, compiles in your browser

Fixed: compiles cleanly

\documentclass{article}

\begin{document}

The file is called data\_2024.csv and holds $x^2$ values.

\end{document}

Related errors

Frequently Asked Questions

How do I type an underscore in LaTeX text?

Write \_. In code or file names, \texttt{my\_file} works, and \url{...} or \path{...} from the url package accept the underscore without escaping.

Why does Missing $ inserted appear in my equation?

Most often there is a blank line inside the equation or align environment. A blank line ends the paragraph, which is not allowed in math, so TeX closes math mode. Remove the empty line or replace it with a % comment line.

Why does \alpha give Missing $ inserted?

Greek letters and most symbols are math-mode commands. Write $\alpha$ in running text. If you need it in a section title or caption, the dollars are needed there too.

Paste your document into Octree — compile errors get a Fix with AI button

When a compile fails, Octree shows the error next to the line that caused it and offers a one-click fix that you can review before applying. Free, nothing to install.

Fix it in Octree →