user8420488483439
user8420488483439

Reputation: 361

Reducing the output file size of tikzDevice

I'm writing a large latex document with lots of plots generated by R's tikzDevice package. Currently, I'm experiencing LaTeX error "TeX capacity exceeded".

I've managed to fix this issue temporarily by following the remedy from Leo Liu's answer here (I've also tried the accepted answer from the same source), but this solution is temporary as I said, because eventually, I will be adding many more plots to my document with at least 1 meg per plot. Some people say that LuaTex dynamically allocates memory so it is never an issue with LuaTex (same source); however, I have a big document and limited time available, so converting to LuaTex is not an option (unless there is an automatic conversion software).

During my search, I found this post by chance talking about the same problem but with matlab's matlab2tikz package. The solution there is to reduce the number of samples in the plot and thus reduce the size of the resulting file. I looked up R's tikzDevice documentation (here and here) for a similar option, but was not able to find one unfortunately.

So the question is: How can I control the size of the plots (tikzpictures) generated by tikzDevice?

Upvotes: 2

Views: 1787

Answers (1)

lbelzile
lbelzile

Reputation: 185

One workaround is to export the file produced by tikzDevice with option standAlone = TRUE. Compile the resulting file with lualatex to avoid the error message "TeX capacity exceeded". This can be done directly from R, using e.g.

tikz(figure.tex, standAlone = TRUE)
...
dev.off()
system("lualatex figure.tex; rm *.aux; rm *.log")

Then, include the file in LaTeX as a graphic using \includegraphics.

To reduce the size of the resulting pdf, you may wish to convert the image to a lossy compression format such as JPEG. Converting to postscript and back can also create smaller files, albeit at the cost of a loss of resolution.

Upvotes: 0

Related Questions