我对tikzDevice
有疑问。我使用最新版本的R
(使用最新的knitr和tikzDevice
软件包)和RStudio
,将TeX Live更新为2015二进制文件(我认为我拥有所有必需的软件包) )。
当我尝试将图形输出到tikzDevice
时,编译挂起。其他图形设备(如PDF
或CairoPNG
也可以顺利运行。
作为示例,我尝试使用RStudio
(XeLaTeX
中设置为默认LaTeX
编译器)从RStudio
编译下面的简单代码,但它挂起使用TikZ指标字典后永远。
我看到的是,编译实际上在"数字"中生成了一个.tikz
扩展名的文件。文件夹,如果我在其上运行XeLaTeX
,则可以成功编译。
我附在RStudio
'编译PDF'的完整日志下面。控制台输出窗格挂起时:
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
在R临时文件夹中找到tikzStringWidthCalc.log
的exerpt:
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.
此外,如果我从R控制台运行命令knit("test.Rnw")
,我会得到:
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
但是,如果从Windows命令提示符处xelatex
图形文件上运行.tikz
,它会成功编译为PDF。
这是我的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
跟我解决tikzDevice
的问题,我找到的唯一解决方法是将图形输出到png等其他设备,将usepackage{tikz}
添加到前导码中,在代码中调用tikz()
chunk和\input{}
得到的.tex
数字如下:
\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}
通过这种方式,我可以使用tikz获得字体的一致性,但让tikzDevice()
更容易工作。