当指定output_file时,带有定理的R bookdown文档不会呈现

时间:2017-10-25 21:29:29

标签: r latex bookdown

我有一个包含定理块的bookdown文档。 yaml配置是

title: "Test document"
toc: no # table of contents - these are manually defined below so they are put in the right place
lof: no # list of figures
lot: no # list of tables
output:
  bookdown::pdf_book:
    keep_tex: yes 
rmd_files: ["test.Rmd"]
documentclass: article
classoption: a4paper
site: bookdown::bookdown_site
geometry:
  [left=3.17cm,
   right=1.75cm,
   top=2.95cm,
   bottom=5cm]
biblio-style: apalike
link-citations: true

身体是

# The discrete convolution formula 

We present a formula for the distribution of the sum of two random variables in Theorem \@ref(thm:discConvForm).

```{theorem, discConvForm, name = "Discrete convolution formula", echo = TRUE}
Consider two independent discrete random variables $X$ and $Y$ with probability mass functions $f_X$ and $f_Y$ respectively. Let us also assume that $X$ and $Y$ take values from the set of non-negative integers. Then, the random variable $Z = X + Y$ has probability mass function $f_Z$ given by
$$f_Z(z) = f_{X+Y}(z) = P(Z = z) = \sum_{t = 0}^z f_X(t)f_Y(z - t)$$
```

当我运行bookdown::render_book("test.Rmd", output_dir = "output")时,它会渲染得很好。当我运行bookdown::render_book("test.Rmd", output_dir = "output", output_file = "newTest.pdf")时,它会出现以下错误:

/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS _main.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output newTest.tex --table-of-contents --toc-depth 2 --template /Users/alex/Library/R/3.4/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --number-sections --highlight-style tango --latex-engine /Library/TeX/texbin/pdflatex --variable graphics=yes --variable tables=yes --standalone 
/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS _main.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output newTest.pdf --table-of-contents --toc-depth 2 --template /Users/alex/Library/R/3.4/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --number-sections --highlight-style tango --latex-engine /Library/TeX/texbin/pdflatex --variable graphics=yes --variable tables=yes --standalone 
! Undefined control sequence.
l.94 \BeginKnitrBlock

pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43

我调查过生成的.tex个文件。当我在没有指定render_book的情况下运行output_file时,在\begin{document}之前就有一块LaTeX代码指定\BeginKnitrBlock(见下文)。但是,当我在指定render_book的情况下运行output_file时,该块不存在。

有问题的街区:

\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}{Lemma}[section]
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\newtheorem{corollary}{Corollary}[section]
\newtheorem{proposition}{Proposition}[section]
\theoremstyle{definition}
\newtheorem{example}{Example}[section]
\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\let\BeginKnitrBlock\begin \let\EndKnitrBlock\end

我该如何解决这个问题?我希望能够指定输出文件名。

SessionInfo()

R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.4

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] bookdown_0.5.4

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.13    digest_0.6.12   withr_1.0.2     rprojroot_1.2   R6_2.2.2        backports_1.1.1 magrittr_1.5    git2r_0.18.0    evaluate_0.10.1 httr_1.3.1     
[11] stringi_1.1.5   curl_2.8.1      rstudioapi_0.6  rmarkdown_1.6   devtools_1.12.0 tools_3.4.2     stringr_1.2.0   yaml_2.1.14     compiler_3.4.2  memoise_1.1.0  
[21] htmltools_0.3.6 knitr_1.17    

0 个答案:

没有答案