【问题标题】:knitr caching fails when using XeLaTeX fontspec package through RStudio通过 RStudio 使用 XeLaTeX fontspec 包时,knitr 缓存失败
【发布时间】:2013-03-04 15:39:18
【问题描述】:

我在 RStudio 中使用 knitr 和 XeLaTeX。我使用块缓存,这样每次编译文档时都不必重新运行某些代码。这个最小的例子表明,如果加载了 fontspec 包,缓存似乎被破坏了。

\documentclass{article}
\usepackage{fontspec} % Appears to somehow conflict with caching.

\begin{document}

<<pre_load, cache=TRUE>>=
library(tikzDevice)
options(tikzDefaultEngine="xetex")
@

\section{Test}
<<test_block, dev='tikz', dependson='pre_load'>>=
plot(1:10,main='Test')
@

\end{document}

此文档第一次编译为 PDF 时,它会起作用,因为没有使用缓存。但是,如果对test_block 块进行了更改,并且代码再次运行,它将失败。例如编译成PDF一次后,把test_block块改成:

<<test_block, dev='tikz', dependson='pre_load'>>=
plot(1:10,main='Test Modified')
@

现在,编译为 PDF 失败并出现以下错误:

! 
 ********************************************
 * XeTeX is required to compile this document.
 * Sorry!
 ********************************************.
\RequireXeTeX ...********************************}
                                                  \endgroup \fi 
l.18 \RequireXeTeX

此错误表示options(tikzDefaultEngine="xetex") 尚未设置。有趣的是,如果fontspec包没有被加载,那么这个错误就不会发生。

我的问题是:这是一个错误,还是我的代码有问题?

我正在通过 RStudio (0.97.246)(通过浏览器通过 RStudio 服务器访问)在 R(R 开发中(不稳定)(2012-11-10 r61101))上使用 knitr(1.1)和 tikzDevice(0.6.3)它本身在 Ubuntu (12.04.2 LTS) 上运行。我的 LaTeX2e 的日期为 。

【问题讨论】:

    标签: r latex knitr rstudio fontspec


    【解决方案1】:

    不要将options(tikzDefaultEngine="xetex") 放在缓存的块中,因为它有一个无法缓存的副作用,所以第二次编译文档时,该选项将被跳过。阅读knitr 网站上的Important Notes in the cache page 部分。

    请注意,您也不需要library(tikzDevice);这个包会在你设置dev='tikz'时自动加载。

    在大多数情况下,您应该缓存绘图块,因为创建 TikZ 图形很慢。

    \documentclass{article}
    \usepackage{fontspec} % Appears to somehow conflict with caching.
    
    \begin{document}
    
    <<pre_load>>=
    options(tikzDefaultEngine="xetex")
    @
    
    \section{Test}
    <<test_block, dev='tikz'>>=
    plot(1:10,main='Test')
    @
    
    \end{document}
    

    【讨论】:

      猜你喜欢
      • 2019-05-14
      • 2013-02-24
      • 1970-01-01
      • 2016-08-16
      • 2023-04-06
      • 2017-01-12
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多