【问题标题】:Cannot add tikz code snippet in my .Rmd post using blogdown无法使用 blogdown 在我的 .Rmd 帖子中添加 tikz 代码片段
【发布时间】:2019-02-23 07:48:40
【问题描述】:

我刚刚开始使用blogdown,并使用模板Hugo-Xmin 创建了一个项目。在 RStudio 中,在 blogdown 中创建项目时,它创建了一些预定义的帖子,我正在编辑这个:

/content/post/2015-07-23-r-rmarkdown.Rmd

添加 tikz 图片

this questionbookdown documentation on engines之后,我通过添加这个sn-p修改了上述文件:

This is a tikz picture:

```{r, echo=FALSE, engine='tikz', out.width='90%', fig.ext=if (knitr:::is_latex_output()) 'pdf' else 'png', fig.cap='Some caption.'}
\begin{tikzpicture}[scale=.7]
\draw [fill=gray!30,very thick] (0,-1) rectangle (5,1);
\draw [very thick] (5, 0) -- (13,0);
\node [below] at (2,-1) {\large Hello};
\node [below, align=center] at (0,-1) {\large Two\\ lines};
\end{tikzpicture}
```

帖子处理失败

一旦我保存(因为我打开了serve),而且在使用blogdown::build_site() 时,我会得到这个:

> blogdown::serve_site()
Rendering content/post/2015-07-23-r-rmarkdown.Rmd
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018/W32TeX) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
Quitting from lines 49-55 (2015-07-23-r-rmarkdown.Rmd) 
Error: Failed to compile .\tikz53878cd6189.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips.
Execution halted
Error in render_page(f) : 
  Failed to render 'content/post/2015-07-23-r-rmarkdown.Rmd'

疑难解答

我检查了我的引擎,发现 tikz 实际上是其中之一:

> names(knitr::knit_engines$get())
 [1] "awk"         "bash"        "coffee"      "gawk"        "groovy"      "haskell"     "lein"        "mysql"      
 [9] "node"        "octave"      "perl"        "psql"        "Rscript"     "ruby"        "sas"         "scala"      
[17] "sed"         "sh"          "stata"       "zsh"         "highlight"   "Rcpp"        "tikz"        "dot"        
[25] "c"           "fortran"     "fortran95"   "asy"         "cat"         "asis"        "stan"        "block"      
[33] "block2"      "js"          "css"         "sql"         "go"          "python"      "julia"       "theorem"    
[41] "lemma"       "corollary"   "proposition" "conjecture"  "definition"  "example"     "exercise"    "proof"      
[49] "remark"      "solution"  

文档说有些引擎是在bookdown而不是knitr中发货的,但我可以看到tikz在那里!所以我有引擎,但我仍然无法使用它。我做错了什么?


更多信息

会生成一个日志文件/content/post/texput.log 并报告有关失败的信息:

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018/W32TeX) (preloaded format=pdflatex 2019.1.11)  25 FEB 2019 07:54
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**.\tikz3cac449b1071.tex

! Emergency stop.
<*> .\tikz3cac449b1071.tex

*** (job aborted, file error in nonstop mode)


Here is how much of TeX's memory you used:
 3 strings out of 492616
 115 string characters out of 6132768
 56950 words of memory out of 5000000
 4017 multiletter control sequences out of 15000+600000
 3640 words of font info for 14 fonts, out of 8000000 for 9000
 1141 hyphenation exceptions out of 8191
 0i,0n,0p,1b,6s stack positions out of 5000i,500n,10000p,200000b,80000s
!  ==> Fatal error occurred, no output PDF file produced!

如果我检查knitr:

> xfun::session_info('knitr')
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200), RStudio 1.1.463

Locale:
  LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
  LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
  LC_TIME=English_United States.1252    

Package version:
  evaluate_0.13   glue_1.3.0      graphics_3.5.2  grDevices_3.5.2 highr_0.7       knitr_1.21.13  
  magrittr_1.5    markdown_0.9    methods_3.5.2   mime_0.6        stats_3.5.2     stringi_1.3.1  
  stringr_1.4.0   tools_3.5.2     utils_3.5.2     xfun_0.5        yaml_2.2.0

【问题讨论】:

  • 检查是否有日志文件,如tikz1ee41b8e2745.log
  • @YihuiXie 我已经编辑了答案。存在日志并且其内容已被报告。该消息引用了一个我找不到的.tex 文件,我猜它是工具完成运行后立即删除的临时文件:(
  • @YihuiXie:不幸的是,这条消息并没有说明什么。你在你的盒子上经历过这个吗?从部署的角度来看,我真的没有做任何先进的事情。只需举一个例子并添加一个 sn-p。
  • 请尝试remotes::install_github(c('yihui/tinytex', 'yihui/knitr', 'yihui/servr'), upgrade = TRUE),重启R,更新你的Rmd帖子,然后重新编译(通过blogdown::serve_site())。如果你也安装了TinyTeX,我相信它应该会自动运行。
  • @YihuiXie:我会试一试,谢谢。会让你知道...

标签: rstudio bookdown blogdown tikz


【解决方案1】:

这原来是 knitr 中的一个问题,它是 Github 上的 I just fixed(我不确定这是否是 pdflatex 的错误)。你可以试试

remotes::install_github('yihui/knitr')

请注意,如果尚未安装两个额外的 R 包,ma​​gickpdftools,则需要安装它们。

【讨论】:

  • 我做到了,而且效果很好。它生成带有图像的pdf。当我尝试渲染文档时发生错误。
  • 我已经完成了获取详细消息的过程,但是当我尝试使用blogdown::serve_site()时,控制台仍然给我相同的消息并且日志文件具有相同的内容
  • 显示的消息在我的问题中报告无法处理帖子
  • 我想我终于想通了。我有点惊讶你是第一个在 Windows 上发现这个问题的人(也许以前没有人真正在 Windows 上使用过tikz 引擎,或者他们只是默默地放弃了)。感谢您的报告!
  • 完美!我真的很高兴这个问题终于得到了解决!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-13
  • 1970-01-01
  • 2019-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多