Unable to get tikzDevice to work

送分小仙女□ 提交于 2019-12-22 05:41:31

问题


I have a problem with tikzDevice. I'm using the latest versions of R (with latest knitr and tikzDevice packages) and RStudio, updated TeX Live to 2015 binaries (and I think I have all the required packages). When I try to output graphics to tikzDevice, compilation hangs. Other graphics devices like PDF or CairoPNG work without a problem.

As an example, I tried to compile a the simple code below from RStudio with XeLaTeX (set as the default LaTeX compiler in RStudio), but it hangs forever after using the TikZ metrics dictionary. What I see is that the compilation actually produces a file with .tikz extension in the "figure" folder, which can be successfully compiled if I run XeLaTeX on it.

I attached below the complete log from RStudio 'Compile PDF' console output pane while it hangs:

Le chargement a n�cessit� le package : knitr

processing file: test.Rnw
  |.............                                                    |  20%
  ordinary text without R code

  |..........................                                       |  40%
label: setup (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |.......................................                          |  60%
  ordinary text without R code

  |....................................................             |  80%
label: fig1 (with options) 
List of 3
 $ eval: logi TRUE
 $ echo: logi FALSE
 $ dev : chr "tikz"

Creating new TikZ metrics dictionary at:
    test-tikzDictionary
Using TikZ metrics dictionary at:
    test-tikzDictionary

Le chargement a n�cessit� le package : knitr 

processing file: knitr-graphics.Rnw
  |..                                                               |   2%
  ordinary text without R code

  |...                                                              |   5%
label: setup (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |.....                                                            |   7%
   inline R code fragments

  |......                                                           |  10%
label: test-plot (with options) 
List of 1
 $ eval: logi FALSE

  |........                                                         |  12%
  ordinary text without R code

  |..........                                                       |  15%
label: pdf-dev (with options) 
List of 4
 $ ref.label: chr "test-plot"
 $ dev      : chr "pdf"
 $ out.width: chr "\\linewidth"
 $ echo     : logi FALSE

  |...........                                                      |  17%
  ordinary text without R code

  |.............                                                    |  20%
label: png-dev (with options) 
List of 4
 $ ref.label: chr "test-plot"
 $ dev      : chr "png"
 $ out.width: chr "\\linewidth"
 $ echo     : logi FALSE

  |..............                                                   |  22%
  ordinary text without R code

  |................                                                 |  24%
label: cairo-png-dev (with options) 
List of 4
 $ ref.label: chr "test-plot"
 $ dev      : chr "CairoPNG"
 $ out.width: chr ".5\\linewidth"
 $ echo     : logi FALSE

  |.................                                                |  27%
  ordinary text without R code

  |...................                                              |  29%
label: two-high (with options) 
List of 3
 $ fig.width : num 3
 $ fig.height: num 2.5
 $ out.width : chr ".49\\linewidth"

Using TikZ metrics dictionary at:
    knitr-graphics-tikzDictionary

And an exerpt of the tikzStringWidthCalc.log found in R temporary folder:

This is XeTeX, Version 3.14159265-2.6-0.99992 (TeX Live 2015/W32TeX) (preloaded format=xelatex 2015.6.25)  1 JUL 2015 13:45
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**c:/Users/guyader/AppData/Local/Temp/RtmpqwmJYG/tikzStringWidthCalc.tex
(c:/Users/guyader/AppData/Local/Temp/RtmpqwmJYG/tikzStringWidthCalc.tex
LaTeX2e <2015/01/01>
Babel <3.9l> and hyphenation patterns for 4 languages loaded.
(c:/texlive/2014/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(c:/texlive/2014/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2014/09/29 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
)
(c:/texlive/2014/texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty
(c:/texlive/2014/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty
(c:/texlive/2014/texmf-dist/tex/latex/pgf/utilities/pgfrcs.sty
(c:/texlive/2014/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.tex
\pgfutil@everybye=\toks14
\pgfutil@tempdima=\dimen103
\pgfutil@tempdimb=\dimen104

(c:/texlive/2014/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-lists.tex)
) (c:/texlive/2014/texmf-dist/tex/generic/pgf/utilities/pgfutil-latex.def
\pgfutil@abb=\box26

[...]

LaTeX Font Info:    Redeclaring math symbol \Omega on input line 30.
LaTeX Font Info:    Redeclaring math symbol \mathdollar on input line 30.
LaTeX Font Info:    Redeclaring symbol font `operators' on input line 30.
LaTeX Font Info:    Encoding `OT1' has changed to `EU1' for symbol font
(Font)              `operators' in the math version `normal' on input line 30.
LaTeX Font Info:    Overwriting symbol font `operators' in version `normal'
(Font)                  OT1/cmr/m/n --> EU1/lmr/m/n on input line 30.
LaTeX Font Info:    Encoding `OT1' has changed to `EU1' for symbol font
(Font)              `operators' in the math version `bold' on input line 30.
LaTeX Font Info:    Overwriting symbol font `operators' in version `bold'
(Font)                  OT1/cmr/bx/n --> EU1/lmr/m/n on input line 30.
LaTeX Font Info:    Overwriting symbol font `operators' in version `normal'
(Font)                  EU1/lmr/m/n --> EU1/lmr/m/n on input line 30.
LaTeX Font Info:    Overwriting math alphabet `\mathit' in version `normal'
(Font)                  OT1/cmr/m/it --> EU1/lmr/m/it on input line 30.
LaTeX Font Info:    Overwriting math alphabet `\mathbf' in version `normal'
(Font)                  OT1/cmr/bx/n --> EU1/lmr/bx/n on input line 30.
LaTeX Font Info:    Overwriting math alphabet `\mathsf' in version `normal'
(Font)                  OT1/cmss/m/n --> EU1/lmss/m/n on input line 30.
LaTeX Font Info:    Overwriting math alphabet `\mathtt' in version `normal'
(Font)                  OT1/cmtt/m/n --> EU1/lmtt/m/n on input line 30.
LaTeX Font Info:    Overwriting symbol font `operators' in version `bold'
(Font)                  EU1/lmr/m/n --> EU1/lmr/bx/n on input line 30.
LaTeX Font Info:    Overwriting math alphabet `\mathit' in version `bold'
(Font)                  OT1/cmr/bx/it --> EU1/lmr/bx/it on input line 30.
LaTeX Font Info:    Overwriting math alphabet `\mathsf' in version `bold'
(Font)                  OT1/cmss/bx/n --> EU1/lmss/bx/n on input line 30.
LaTeX Font Info:    Overwriting math alphabet `\mathtt' in version `bold'
(Font)                  OT1/cmtt/m/n --> EU1/lmtt/bx/n on input line 30.
tikzTeXWidth=4.80003pt
! Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.37 \@@end

Here is how much of TeX's memory you used:
 23160 strings out of 495610
 491023 string characters out of 6186855
 478788 words of memory out of 5000000
 26156 multiletter control sequences out of 15000+600000
 6670 words of font info for 20 fonts, out of 8000000 for 9000
 14 hyphenation exceptions out of 8191
 55i,5n,54p,10417b,529s stack positions out of 5000i,500n,10000p,200000b,80000s

No pages of output.

In addition, if I run the command knit("test.Rnw") from R console, I get this:

processing file: test.Rnw
  |.............                                                    |  20%
  ordinary text without R code

  |..........................                                       |  40%
label: setup (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |.......................................                          |  60%
  ordinary text without R code

  |....................................................             |  80%
label: fig1 (with options) 
List of 3
 $ eval: logi TRUE
 $ echo: logi FALSE
 $ dev : chr "tikz"

Using TikZ metrics dictionary at:
    test-tikzDictionary
Quitting from lines 14-17 (test.Rnw) 
Error: failed to compile figure/graphics-fig1-1.tikz to PDF
In addition: Warning message:
running command '"C:\texlive\2014\bin\win32\xelatex.exe" "graphics-fig1-1.tikz"' had status 1 

Though, again if run xelatex on the .tikz graphics file from a windows command prompt, it successfully compiles to PDF.

Here's my sessionInfo():

R version 3.2.1 (2015-06-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C                   LC_TIME=French_France.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.2.1

Following up on my problem with tikzDevice, the only workaround I found is to output the graphics to another device like png, add usepackage{tikz} to the preamble, call tikz() inside the code chunk and \input{} the resulting .tex figure like this:

\documentclass{article}
\usepackage{tikz}

\begin{document} 

<<setup, include=FALSE, cache=FALSE>>=
library(knitr)
library(tikzDevice)
options(formatR.arrow=TRUE,width=50,tikzDefaultEngine='xetex')
opts_chunk$set(fig.path='figure/graphics-', cache.path='cache/graphics-', fig.align='center', dev='png', fig.width=5,     fig.height=5, fig.show='hold', cache=TRUE, par=TRUE, concordance=TRUE)
@

\begin{figure} 

<<fig1,eval=TRUE,echo=FALSE>>= 
library(ggplot2)
setwd("~/")
td <- getwd()
tf <- file.path(td,'fig1.tex')
tikz(tf, standAlone=F, bareBones=F)
qplot(displ, hwy, data = mpg, colour = factor(cyl))
dev.off()
@

\input{fig1.tex}

\end{figure} 

\end{document}

This way I can get the consistency of fonts from using tikz, but it would be much easier to have tikzDevice() to work.

来源:https://stackoverflow.com/questions/31163917/unable-to-get-tikzdevice-to-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!