为什么在使用 rmarkdown 和 bookdown 时包含带有乳胶方程式环境的外部 Rmd 文件会导致不同的 DOCX 输出?
Why inclusion of external Rmd-file with latex equation environment leads to different DOCX output while using rmarkdown and bookdown?
下面是我使用最新的 RStudio 编织成 MS Word 文档的最简单的 Rmd 文件:
---
output:
word_document: default
bookdown::word_document2: default
---
```{sh, echo=FALSE, comment=''}
cat ~/latex-test.Rmd
```
~/latex-test.Rmd
内容如下:
Auto-numbered equation:
$$ f(x) = \sin(x) $$
---
LaTeX equation without label (using `\begin{equation}...\end{equation}`)
\begin{equation}
h(z) = \sinh(z)
\end{equation}
---
LaTeX equation with bookdown-supported label (using `\begin{equation}...(\#eq:label)\end{equation}`)
\begin{equation}
f\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k}
(\#eq:binom)
\end{equation}
---
LaTeX equation with Xaringan-supported label (using `\begin{equation}...\label{label}\end{equation}`):
\begin{equation}
g\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k}
\label{binom2}
\end{equation}
编织到 word_document: default
给出的 docx 文件内容与 ~/latex-test.Rmd
.
中包含的内容完全相同
所以我不会在这里包含它以保存 space.
但是编织到 bookdown::word_document2: default
会产生额外的 $$...$$
环绕 equation
环境:
(我已经手动突出显示了意想不到的 $$
)
为什么会这样?我究竟做错了什么?这是一个错误吗?
备注:
html_document: default
和bookdown::html_document2: default
的输出相等且正确。
odt_document: default
和 bookdown::odt_document2: default
的输出也不正确。
这是 bookdown 中 I just fixed 在 Github 上的错误。您可以通过 remotes::install_github('rstudio/bookdown')
.
尝试 bookdown 的开发版本
下面是我使用最新的 RStudio 编织成 MS Word 文档的最简单的 Rmd 文件:
---
output:
word_document: default
bookdown::word_document2: default
---
```{sh, echo=FALSE, comment=''}
cat ~/latex-test.Rmd
```
~/latex-test.Rmd
内容如下:
Auto-numbered equation:
$$ f(x) = \sin(x) $$
---
LaTeX equation without label (using `\begin{equation}...\end{equation}`)
\begin{equation}
h(z) = \sinh(z)
\end{equation}
---
LaTeX equation with bookdown-supported label (using `\begin{equation}...(\#eq:label)\end{equation}`)
\begin{equation}
f\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k}
(\#eq:binom)
\end{equation}
---
LaTeX equation with Xaringan-supported label (using `\begin{equation}...\label{label}\end{equation}`):
\begin{equation}
g\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k}
\label{binom2}
\end{equation}
编织到 word_document: default
给出的 docx 文件内容与 ~/latex-test.Rmd
.
中包含的内容完全相同
所以我不会在这里包含它以保存 space.
但是编织到 bookdown::word_document2: default
会产生额外的 $$...$$
环绕 equation
环境:
(我已经手动突出显示了意想不到的 $$
)
为什么会这样?我究竟做错了什么?这是一个错误吗?
备注:
html_document: default
和bookdown::html_document2: default
的输出相等且正确。odt_document: default
和bookdown::odt_document2: default
的输出也不正确。
这是 bookdown 中 I just fixed 在 Github 上的错误。您可以通过 remotes::install_github('rstudio/bookdown')
.