1

I have just started using blogdown and I have created a project by using template Hugo-Xmin. In RStudio, when creating the project in blogdown, it created some predefined posts, I am editing this one:

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

Adding a tikz image

Following this question and the bookdown documentation on engines, I modified the afore-mentioned file by adding this snippet:

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}
```

Failed to process the post

As soon as I save (since I have the serve on), but also when using blogdown::build_site(), I get this:

> 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'

Troubleshooting

I checked my engines and saw that tikz is actually among them:

> 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"  

The documentation said that some engines are shipped in bookdown and not knitr, but I can see tikz is there! So I have the engine, but still I cannot use it. What am I doing wrong?


More info

A log file /content/post/texput.log is generated and reports this info on the failure:

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!

If I check 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
Andry
  • 16,172
  • 27
  • 138
  • 246
  • Check if there is a log file, such as `tikz1ee41b8e2745.log`. – Yihui Xie Feb 25 '19 at 05:36
  • @YihuiXie I have edited the answer. A log is present and its content has been reported. The message references a `.tex` file which I could not find, I guess it is a temporary file removed as soon as the tools finish running :( – Andry Feb 25 '19 at 07:00
  • @YihuiXie: Unfortunately the message does not tell much. Have you experienced this on your box? I am really not doing anything advanced from deployment point of view. Just taking one of the examples and adding a snippet. – Andry Feb 26 '19 at 12:36
  • Please try `remotes::install_github(c('yihui/tinytex', 'yihui/knitr', 'yihui/servr'), upgrade = TRUE)`, restart R, update your Rmd post, and recompile it (via `blogdown::serve_site()`). If you have also installed [TinyTeX](https://yihui.name/tinytex/), I believe it should work automatically. – Yihui Xie Mar 01 '19 at 20:41
  • @YihuiXie: I will give this a shot, thanks. Will let you know... – Andry Mar 01 '19 at 21:59
  • @YihuiXie: I have tried, but it keeps failing with: `cannot remove prior installation of package ‘stringi’ even though I have installed it several times and restarted all R sessions as well. – Andry Mar 05 '19 at 06:12
  • @YihuiXie: I think I solved the package unsinstall issue. Now, after what you told me to do, I get the same exact error I was getting before and same logfile produced with same content :( – Andry Mar 05 '19 at 06:17
  • The logfile shouldn't be named `texput.log`. It should be something like `tikzxxxxx.log`. The error message shouldn't be exactly the same, either. At least the error shouldn't come from `tools::texi2dvi` because if you have successfully installed the dev version of **knitr**, it no longer uses `tools::texi2dvi`. Please check your `xfun::session_info('knitr')`. – Yihui Xie Mar 05 '19 at 13:02
  • It says: `Error: Failed to compile .\tikz51143a65cfd.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips.` in the console – Andry Mar 05 '19 at 13:09
  • @YihuiXie: There is not trace of another logfile other that one (inside `post`). I checked other dirs and I cannot find any log there. – Andry Mar 05 '19 at 13:10
  • @YihuiXie: I have updated the question with the output from the command you asked me to run. – Andry Mar 05 '19 at 13:12
  • @YihuiXie: Is it possible that somehow my environment got screwed up? By the new info I posted in the question, can you see the proper version of the dependencies or some of them ave not been properly updated? In case, how can I reset my packages? Do I need ro remove R/RStudio and install them over again? – Andry Mar 05 '19 at 15:32
  • As the error message says, follow https://yihui.name/tinytex/r/#debugging and see if you get any new information. You don't need to reinstall R or RStudio. Quit and restart RStudio should suffice. – Yihui Xie Mar 05 '19 at 17:32

1 Answers1

1

This turns out to be an issue in knitr which I just fixed on Github (I'm not sure if it is a bug of pdflatex). You may try

remotes::install_github('yihui/knitr')

Note that you will need to install two additional R packages, magick and pdftools, if they haven't been installed yet.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • I did it and it works. It generates the pdf with the image. The error happens when I try to render the document. – Andry Mar 06 '19 at 15:54
  • I have done the procedure to get verbose messages, but the console still gives me the same message and the logfile has the same content when I try to use `blogdown::serve_site()` – Andry Mar 06 '19 at 15:55
  • The message shown is reported in my question under _Failed to process the post_ – Andry Mar 06 '19 at 15:57
  • I guess I finally figured it out. I'm kind of surprised that you are the first person to discover this problem on Windows (perhaps no one has really used the `tikz` engine on Windows before, or they just silently gave up). Thanks for the report! – Yihui Xie Mar 06 '19 at 20:12
  • Oh I see. I will give it a try. I have seen the change and thanks a lot for pointing me to that and thanks for fixing it. Since I intend to use rmarkdown and bookdown for a system I want to create, getitng insights in the codebase is very important to me :) Let me try this and see – Andry Mar 06 '19 at 21:40
  • 1
    Perfect! I'm really glad that this issue has finally been resolved! – Yihui Xie Mar 06 '19 at 21:59