Let
X
Journal

Fix 'Missing $ Inserted' & Math-Mode Errors in LaTeX

SPECIMEN IDLETX-SPEC-FIX-
DATE RECORDEDJun 4, 2026
READING COMPLEXITY2 min read
TAG INDEX
latexerrorsmathdebugging
Document Abstract

'Missing $ inserted' means you used a math command outside math mode. Wrap the expression in $...$ or fix an unclosed dollar sign. Full causes and fixes inside.

"Missing $ inserted" means you used a math-mode command or character outside math mode — typically a stray _, ^, \alpha, or \frac in normal text, or an unclosed $. The fix is to wrap the expression in $...$ (inline) or \[...\] (display), or to close the dollar sign you left open. Here's every cause and how to spot it.

The fix in one line

% WRONG — math command in text:
The variable x_1 equals 5.
% RIGHT:
The variable $x_1$ equals 5.

Any _, ^, Greek letter, \frac, \sum, or other math command must live inside math mode.

The common triggers

| What you wrote | Why it errors | Fix | |---|---|---| | x_1 in text | _ is subscript (math only) | $x_1$ | | 2^n in text | ^ is superscript (math only) | $2^n$ | | \alpha in text | Greek is math only | $\alpha$ | | my_file in text | literal _ | \_ or \texttt{my\_file} | | $x = 5 (no close) | unclosed $ | add closing $ | | 50% then math | % started a comment | escape as 50\% |

The underscore trap

Writing a filename or variable like my_file in normal text is the most common cause, because _ means subscript. Print a literal underscore with \_, or wrap a code-style name in \texttt{my\_file}. The underscore package makes _ literal in text if you use them often.

Finding the culprit line

Read the l.<number> line in the output — the math character just before the break is usually it. But an unclosed $ makes LaTeX blame a line far below the real mistake, so also scan upward for a $ that was opened and never closed. Comment out paragraphs with % to bisect quickly.

Display math and equations

For standalone equations use \[...\] or the equation environment, not a sentence with bare commands — see the full math equations guide and the symbols reference. This error is #2 on our common LaTeX errors list.

→ See math-mode errors flagged inline as you type in LetX.


Written by Shihab Shahriar Antor — AI Engineer & Founder of Shahriar Labs, maker of LetX.

Frequently Asked Questions

What exactly triggers 'Missing $ inserted'?

LaTeX raises it when it sees a character or command that only works in math mode while in normal text mode — most often a lone underscore (_), caret (^), or a command like \alpha, \frac, or \sum used outside dollar signs. It also fires when a $ is left unclosed, so LaTeX reaches the end of the paragraph still expecting math. The fix is to wrap the expression in $...$ or to add the missing closing $.

Why do underscores in filenames or text cause this error?

The underscore is the subscript operator and is only valid in math mode, so writing my_file in normal text triggers 'Missing $ inserted'. To print a literal underscore in text, escape it as \_ , or use \texttt{my\_file} for a code-style name. The underscore package also lets _ behave as a literal in text. This is one of the most common beginner errors when typing file paths or variable names.

How do I find which line caused the missing-$ error?

Read the l.<number> line in the error output — it shows the text up to the break, and the math-mode character or command just before it is the cause. Because an unclosed $ can make LaTeX blame a line far below the real mistake, also scan upward for a dollar sign that was opened but never closed. Commenting out paragraphs with % to bisect the document quickly isolates a stray $.