Closed perlatex closed 3 years ago
这个问题出现的原因是,我默认了会用到数学环境。如果不用数学环境,可以将 .Rprofile 里面 option(bookdown.post.latex
里面的内容删除。
如果不确定之后是否会用到数学环境,可以将这一段移删除,而在 index.Rmd 的 yaml 之后,添加下面的内容:
```{r modify-latex, include = FALSE}
options(bookdown.post.latex = function(x) {
# x is the content of the LaTeX output file
# The following codes is another way to removes amsthm environments
start_row <- grep("package\\{amsthm", x)
end_row <- grep("newtheorem\\*\\{solution", x)
if (length(start_row) > 0) {
x <- x[-c(start_row:end_row)]
# Remove \iffalse \fi\\
x <- gsub("^\\\\iffalse.\\\\fi\\{\\}+?(\\\\)", "", x)
x <- gsub("^\\\\tightlist", "", x)
# fix theorem environments for elegantbook. Remove or modify if other book classes are using!!!
x <- gsub("(^\\\\BeginKnitrBlock\\{)+(definition|axiom|theorem|lemma|corollary|proposition|postulate)+(\\}$)", "\\1\\2\\3\\{\\}\\{\\}", x)
x <- gsub("(^\\\\BeginKnitrBlock\\{)+(definition|axiom|theorem|lemma|corollary|proposition|postulate)+(\\})+\\[(.*)\\]", "\\1\\2\\3\\{\\4\\}\\{\\}", x)
x <- gsub("(^\\\\\begin\\{)+(definition|axiom|theorem|lemma|corollary|proposition|postulate)+(\\}$)", "\\1\\2\\3\\{\\}\\{\\}", x)
x <- gsub("(^\\\\begin\\{)+(definition|axiom|theorem|lemma|corollary|proposition|postulate)+(\\})+(.*)", "\\1\\2\\3\\{\\4\\}\\{\\}", x)
}
})
由于水平有限,不知道怎么在 .Rprofile 里用 if 语法。
Thanks
黄湘云老师和叶飞老师开发的ElegantBookdown 包很漂亮,兼顾了很多功能需求。但使用过程中,发现 theorem-block 必须要保留一个, 比如{lemma},否则,会报错
` Error in start_row:end_row : argument of length 0 Calls: ... render_new_session -> -> -> post
Execution halted
Exited with status 1. `
注意到@hongtaoh 郝鸿涛也有类似疑问(https://hongtaoh.com/cn/2020/05/26/bookdown-tips/)