Blogdown 无法在我的 Rmd 文档中呈现 tikz 块

Blogdown fails rendering a tikz block in my Rmd document

此问题与 密切相关,但存在以下差异:


我已经使用模板 Hugo-Xmin 创建了一个项目。在 RStudio 中,在 blogdown 中创建项目后,它创建了一些预定义的 posts,我正在编辑这个:

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

我通过在文件末尾添加以下片段修改了该文件:

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

无法处理 post

我的工作目录是项目文件夹,我从那里 运行 在 R 控制台中输入命令:

blogdown::build_site()

得到这个:

> blogdown::build_site()
Rendering content/_index.Rmarkdown
running: bash  -c "cd ../..;
find . -not -path '*/exampleSite/*' \( -name '*.html' -o -name '*.css' \) | xargs wc -l"
Rendering content/post/2015-07-23-r-rmarkdown.Rmd
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode
! LaTeX Error: File `preview.sty' not found.

! Emergency stop.
<read *>

Quitting from lines 49-55 (2015-07-23-r-rmarkdown.Rmd)
Error: Failed to compile tikz2b145b766cfa.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See tikz2b145b766cfa.log for more info.
Execution halted
Error in render_page(f) :
  Failed to render 'content/post/2015-07-23-r-rmarkdown.Rmd'

重要 请注意,我已遵循帮助 link 并在文件开头添加了以下片段:

```{r, include=FALSE}
options(tinytex.verbose = TRUE)
```

我上面报告的输出是我在这个片段就位时得到的输出。


疑难解答 1

通过检查文件 tikz2b145b766cfa.log(如错误消息中所报告),我可以看到以下错误:

This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013) (format=pdflatex 2019.3.18)  18 MAR 2019 21:12
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**tikz2b145b766cfa.tex
(./tikz2b145b766cfa.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ru
ssian, ukrainian, bulgarian, loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
\@input{preview.aux}
\openout2 = `preview.aux'.

No file preview.tex.

! LaTeX Error: File `preview.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Enter file name:
! Emergency stop.
<read *>

l.4 \usepackage
               {amsmath}^^M
Here is how much of TeX's memory you used:
 200 strings out of 494820
 2171 string characters out of 3178049
 47774 words of memory out of 3000000
 3480 multiletter control sequences out of 15000+200000
 3640 words of font info for 14 fonts, out of 3000000 for 9000
 198 hyphenation exceptions out of 8191
 23i,0n,17p,164b,36s stack positions out of 5000i,500n,10000p,200000b,50000s

!  ==> Fatal error occurred, no output PDF file produced!

重要的是要知道我在 CentOS 系统上安装了很多软件包和软件:

yum install texlive*

并且:

install.packages("devtools")
remotes::install_github('yihui/knitr')
install.packages(c('magick', 'pdftools'))

在 R.

疑难解答 2

按照建议,我安装了:tinytex。它成功了。在那之后,在 运行ning build_site() 之后,我总是被提示缺少我必须安装的库。 30 分钟后,我收到这条消息:

> blogdown::build_site()
Rendering content/_index.Rmarkdown
running: bash  -c "cd ../..;
find . -not -path '*/exampleSite/*' \( -name '*.html' -o -name '*.css' \) | xargs wc -l"
Rendering content/post/2015-07-23-r-rmarkdown.Rmd
hugo: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by hugo)
hugo: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by hugo)

不幸的是,我正在努力解决这个问题,因为 libstdc++-4.8.5-36.el7.x86_64 已经安装,我不确定如何修复 GLIBCXX_3.4.20GLIBCXX_3.4.21。对它们尝试 yum install 无效。

我不知道为什么你的 TeX Live 找不到 preview.sty,但我很确定 TinyTeX 会自动工作:

# first make sure all your R packages are up-to-date, then
tinytex::install_tinytex()