Mathjax 无法在 github 上正确呈现 pmatrix

Mathjax does not render pmatrix correctly on github

提问人:Grant Curell 提问时间:10/31/2023 最后编辑:Grant Curell 更新时间:11/1/2023 访问量:33

问:

我在一些 markdown 中使用以下代码:

$$
PE_{\text{input}} = 
\begin{pmatrix}
0 & 1 & 0 & 1 \\
\sin\left(\frac{1}{10000^0}\right) & \cos\left(\frac{1}{10000^{0.5}}\right) & \sin\left(\frac{1}{10000^2}\right) & \cos\left(\frac{1}{10000^{2.5}}\right) \\
\sin\left(\frac{2}{10000^0}\right) & \cos\left(\frac{2}{10000^{0.5}}\right) & \sin\left(\frac{2}{10000^2}\right) & \cos\left(\frac{2}{10000^{2.5}}\right)
\end{pmatrix}
=
\begin{pmatrix}
0 & 1 & 0 & 1 \\
0.8415 & 0.99995 & 0.0001 & 1 \\
0.9093 & 0.9998 & 0.0002 & 1
\end{pmatrix}
$$

它在 markdown 中合二为一地正确呈现,当我通过语法检查器时,我找不到任何错误。在 Markdown All in One 预览版中:

enter image description here

但是,它会导致 markdown all in one 的 TOC 功能中断,并且在 GitHub 上呈现如下:

enter image description here

我无法找出它的问题所在。我尝试删除左/右,分离两个矩阵,并弄乱字符串,但结果总是一样的。

在线语法检查:

enter image description here

试图逃避反斜杠

尝试使用此答案中显示的技术

$$
PE_{\text{input}} = 
\begin{pmatrix}
0 & 1 & 0 & 1 \\\\
\sin\left(\frac{1}{10000^0}\right) & \cos\left(\frac{1}{10000^{0.5}}\right) & \sin\left(\frac{1}{10000^2}\right) & \cos\left(\frac{1}{10000^{2.5}}\right) \\\\
\sin\left(\frac{2}{10000^0}\right) & \cos\left(\frac{2}{10000^{0.5}}\right) & \sin\left(\frac{2}{10000^2}\right) & \cos\left(\frac{2}{10000^{2.5}}\right)
\end{pmatrix}
=
\begin{pmatrix}
0 & 1 & 0 & 1 \\\\
0.8415 & 0.99995 & 0.0001 & 1 \\\\
0.9093 & 0.9998 & 0.0002 & 1
\end{pmatrix}
$$

尝试此操作时,输出保持不变。

GitHub Markdown MathJax

评论

0赞 Davide Cervone 10/31/2023
这与这篇文章的问题相同,请参阅我的答案。请注意,在 HTML 页面中,' 但他 Markdown 处理。您可以改用“\\\”来克服该问题。\` in your original have been turned into
0赞 Davide Cervone 10/31/2023
这回答了你的问题吗?MathJax 不允许在 GitHub Pages 上进行多行内联数学运算
0赞 Grant Curell 11/1/2023
@DavideCervone - 消极的。我只是试一试反斜杠技巧,结果是一样的。我用 \\\\ 替换了 \\ 的所有实例
0赞 Grant Curell 11/1/2023
@DavideCervone我无法让带有双转义的多线工作,但你确实让我朝着正确的方向前进。请参阅下面的答案,了解我必须做些什么才能使其工作。
0赞 Grant Curell 11/1/2023
@DavideCervone您可能会发现答案中的更新很有趣。这似乎也与执行 pmatrix 命令的附加命令有关。

答:

1赞 Grant Curell 11/1/2023 #1

这就是最终对我有用的东西。我更新了代码,使其全部适合一行,并使用三个 \ (\) 来生成矩阵:

$$ PE_{\text{input}} = \begin{pmatrix} 0 & 1 & 0 & 1 \\\ \sin\left(\frac{1}{10000^0}\right) & \cos\left(\frac{1}{10000^{0.5}}\right) & \sin\left(\frac{1}{10000^2}\right) & \cos\left(\frac{1}{10000^{2.5}}\right) \\\ \sin\left(\frac{2}{10000^0}\right) & \cos\left(\frac{2}{10000^{0.5}}\right) & \sin\left(\frac{2}{10000^2}\right) & \cos\left(\frac{2}{10000^{2.5}}\right) \end{pmatrix} = \begin{pmatrix} 0 & 1 & 0 & 1 \\\ 0.8415 & 0.99995 & 0.0001 & 1 \\\ 0.9093 & 0.9998 & 0.0002 & 1 \end{pmatrix} $$

@DavideCervone是对的 - 这绝对是 \s 的东西,但我无法通过在多行版本上转义它们来修复它。

更新

我还注意到,如果它先出现,这就会起作用。

$$
W_O = 
\begin{pmatrix}
0.37738326 & 0.83274845 & 0.37280978 & 0.14584743 \\\\
0.28706851 & 0.29072609 & 0.69116998 & 0.20106682 \\\\
0.26764653 & 0.12058646 & 0.82634382 & 0.60818759 \\\\
0.44329703 & 0.4425581  & 0.89811744 & 0.24551412 \\\\
0.9186323  & 0.40029736 & 0.17636762 & 0.06896409 \\\\
0.41921272 & 0.0495383  & 0.77792527 & 0.4354529  \\\\
0.14791365 & 0.66822966 & 0.48313699 & 0.94127396 \\\\
0.11604641 & 0.51794357 & 0.62942357 & 0.76420883
\end{pmatrix}
$$

但是,它后面的这段代码没有。

$$
\text{Concat}(\text{Attention}_1, \text{Attention}_2)\times W_{O}=
\text{MultiHead}(Q,K,V)=
\begin{pmatrix}
4.42554033 & 5.589241 & 6.99844643 & 4.79288192 \\\\
4.55176485 & 5.6122494 & 7.09923364 & 4.82144704 \\\\
4.21254506 & 5.31988824 & 6.84520426 & 4.79017392
\end{pmatrix}
$$

将它们都放在一条线上可以解决它。

因此,似乎也与其他命令有一些交互。

评论

0赞 Davide Cervone 11/2/2023
任何一行的末端是否有空格?Markdown 使用两个空格来指示强制换行,这可能会导致问题。此外,第二个有多个下划线,Markdown 将其用作斜体的分隔符,并且会在数学中插入或类似的标签,使 MathJax 忽略它。从浏览器查看页面源代码,看看数学中间是否有任何 HTML 标记。<emph>