I am trying to use XeLaTeX, knitr and tikz - and failing with a ghostscript error. I have tried many different approaches and the situation is as follows:
- XeLaTeX with knitr: works
- PDFLaTeX with knitr: works
- PDFLaTeX with knitr and tikz: works
- XeLaTeX with knitr and tikz: fails
The simple document I made is here http://paste.lisp.org/+31GJ , the main part is this:
<<xetex-tikz, eval=FALSE, echo=FALSE>>=
options(tikzDefaultEngine='xetex')
@
A plot:
<<test, echo=FALSE,dev='tikz'>>=
plot(10,10)
@
the error message is in an annotation there as well, but I'll paste it here:
GPL Ghostscript 9.14: Unrecoverable error, exit code 1
** WARNING ** Filtering file via command -->rungs -q -dNOPAUSE -dBATCH -dEPSCrop -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -sOutputFile='/tmp/xdvipdfmx.45a08580e905757a9f5e6fc456cb9f8b' '/dev/null' -c quit<-- failed.
** WARNING ** Image format conversion for "/dev/null" failed...
** WARNING ** Image width=0.0!
** WARNING ** Image height=0.0!
** ERROR ** pdf_ref_obj(): passed invalid object.
To avoid any issues with older packages (RHEL5 has an older version of texlive, for example), I locally installed the following:
TeXlive 2013:
$ type xelatex
xelatex is hashed (/usr/local/texlive/2013/bin/x86_64-linux/xelatex
$ xelatex -version
XeTeX 3.1415926-2.5-0.9999.3-2013060708 (TeX Live 2013)
kpathsea version 6.1.1
GNU R
$ type R
R is /usr/local/bin/R
$ R --version
R version 3.0.3 (2014-03-06) -- "Warm Puppy"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)
Ghostscript
$ type ghostscript
ghostscript is /usr/local/bin/ghostscript
$ ghostscript --version
9.14
I set R_LATEXCMD to xelatex (before that pdflatex was being used, which meant that knit would fail since I use XeTeX packages) and that's about the only global variable or additional setting I made; paths seem to be correct, e.g.:
$ kpsewhich tikz
/usr/local/texlive/2013/texmf-dist/tex/plain/pgf/frontendlayer/tikz.tex
On R I updated the packages and installed knitr and tikzDevice (latest versions, via install.package).
Any pointers would be appreciated; the XeLaTeX+knitr+tikz combination doesn't strike as particularly exotic: tikz is recommended in the knitr graphics manual and is needed to use the same fonts as the main document, and XeLaTeX is a very common choice of engine - and I need the unicode support it provides in order to use Charis SIL, IPA characters, etc.