首页 > 解决方案 > 无法使用相同的 Rmarkdown 输入输出到 pdf、word 和 HTML

问题描述

所以我希望有一个简单HTMLWord, 和PDF输出到静态R降价文档。它在下面。

该脚本与 Word 和 HTML 很好地结合在一起。但是编织到 pdf 会出现以下错误。

! Package amsmath Error: \begin{align} allowed only in paragraph mode.
Error: LaTeX failed to compile pdfissuesdoubeldollar.tex. See 
https://yihui.org/tinytex/r/#debugging for debugging tips. See 
pdfissuesdoubeldollar.log for more info

现在,我可以同时取出 $$,它会进行 PDF 和 HTML 编织,但 Word 只是跳过了编写方程式。仅使用一美元也无济于事,而且还存在方程式未在页面上居中的问题。

有一些解决方法,例如制作 word 文件,然后使用 acrobat 或将 word 文件另存为 PDF。但我正在尝试自动编织大约 130 个文件,而不必维护两个单独的文件。不必维护单独的文件是我从 MSWord 迁移到 Rmarkdown 的唯一主要原因。我愿意有一个有条件的 R 脚本,有和没有美元,但我怎样才能捕捉到它正在编织的输出格式以及我该怎么做。任何帮助将不胜感激。

Rmarkdown 脚本如下

output:
  pdf_document:
    toc: no
    toc_depth: '4'
  html_document:
    toc: yes
    toc_depth: 4
    toc_float: yes
    theme: readable
  word_document:
    toc: no
    toc_depth: '4'


{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)


$$\begin{align} \in_{a} &= \frac{\text{Approximate Error}}{\text{Present Approximation}}\\ &= \frac{- 0.3830}{9.8800}\\ &= - 0.0388\end{align}$$

标签: rr-markdownpdf-generation

解决方案


通常我总是使用\begin{split}而不是\begin{align}用于 LaTeX 方程。


推荐阅读