Getting the error "Missing $ inserted" in LaTeX
It's actually the underscores. Use \_
instead, or include the underscore package.
I had this problem too. I solved it by removing the unnecessary blank line between equation tags. This gives the error:
\begin{equation}
P(\underline{\hat{X}} | \underline{Y}) = ...
\end{equation}
while this code compiles succesfully:
\begin{equation}
P(\underline{\hat{X}} | \underline{Y}) = ...
\end{equation}
The "Missing $ inserted" is probably caused by the underscores and bars. These characters in LaTeX have special meaning in math mode (which is delimited by $
characters). Try escaping them; e.g. update\_element
instead of update_element
.
However, if you're trying to display code, a better solution would be to use the \verb
command, which will typeset the text in a monospaced font and will automatically handle underscores and bars correctly (no need to escape them with \
).