daqana / tikzDevice

A R package for producing graphics output as PGF/TikZ code for use in TeX documents.

Home Page:https://daqana.github.io/tikzDevice

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Difference between version 0.12.3.2 and 0.12.3.1

jamarav opened this issue · comments

Hi everybody,

I would like to report my expirience with the tikzDevice because I am experiencing problems with the cran version.

I'm writing my phD with knitr and plotting with ggplot and tikzDevice and I only can use the tikzDevice package building it from the master branch. I'm not sure which is the difference between the tikzDevice package version 0.12.3.2 and 0.12.3.1 (cran repository) but the version in the cran repository doesn't works for me.

Probably the reason is that I divide the phD in different *.Rnw files and I use a custom *.cls class (installed in my texlive distribution). I have a main.Rnw in the main directory and then different *.Rnw files (chapters) placed in different subdirectories.

With this background, I'm able to work propertly with the tikzDevice built from the master branch. The only requirement is set the main directory in R before plotting with the tikzDevice (When I plot in the child documents). I use this function:

printTikz = function(p, current_wdirectory) {
  
  setwd(base_directory)

  print(p)
  
  setwd(current_wdirectory)
  
}

I would like to know if there are any major changes between the development version and the version in the cran repository that explain this strange behaviour. I don't understand why it works in one case and not in the other.

As an example this is an error if I use the version from the cran repository (it works with the development version):

Quitting from lines 613-649 (./03_chapters/chap_03/chap_03.Rnw) 
Quitting from lines 758-758 (./03_chapters/chap_03/chap_03.Rnw) 
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 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
Calls: knit ... descentDetails.text -> grid.Call -> <Anonymous> -> getMetricsFromLatex

However if I run the tikzTest() funtion I don't get any error:

> tikzDevice::tikzTest("\\char77")

Active compiler:
	/usr/local/texlive/2021/bin/x86_64-linux/pdflatex
	pdfTeX 3.141592653-2.6-1.40.23 (TeX Live 2021)
	kpathsea version 6.3.3

Measuring dimensions of: \char77
Running command: '/usr/local/texlive/2021/bin/x86_64-linux/pdflatex' -interaction=batchmode -halt-on-error -output-directory '/tmp/RtmpzR82WU/tikzDevice27b7386cced' 'tikzStringWidthCalc.tex'
This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
[1] 9.16443

This is my session info:

> print(sessionInfo())
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale:
 [1] LC_CTYPE=es_ES.UTF-8       LC_NUMERIC=C               LC_TIME=es_ES.UTF-8        LC_COLLATE=es_ES.UTF-8     LC_MONETARY=es_ES.UTF-8   
 [6] LC_MESSAGES=es_ES.UTF-8    LC_PAPER=es_ES.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C       

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

loaded via a namespace (and not attached):
[1] compiler_4.1.0      tools_4.1.0         tikzDevice_0.12.3.1 filehash_2.4-2      grid_4.1.0 

Ok. I found the problem. It seems that with the current version in cran we can't include .tex files with \input{} function in the preamble. Probably, this functionality is only included in the development version. I attached the tikzStringWidthCalc.log file (
tikzStringWidthCalc.log
).
For the moment I will avoid using these types of functions in the preamble until a new stable version is released and use the version in cran. Of course I need to install my custom *.cls class in my latex distribution in order to use the cran version. I tried with the developement version and works for me without install the *.cls class in my latex distribution (It is located in the main folder with my main.Rnw file). It seems another difference between the development version and the version in cran.

Just a suggestion, in order to improve the use of the tikzDevice plotting from child document, It would be possible to print figures without having to change to the main path? (print tikz plots directly in the child documents located in different subdirectories)

At this time,
I solved this with my printTikz() function attached above:

printTikz = function(p, current_wdirectory) {
  
  setwd(base_directory)

  print(p)
  
  setwd(current_wdirectory)
  
}

Ok, now I can print tikz figures from any subdirectory without the printTikz() function attached above. The only requirement is to install de custom *.cls in the latex distribution. With the development version it is not necessary to install, but we need to locate *.cls file in the main folder. I had problems printing from child documents because I didn't put a copy of the *.cls file in the subdirectories of the child documents.
Definitely, the best thing is to install the *.cls class in our latex distribution