daqana / tikzDevice

A R package for producing graphics output as PGF/TikZ code for use in TeX documents.
https://daqana.github.io/tikzDevice
131 stars 26 forks source link

Fail to create plot using tikzDevice #209

Open famfigueiredo opened 3 years ago

famfigueiredo commented 3 years ago

Very recent LaTeX user, and I am trying to export one of my ggplots to LaTeX using tikz. I manage to create the '.tex' file as recommended in all the examples I have been able to find, but once I try to execute my plot command, I get the following error message:

Measuring dimensions of: \char77 Running command: '/usr/local/bin/pdflatex' -interaction=batchmode -halt-on-error -output-directory '/var/folders/9z/rwd9dk612nq_7vv9j9vqzsj97z3jn5/T//RtmpMVHkIe/tikzDevice142fb477a068b' 'tikzStringWidthCalc.tex' Error in getMetricsFromLatex(TeXMetrics, verbose = verbose) : TeX was unable to calculate metrics for:

\char77

Run the following commands for diagnosis:

tikzTest()
tikzTest("\\char77")

Common reasons for failure include:

The TeX and log files used for the calculation can help diagnose the problem. If these files are missing, rerun the plot and make sure to keep the R session open. TeX file: tikzStringWidthCalc.tex Log file: tikzStringWidthCalc.log](url)

After trying to run tikzTest(), I get the following result:

Active compiler: /usr/local/bin/pdflatex pdfTeX 3.14159265-2.6-1.40.21 (TeX Live 2020) kpathsea version 6.3.2

Measuring dimensions of: \char77 Running command: '/usr/local/bin/pdflatex' -interaction=batchmode -halt-on-error -output-directory '/var/folders/9z/rwd9dk612nq_7vv9j9vqzsj97z3jn5/T//RtmpMVHkIe/tikzDevice142fb163405b6' 'tikzStringWidthCalc.tex' This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex) restricted \write18 enabled. entering extended mode

TeX was unable to calculate metrics for:

\char77

Contents of TeX file tikzStringWidthCalc.tex:

\documentclass[10pt]{article}

\usepackage{tikz}

\usepackage[active,tightpage,psfixbb]{preview}

\PreviewEnvironment{pgfpicture}

\setlength\PreviewBorder{0pt}

\usepackage[T1]{fontenc}

\usetikzlibrary{calc}

\batchmode \begin{document} \begin{tikzpicture} \node[inner sep=0pt, outer sep=0pt, scale=1] (TeX) {\char77}; \path let \p1 = ($(TeX.east) - (TeX.west)$), \n1 = {veclen(\x1,\y1)} in (TeX.east) -- (TeX.west) node{ \typeout{tikzTeXWidth=\n1} }; \end{tikzpicture} \end{document} Contents of log file tikzStringWidthCalc.log:

This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex 2020.9.15) 17 SEP 2020 13:46 entering extended mode restricted \write18 enabled. %&-line parsing enabled. **tikzStringWidthCalc.tex

(/var/folders/9z/rwd9dk612nq_7vv9j9vqzsj97z3jn5/T//RtmpMVHkIe/tikzDevice142fb16 3405b6/tikzStringWidthCalc.tex LaTeX2e <2020-02-02> patch level 5 L3 programming layer <2020-09-06> (/Users/ffi007/Library/TinyTeX/texmf-dist/tex /latex/base/article.cls Document Class: article 2019/12/20 v1.4l Standard LaTeX document class (/Users/ffi007/Library/TinyTeX/texmf-dist/tex/latex/base/size10.clo File: size10.clo 2019/12/20 v1.4l Standard LaTeX file (size option) ) \c@part=\count168 \c@section=\count169 \c@subsection=\count170 \c@subsubsection=\count171 \c@paragraph=\count172 \c@subparagraph=\count173 \c@figure=\count174 \c@table=\count175 \abovecaptionskip=\skip47 \belowcaptionskip=\skip48 \bibindent=\dimen134 )

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

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

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

l.4 ^^M

Here is how much of TeX's memory you used: 218 strings out of 482824 2883 string characters out of 5955256 238541 words of memory out of 5000000 15683 multiletter control sequences out of 15000+600000 535088 words of font info for 29 fonts, out of 8000000 for 9000 14 hyphenation exceptions out of 8191 25i,0n,25p,138b,36s stack positions out of 5000i,500n,10000p,200000b,80000s

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

rinzebloem commented 3 years ago

I'm suffering the same issue.

lbelzile commented 3 years ago

Its hard to do anything without a MWE. Based on your log, it appears the problem is due to the lack of installation of the tikz package. Try tinytex::tlmgr_install(pkgs = "tikz")

rinzebloem commented 3 years ago

The below code returns the same error as @famfigueiredo specified.

library(tikzDevice) library(tinytex) library(filehash) tinytex::tlmgr_install(pkgs = "tikz") options(tikzDefaultEngine = 'pdftex') options(tikzDocumentDeclaration = "\\documentclass[11pt]{report}")

tikz(file = "./Analysis/Figures/Imputation cross-validation/CV imputation boxplot.tex", width = 6.28, height = 4) df <- mtcars boxImp <- df %>% ggplot(aes(y = disp)) + geom_boxplot() print(boxImp) dev.off()

rstub commented 3 years ago

@famfigueiredo The error you quote indicates that tikz.sty is not installed. This comes with the pgf TeX Live package. Is that installed? One way to test this is

any("pgf" == tinytex::tl_pkgs(only_installed=TRUE))

If you are using TinyTeX as TeX distribution you can use tinytex::tlmgr_install(pkgs = "pgf") to install this package.

@rinzebloem The same might apply to you. Do you also get ! LaTeX Error: Filetikz.sty' not found.`?

rinzebloem commented 3 years ago

@rstub I was missing the file grfext.sty which I've resolved just now by running

tinytex::install_tinytex() after loading the packages in Rstudio

and

tlmgr install grfext in the Windows command prompt. Things are running smoothly now. Thanks a lot for the help!

bridgeovertroubledhuman commented 1 year ago

I do not have tinytex and I also have this problem (I am on a Mac).

rstub commented 1 year ago

@bridgeovertroubledhuman Can you post the output of tikzDevice::tikzTest(), please?