LaTeX troubleshooting

How to Fix “Missing $ Inserted” in LaTeX

Understand math mode, special characters, and unmatched delimiters so you can fix Missing $ inserted without adding random dollar signs.

Summary: Missing $ inserted usually means LaTeX found math-only syntax in ordinary text, or math mode was opened or closed incorrectly. Fix the source context; do not add random dollar signs near the reported line.

Text mode and math mode are different

Ordinary sentences are set in text mode. Mathematical notation belongs in math mode, opened with forms such as $...$, \(...\), or a display environment. Commands and characters can have different meanings in each mode.

% Broken: subscript syntax appears in ordinary text
The value x_1 is the first observation.

% Fixed: put the mathematical expression in math mode
The value $x_1$ is the first observation.

The reported line is where TeX finally notices the conflict. An unmatched delimiter earlier in the paragraph can still be the real cause.

1. Escape underscores in ordinary text

An underscore introduces a subscript in math mode. In a file name, identifier, email-like string, or ordinary prose, print it as \_.

% A variable: use math mode
The model uses $feature_2$.

% A literal file name: escape the underscore
Load the file named results\_final.csv.

If the content is code, a verbatim or code-listing environment may be more appropriate than escaping every special character.

2. Put math-only commands inside math mode

Greek letters, superscripts, subscripts, fractions, and many symbols require math mode.

% Broken
The rate is \alpha and the area is r^2.

% Fixed
The rate is $\alpha$ and the area is $r^2$.

Do not wrap a whole paragraph in dollar signs. Keep the mathematical expression bounded so spacing, fonts, and line breaking remain appropriate for the surrounding prose.

3. Match every math delimiter

A missing closing delimiter can keep LaTeX in math mode. A stray closing delimiter can make it enter or leave math mode at the wrong point.

% Broken: the first expression never closes
The estimate is $x_1 + x_2, and the residual is $r$.

% Fixed
The estimate is $x_1 + x_2$, and the residual is $r$.

Prefer \(...\) for new inline maths when it makes paired delimiters easier to see. Do not mix an opening $ with a closing \).

4. Use text commands correctly inside maths

Words inside an equation should not be written as unstructured math letters. With amsmath, use \text{...} for a short explanation.

\usepackage{amsmath}

\[
  f(x) = 0 \quad \text{when } x < 0
\]

If \text itself is undefined, load amsmath in the preamble. The amsmath package page links to its maintained manual.

5. Check other special characters

The characters below have structural meanings in normal LaTeX source. A problem around them can produce a different error first and a math-mode error later.

Literal characterCommon text formWhy it matters
_\_Subscript marker in math mode
%\%Starts a source comment
&\&Alignment separator in tables and aligned maths
#\#Parameter marker in macro definitions
{ or }\{ or \}Groups command arguments

Why adding a dollar sign can be the wrong fix

TeX says it inserted a dollar sign as part of its own error recovery. That does not mean the correct repair is always to add $ at the reported position. The actual source might need an escaped underscore, a removed stray delimiter, a closed brace, or a properly bounded formula.

A step-by-step check

  1. Go to the first Missing $ inserted message in the log.
  2. Inspect the complete paragraph or command argument around that line.
  3. Look for unescaped underscores and carets in ordinary text.
  4. Pair every $, \(/\), \[/\], and math environment.
  5. Check that math-only commands are inside a deliberately small math expression.
  6. Compile again after one correction and inspect both log and PDF.

Final verification

Once the build succeeds, read the affected sentence in the PDF. Check that prose did not switch to math italics, spaces were not lost, and symbols mean what you intended. If several unrelated messages remain, return to the broader LaTeX compilation error workflow and work from the first remaining cause.