在LaTeX中收到错误"Missing $ inserted"

Esp*_*sen 174 latex

我尝试在乳胶中写下以下内容:

\begin{itemize}
    \item \textbf{insert(element|text)} inserts the element or text passed at the start of the selection.
    \item \textbf{insert_after(element|text)} inserts the element or text passed at the end of the selection.
    \item \textbf{replace(element|text)} replaces the selection with the passed text/element.
    \item \textbf{delete()} deletes the selected text.
    \item \textbf{annotate(name,value)} annotates the selected text with the passed name and value-pair. This can either be a hidden meta-data about the selection, or can alter the visible appearance.
    \item \textbf{clear_annotation()} removes any annotation for this specific selection.
    \item \textbf{update_element(value)} performs an update of the element at the selection with the passed value.
\end{itemize}
Run Code Online (Sandbox Code Playgroud)

出于某种原因,我得到了一堆错误.我认为使用"插入"这个词有一些东西.我收到"Missing $ inserted"之类的错误,所以似乎解析试图在我的部件上修复一些"错误".我是否需要逃避"插入"之类的词语,我该怎么做?

Wil*_*den 319

"Missing $ inserted"可能是由下划线和条形引起的.LaTeX中的这些字符在数学模式中具有特殊含义(由$字符分隔).试着逃避它们; 例如,update\_element而不是update_element.

但是,如果您正在尝试显示代码,则更好的解决方案是使用该\verb命令,该命令将以等宽字体排版文本,并将自动正确处理下划线和条形(无需使用它们进行转义\).

  • 我遇到此错误是因为我的参考书目中的标题之一中有“$”符号。使用“\$”有帮助。 (2认同)

Nie*_*jou 42

它实际上是下划线.请\_改为使用,或包含下划线包.


Utk*_*mir 17

我也有这个问题.我通过删除方程标签之间不必要的空白行来解决它.这给出了错误:

\begin{equation}
P(\underline{\hat{X}} | \underline{Y}) = ...

\end{equation}
Run Code Online (Sandbox Code Playgroud)

而这段代码成功编译:

\begin{equation}
P(\underline{\hat{X}} | \underline{Y}) = ...
\end{equation}
Run Code Online (Sandbox Code Playgroud)


小智 6

另外,我有这个问题但是bib文件不会重新编译.我删除了问题,这是注释字段中的下划线,并再次编译tex文件,但仍然得到相同的错误.最后我得到了编译后的bib文件(我认为是.bbl)并且运行正常.我不得不使用反斜杠逃避_.


小智 5

我遇到了同样的问题-我已经阅读了所有这些答案,但不幸的是,没有一个对我有用。最终我尝试删除此行

%\usepackage[latin1]{inputenc}
Run Code Online (Sandbox Code Playgroud)

并且所有错误都消失了。