LaTeX error "Command \item invalid in math mode": cause and fix
A command that only works in text was read while math mode was on. Usually math mode is on by accident, because a $ earlier in the paragraph has no partner.
Why it happens
- A dollar sign is meant as a currency sign and written as
$without a backslash. Everything up to the next$becomes math, including the next\item. - A formula is missing its closing
$. - A text accent such as
\'eor\"uis used inside a formula. LaTeX then prints the warning "Command \' invalid in math mode" followed by the error "Please use \mathaccent for accents in math mode". - A font size command such as
\largeis used inside a formula. This only gives the warning "Command \large invalid in math mode", and the size does not change.
How to fix it
- Write a dollar sign in text as
\$. - Look for the
$without a partner in the lines before the one the log names. - In formulas use the math accents:
\acute{e},\ddot{u},\hat{x},\tilde{n}. - For words inside a formula use
\text{...}fromamsmath. See Text in math mode in LaTeX.
A document that produces the message
\documentclass{article}
\begin{document}
\begin{itemize}
\item A ticket costs 5$ per person.
\item Children pay half.
\end{itemize}
\end{document}The corrected document
\documentclass{article}
\begin{document}
\begin{itemize}
\item A ticket costs 5\$ per person.
\item Children pay half.
\end{itemize}
\end{document}Both documents were compiled with pdfLaTeX from TeX Live 2023. The first produces the message, the second compiles without an error.
Finding the line in the editor
The editor lists every error and warning of a compile run with file and line. Select an entry and the cursor jumps to that line. See Error list with jump to the line.