jupyter notebook 在转换为 pdf 期间崩溃乳胶

jupyter notebook crashes latex during conversion to pdf

当我尝试在 jupyter notebook markdown 单元格中编写数学函数时,在使用 Latex 转换为 PDF 期间,它给出了数百行不完整且不可读的错误消息。如果我删除这个数学函数,即使使用其他数学函数,它也能正常工作。似乎与试图阅读此内容的乳胶发生了一些奇怪的互动。有人能看出原因吗?

$$
m_{M,n}(x;\Theta_{1},..,\Theta_{M},D_{n}) = \left\{
    \begin{array}\
        1 & if \frac{1}{M} \sum \limits _{j=1} ^{M} m_{n}(x;\Theta_{j},D_{n}) > 1/2 \
        0 & otherwise
    \end{array}
\right.
$$

The output is supposed to look like this

您的 LaTeX 代码无效。 array 环境期望传递对齐参数,例如 \begin{array}{ll} 两列左对齐。

此外,第一行的 \ 根本没有必要。

工作代码为:

$$
    m_{M,n}(x;\Theta_{1},..,\Theta_{M},D_{n}) = \left\{
        \begin{array}{ll}
            1 & \mathrm{if}\; \frac{1}{M} \sum \limits _{j=1} ^{M}  m_{n}(x;\Theta_{j},D_{n}) > 1/2 \
            0 & \mathrm{otherwise}
        \end{array}
    \right.
$$

Result:

但为什么它在 Jupyter Notebook 中有效?

这是因为 Jupyter Notebook 使用 MathJax,另一个 TeX 实现,当您不通知 array 的对齐时,默认情况下使用 cc。因此,Jupyter Notebook(或 MathJax)真的不在乎您的代码是否缺少它。

然而,在 LaTeX 方面,情况就完全不同了。在 LaTeX 中,任何通过 {} 传递的参数都是必需的(与 [] 相对,后者是可选的),因此当您编写 \begin{array}\ 时,TeX 会尝试扩展 \ 标记作为对齐参数,这显然会引发错误(首先是因为 \ 不是预期的,然后是因为您只传递了一个参数并试图使用两列)。