Getting Started
Text Formatting
Mathematical Expressions
Document Structure
Page Layout
Errors & Troubleshooting
Missing $ Inserted: Fixing LaTeX's Most Confusing Error
Missing $ inserted means TeX found something that only works in math mode — an underscore, a caret, a command like \frac — while it was typesetting ordinary text. Nearly always the culprit is a bare underscore in prose: file_name.txt, my_variable, a snake_case identifier pasted from code. Escape it as \_ and the error disappears.
Why the reported line is often wrong
This error is confusing because of how TeX recovers from it. When TeX hits a math-only token in text mode, it doesn't stop. It inserts the missing $ for you and carries on — which silently switches the rest of your paragraph into math mode. Words get typeset as strings of variables, spaces vanish, and TeX only raises the error when something downstream becomes impossible, often at the end of the paragraph.
So the line number in the error is where TeX gave up, not where you made the mistake. When the reported line looks innocent, search backwards from it for a bare _, a bare ^, or a $ that never got closed. The real mistake is almost always above.
Cause 1: a bare underscore in text
The classic. Underscore means subscript, and subscripts only exist in math mode:
My recommendation: use \verb or \url for anything that came out of a computer. They neutralize every special character at once, so the same file name won't break again next time it contains a % or #. Escaping characters one at a time is whack-a-mole.
Cause 2: a bare ^ in text
Same story, other direction. ^ means superscript and is math-only:
Cause 3: an unclosed $
Every $ toggles math mode. Lose one, and everything after it is interpreted in the wrong mode until TeX falls over:
These are painful to spot by eye in a long paragraph. Cheap trick: comment out half the paragraph and recompile. Error gone? The stray $ is in the commented half. Repeat. You'll corner it in three or four compiles.
Cause 4: math commands outside math mode
\frac, \alpha, \sum, \infty — all math-only. Used in prose, TeX inserts the $ and the sentence comes out mangled even when it compiles:
Cause 5: a blank line inside display math
The sneaky one. A blank line is a paragraph break, and paragraph breaks are illegal inside display math. People add one for readability in the source and get Missing $ inserted pointing at the equation:
Want breathing room in the source anyway? End the line with %. A comment-only line is not a paragraph break, so it's safe inside math environments.
Frequently asked questions
What causes the 'Missing $ inserted' error in LaTeX?
TeX met a character or command that is only legal in math mode — most often a bare underscore or ^, or a command like \frac or \alpha — while it was in text mode. It inserts a $ to recover, which starts math mode where you never intended it, and the rest of the paragraph breaks.
Why does the error point to a line far from my actual mistake?
Because TeX silently opened math mode at the real mistake and kept reading. It only reports an error when something later becomes impossible to typeset — often at the next blank line or paragraph end. Search backwards from the reported line for a stray _, ^, or an unclosed $.
How do I write an underscore in normal text without an error?
Escape it: \_ prints a literal underscore in text mode. For file names and identifiers, \verb|file_name.txt| or \url{...} from the hyperref package are better — they also survive other special characters and allow line breaks in URLs.
Why does a blank line inside my equation cause 'Missing $ inserted'?
Blank lines mean paragraph breaks, and paragraph breaks are forbidden inside display math. TeX bails out of the math and complains. Delete the blank line, or use % at the end of a line if you want visual spacing in the source without a paragraph break.
Missing $ Inserted: Fixing LaTeX's Most Confusing Error
Missing $ inserted means TeX found something that only works in math mode — an underscore, a caret, a command like \frac — while it was typesetting ordinary text. Nearly always the culprit is a bare underscore in prose: file_name.txt, my_variable, a snake_case identifier pasted from code. Escape it as \_ and the error disappears.
Why the reported line is often wrong
This error is confusing because of how TeX recovers from it. When TeX hits a math-only token in text mode, it doesn't stop. It inserts the missing $ for you and carries on — which silently switches the rest of your paragraph into math mode. Words get typeset as strings of variables, spaces vanish, and TeX only raises the error when something downstream becomes impossible, often at the end of the paragraph.
So the line number in the error is where TeX gave up, not where you made the mistake. When the reported line looks innocent, search backwards from it for a bare _, a bare ^, or a $ that never got closed. The real mistake is almost always above.
Cause 1: a bare underscore in text
The classic. Underscore means subscript, and subscripts only exist in math mode:
My recommendation: use \verb or \url for anything that came out of a computer. They neutralize every special character at once, so the same file name won't break again next time it contains a % or #. Escaping characters one at a time is whack-a-mole.
Cause 2: a bare ^ in text
Same story, other direction. ^ means superscript and is math-only:
Cause 3: an unclosed $
Every $ toggles math mode. Lose one, and everything after it is interpreted in the wrong mode until TeX falls over:
These are painful to spot by eye in a long paragraph. Cheap trick: comment out half the paragraph and recompile. Error gone? The stray $ is in the commented half. Repeat. You'll corner it in three or four compiles.
Cause 4: math commands outside math mode
\frac, \alpha, \sum, \infty — all math-only. Used in prose, TeX inserts the $ and the sentence comes out mangled even when it compiles:
Cause 5: a blank line inside display math
The sneaky one. A blank line is a paragraph break, and paragraph breaks are illegal inside display math. People add one for readability in the source and get Missing $ inserted pointing at the equation:
Want breathing room in the source anyway? End the line with %. A comment-only line is not a paragraph break, so it's safe inside math environments.
Frequently asked questions
What causes the 'Missing $ inserted' error in LaTeX?
TeX met a character or command that is only legal in math mode — most often a bare underscore or ^, or a command like \frac or \alpha — while it was in text mode. It inserts a $ to recover, which starts math mode where you never intended it, and the rest of the paragraph breaks.
Why does the error point to a line far from my actual mistake?
Because TeX silently opened math mode at the real mistake and kept reading. It only reports an error when something later becomes impossible to typeset — often at the next blank line or paragraph end. Search backwards from the reported line for a stray _, ^, or an unclosed $.
How do I write an underscore in normal text without an error?
Escape it: \_ prints a literal underscore in text mode. For file names and identifiers, \verb|file_name.txt| or \url{...} from the hyperref package are better — they also survive other special characters and allow line breaks in URLs.
Why does a blank line inside my equation cause 'Missing $ inserted'?
Blank lines mean paragraph breaks, and paragraph breaks are forbidden inside display math. TeX bails out of the math and complains. Delete the blank line, or use % at the end of a line if you want visual spacing in the source without a paragraph break.
Getting Started
Text Formatting
Mathematical Expressions
Document Structure
Page Layout
Errors & Troubleshooting
