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

TeX was unable to calculate metrics for the following string or character: m #196

Closed ThomasWilli closed 4 years ago

ThomasWilli commented 4 years ago

While I had tikzDevice working nicely, it no longer wants to work for me. When dealing with a simple plot as shown below it gives the above error. I updated all my packages (from dev as suggested here #114) but without success. I used a second machine and got the same error.

library(tikzDevice)
tikzDevice::tikz("test.tex", width = 3.5, height = 3)
plot(1:10)
dev.off()

Measuring dimensions of: m
Running command: '/usr/local/bin/pdflatex' -interaction=batchmode -halt-on-error -output-directory '/var/folders/_m/jtfsgy79743fd5wlqhjkjhjm0000gn/T//Rtmp5IHDhh/tikzDevice388f4b8f810e' 'tikzStringWidthCalc.tex'
Error in getMetricsFromLatex(TeXMetrics, verbose = verbose) : 
TeX was unable to calculate metrics for:

m

Run the following commands for diagnosis:

tikzTest()
tikzTest("m")

Common reasons for failure include:
  * The string contains a character which is special to LaTeX unless
escaped properly, such as % or $.
  * The string makes use of LaTeX commands provided by a package and
the tikzDevice was not told to load the package.

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

When I run tikzTest("m") it tells me that

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

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

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

l.4 ^^M

Here is some more info:

sessionInfo()

R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks   /vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] tidyr_0.8.3       ggplot2_3.1.1     tikzDevice_0.12.3 dplyr_0.8.0.1    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1        pillar_1.3.1      compiler_3.6.0    plyr_1.8.4        remotes_2.0.4    
 [6] readstata13_0.9.2 prettyunits_1.0.2 tools_3.6.0       digest_0.6.18     pkgbuild_1.0.3       
[11] pkgload_1.0.2     memoise_1.1.0     tibble_2.1.1      gtable_0.3.0      pkgconfig_2.0.2  
[16] rlang_0.3.4       filehash_2.4-2    cli_1.1.0         rstudioapi_0.10   curl_3.3         
[21] yaml_2.2.0        withr_2.1.2       fs_1.2.7          desc_1.2.0        devtools_2.0.2   
[26] rprojroot_1.3-2   grid_3.6.0        tidyselect_0.2.5  glue_1.3.1        R6_2.4.0         
[31] processx_3.3.0    sessioninfo_1.1.1 purrr_0.3.2       callr_3.2.0       magrittr_1.5     
[36] usethis_1.5.0     backports_1.1.4   scales_1.0.0      ps_1.3.0          assertthat_0.2.1 
[41] colorspace_1.4-1  lazyeval_0.2.2    munsell_0.5.0     crayon_1.3.4  
rstub commented 4 years ago

! LaTeX Error: Filetikz.sty' not found.`

That is a problem. Which TeX distribution do you use? Is tikz.sty installed?

ThomasWilli commented 4 years ago

I re-installed MacTeX this morning and I am not able to find tikz.sty...

rstub commented 4 years ago

tikz.sty should be part of the pgf package.

ThomasWilli commented 4 years ago

According to my TeX Live Utility pgf is installed...

Screenshot 2019-10-07 at 14 33 07

But I can't find tikz.sty.

rstub commented 4 years ago

Can you compile LaTeX documents that use tikz.sty independent of R/tikzDevice? What is the output of kpsewhich pgf.sty and kpsewhich tikz.sty on the command line?

ThomasWilli commented 4 years ago

I can compile LaTeX documents including \usepackage{tikz} without problems. kpsewhich pgf.sty and kpsewhich tikz.sty return nothing.

rstub commented 4 years ago

Very odd. Just so that I understand your system correctly (I am not a MacTeX user ...): kpsewhich article.cls does return the path to the article.cls of your TeX installation.

ThomasWilli commented 4 years ago

Yes it does: ~/Library/TinyTeX/texmf-dist/tex/latex/base/article.cls

rstub commented 4 years ago

Now we are getting somewhere: It seems you have both MacTeX and TinyTeX installed. MacTeX includes pgf and is used by whatever tools you use for normal LaTeX content. TinyTeX does not contain pgf and is probably earlier in $PATH than MacTeX and therefore used by tikzDevice.

I suggest you decide which TeX installation you want to use and uninstall the other one. In case you want to use TinyTeX, you have to install the required packages tinytex::tlmgr_install(c('pgf', 'preview', 'xcolor')).

ThomasWilli commented 4 years ago

I deleted TinyTeX and everything seems to work. Thanks for clarifying this to me.

rstub commented 4 years ago

You are welcome.

bridgeovertroubledhuman commented 1 year ago

I have the same problem, but I do not have tinytex on my computer. Should I make a new post?

rstub commented 1 year ago

@bridgeovertroubledhuman Sorry for the late reply. Yes, please create a new issue.