缺少 $ 和 }?

缺少 $ 和 }?

我收到“插入了缺失的 $”和“插入了缺失的 }。额外的 },或者忘记了 \endgroup”

代码如下:

\documentclass{article}

\usepackage{calc}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amssymb}
\begin{document}
\begin{center}

\begin{flushleft}
As is clearly shown in this bar chart that is absolutely,
incontrovertibly, and significantly different from all other
figures shown previously, the doramus bar goes ``Woo!'' because
it can fly, but notice how tidanme is actually quite sad due to a
physical disorder that has prevented it from being taller. The
disruptive selection is clear here though, as sound frequencies
that are really really high (RRH) are very common while sound
frequencies that are really really low (RRL) are common when
added together and multiplying by $(i(2z)+42)$ where $z$ \in
\mathbb{R}\backslash\frac{\pi}{2}.

\end{flushleft}

\end{document}

为什么它会告诉我这些?代码运行正常。谢谢!

答案1

如果我最小化你的例子并运行pdflatex

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\begin{center}

\begin{flushleft}
As is clearly shown in this bar chart that is absolutely,
incontrovertibly, and significantly different from all other
figures shown previously, the doramus bar goes ``Woo!'' because
it can fly, but notice how tidanme is actually quite sad due to a
physical disorder that has prevented it from being taller. The
disruptive selection is clear here though, as sound frequencies
that are really really high (RRH) are very common while sound
frequencies that are really really low (RRL) are common when
added together and multiplying by $(i(2z)+42)$ where $z$ \in
\mathbb{R}\backslash\frac{\pi}{2}.

\end{flushleft}

\end{document}

我确实得到了错误

! Missing $ inserted.
<inserted text> 
                $
l.17 ... multiplying by $(i(2z)+42)$ where $z$ \in

这个错误信息实际上向我展示了问题所在,它是正如 Christian Hupfer 在评论中指出的那样\in

由于\in是数学模式命令,因此需要处于数学模式,这就是为什么$为您插入了缺失值。这就是为什么代码看起来工作正常,缺失值已插入$,您的代码已更正,但您不能依靠它来很好地清除一般情况下的任何错误。然而,如果我们忽略错误并继续前进,在缺失值就位的$情况下,我会得到另一个

! Missing $ inserted.
<inserted text> 
                $
l.20

错误。这是因为第一个缺失部分$已经放进去了,但是开头当然$需要一个结尾部分$,而结尾部分还没有放进去。所以现在它会放一个结尾部分,我们可以继续前进。

然后你又会发现一些错误,我猜,这些错误是由于你忽略了第一个错误,以及

! LaTeX Error: \begin{center} on input line 7 ended by \end{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.23 \end{document}

或者换句话说,你忘记了\end{center}正如 LShaver 在评论中指出的那样。在这种情况下,这些错误可以再次成功纠正,这就是为什么您确实获得了基本正常运行的输出,但一般来说,这不值得依赖。相反,我们需要在遇到错误时修复它们。

我有几个一般性的意见。首先,我们需要将整个数学表达式括在 中$ ... $。实际上,将 括z在中是完全正确的$ ... $,如果您在句子中单独使用数学变量,那么您所得到的就是正确的,例如:

where $z$ is real.

在这里,您使用了正确的逻辑标记来标记出z一个数学对象,它将采用正确的字体,并且您拥有一对内的单个逻辑数学单元的整体$ ... $

但是在你的例子中,数学单位并不以 结尾,z它需要考虑其后的所有内容。许多新用户可能会认为$ ... $这是一种获取特殊符号的黑客手段,但要小心这种诱惑。例如

where z $\in$ $\mathbb{R}$ \textbackslash $\frac{$\pi$}{2}$

是刚接触 LaTeX 的人有时会犯的简单错误。相反,重要的是将其视为$ ... $标记一个逻辑、语义单元,它表示,这是我的数学对象/单元,所有内容都需要放在那里,因为$ ... $它不仅提供特殊符号,还为你设置数学,为你提供适当的间距、适当的字体、适当的字距等等。

因此,我们应该

added together and multiplying by $(i(2z) + 42)$ where $z \in
\mathbb{R} \backslash \frac{\pi}{2}$.

此外,我认为您应该使用\setminus而不是\backslash\setminus在语义上更合乎逻辑,命令名称的作用与它所说的一样,但更重要的是它为您提供了二元运算符周围的正确间距。比较:

\[
  z \in \mathbb{R} \setminus \frac{\pi}{2} \quad \text{and} \quad z
  \in \mathbb{R} \backslash \frac{\pi}{2}
\]

在此处输入图片描述

如果您使用硬包装,正如我在问答中所做的那样,它可以使错误消息(包括行号,例如l.17)更有用,但这是一个选择的问题。

如果你缩进代码,可以更容易地发现诸如\end{environment}缺少

例如,如果我缩进最小化版本的代码,我会得到

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\begin{center}
  \begin{flushleft}
    As is clearly shown in this bar chart that is absolutely,
    incontrovertibly, and significantly different from all other
    figures shown previously, the doramus bar goes ``Woo!'' because it
    can fly, but notice how tidanme is actually quite sad due to a
    physical disorder that has prevented it from being taller. The
    disruptive selection is clear here though, as sound frequencies
    that are really really high (RRH) are very common while sound
    frequencies that are really really low (RRL) are common when added
    together and multiplying by $(i(2z) + 42)$ where
    $z \in \mathbb{R} \setminus \frac{\pi}{2}$.
  \end{flushleft}

\end{document}

我们可以看到有些地方不对,因为我们仍然处于一个缩进级别。您可能还想使用一个可以为您插入完整环境的编辑器,这样您就不会忘记。尝试阅读此列表

应用这些修正后,我们应该不会得到任何错误和良好的输出:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\begin{center}
  \begin{flushleft}
    As is clearly shown in this bar chart that is absolutely,
    incontrovertibly, and significantly different from all other
    figures shown previously, the doramus bar goes ``Woo!'' because it
    can fly, but notice how tidanme is actually quite sad due to a
    physical disorder that has prevented it from being taller. The
    disruptive selection is clear here though, as sound frequencies
    that are really really high (RRH) are very common while sound
    frequencies that are really really low (RRL) are common when added
    together and multiplying by $(i(2z) + 42)$ where
    $z \in \mathbb{R} \setminus \frac{\pi}{2}$.
  \end{flushleft}
\end{center}

\end{document}

在此处输入图片描述

相关内容