我正在使用knit2pdf("book.Rnw", quiet=TRUE)在RStudio下编译一个图书项目。编织步骤需要很长时间(我还没有使用缓存),当有新的引用、数字、交叉引用等时,即使.Rnw文件没有改变,也要经过几次传递才能解决它们。
我想要的是knit2pdf的等效或扩展,它允许knit=FALSE抑制.tex文件的重新生成,或者有一个选项latex.passes=请求额外的tools::texi2pdf运行。
我看过knit2pdf中的代码,它有点不透明,不允许为这个功能提供一个简单的修补程序。
发布于 2014-02-25 00:32:16
knit2pdf所做的就是生成一个.tex文件,然后调用tools:texi2pdf。如果您要寻找的knit2pdf版本不首先生成.tex文件,那么它就是tools::texi2pdf。
使用stringr::str_replace,我做了这样的事情,并发现它足够了:
knit2pdf_mod <- function(rnw_file) {
knit2pdf(rnw_file, compiler = "xelatex")
texi2pdf(file = str_replace(rnw_file, pattern = "Rnw", replacement = "tex"))
}您可以添加一个for循环,以便尽可能多地重复texi2pdf步骤。
knit2pdf_mod <- function(rnw_file, latex.passes = 1) {
knit2pdf(rnw_file, compiler = "xelatex")
for (i in 1:latex.passes) {
texi2pdf(file = str_replace(rnw_file, pattern = "Rnw", replacement = "tex"))
}
}https://stackoverflow.com/questions/22000964
复制相似问题