Saving Canvas in Tex awesome! But long compiling time

Hi rooters.
I was really surprised when I read root.cern.ch/drupal/content/saving-canvas-tex but I find a problem, when I print the canvas in a (.tex) file, it is too big. Around 3 or 4 times the size of a (.pdf) print. And after input it in the main .tex, the compiling time increases a lot, the compiler spends around 2 minutes with five images. That does not happen using Gnuplot’s epslatex output.
What could be the reason?
Im using Root 5.34/21, and when I use .tex print the following warning message appears: Warning in TTeXDump::DrawFrame: not yet implemented

Here an image used.
https://www.dropbox.com/home/texroot

And the Latex input

\usepackage{tikz} \usetikzlibrary{patterns} \usetikzlibrary{plotmarks}

\begin{figure}[H] \begin{center} \scalebox{0.5}{\input{images/plastic_gain_semilog.tex}} \end{center} \end{figure}

I am compiling with pdflatex.
Thanks in advance.

There is a big difference in how gnuplot’s latex output and ROOT’s work.

(This is all from memory, maybe I got some parts wrong):
Gnuplot outputs two files: a .ps file with all the graphical elements (lines, colours, boxes), and a little snippet .tex file that does any text (axis tickmarks, labels, legend). The .tex snippet also takes care of including the graphical file. So when you include the gnuplot snippet in your document, very little processing actually has to be done: just the text labels.

ROOT on the other hand uses tikz to describe every part of the plot. So each line, point, and colour is drawn using tikz commands, instead of PostScript. The translation of the tikz commands into the output format is what takes a long time, and makes the output file quite large.

I tried using the ROOT tex output, but for certain kinds of plots (2D coloured histograms) the compilation time was unreasonable. Even with a reasonable number of bins, it was too much. For basic 1D histograms and TGraphs without too many points, it’s fine. Given this problem, I wouldn’t switch to using the tex output for everything just yet. Unfortunately given the way it is implemented, there is no real “fix”.

Jean-François

Yes Jean you are right that is exactly how Gnuplot works.
I was also reading this talk [url]Plot mode similar to gnuplot’s epslatex and I realized it is an old discussion. I believe that something like epslatex ouput would be nice, it has not to work in the gnuplot way, but a LaTeX friendly out should be implemented, the (.tex) output is also nice but is like spend unreasonable compiling time just to produce an “infinity” resolution image, that even the eyes can not distinguish.

I use ROOT for the data analysis and Gnuplot for the plots, however when the plots depends of the analysis parameters, the work becomes harder and tricky ( for example, I did a program that compares two similar shape experimental data draws but with different height and width, basically it makes an axis scaling based in the maximun and the FWHM, but it have to print the actual axis for both draws which depends of the scale parameters. A more simple example is just draw a legend with the number of entries and the mean.). In this cases I prefer print the Canvas.

Andres Navarro.

You could maybe look into this C++ library for talking to gnuplot: http://www.stahlke.org/dan/gnuplot-iostream/

Then even if there are dynamic parameters in the analysis, they can be used to set the proper values on the gnuplot side via TString::Format or something.

Jean-François

Sounds weird… ROOT is able to do plot as good a gnuplot even better I think (specially the axis)

The TeX output of ROOt is not meant to be compact du to produced the same look and feel ans TeX itself. You even get a different look than what you get on screen. But for some better having the same exact font as TEX is important. The TeX output is all ascii. Not compressed. If you want compress file use PDF.

Thanks for your reply, couet.

Yes you are right is something weird, that’s why when I read your article about Tex output I said: nice Now ROOT can do all Gnuplot’s work!, let’s forget Gnuplot! however Gnuplot’s epslatex output and Root’s .tex ouput are complete different. I think that the Root’s .tex ouput is actually useful in several cases, but something like a epslatex would be also nice, because we could print in a compressed mode (pdf , eps , png , jpg…) the graphical elements and the text with TeX fonts, in this case compiling time would not be a problem in big documents like books and the Tex format would be conserved; as you said:

Otherwise, the images would not be compact and therefore, long compiling time would be spent (Tex output of ROOT) or the images would not have latex fonts (pdf, eps, png , jpg outputs).

Cheers.

It looks like it’s possible to include “inline” pdf figures in TeX: http://tex.stackexchange.com/questions/174252/include-pdf-via-pdfliteral

I haven’t looked into it enough to know if this is reasonable, but possibly ROOT’s TeX output could use these “inline” pdfs for the graphics and TeX for the text, all in one file.

Jean-François

Hi Andres,

Can you post here the kind of plot you do with gnuplot you can do with ROOT ?

Olivier

Sure!

Here Gnuplot’s plots.
4shared.com/file/ngBsYVOPba/l_online.html
4shared.com/file/kYn4Dis0ce/l_online.html

And Here Root’s plots
4shared.com/file/11w4gtIEce/ … cuado.html

The download looks tans form this place… Did not work for me.
Can you post the file here ?

Sorry I did not see the Upload attachment tab.
plastic_Voltage_Adecuado_semilog.tex (511 KB)
l.tex (4.24 KB)
l.eps (22.7 KB)

Thanks. Can you also provide a master TeX file using this 2 pictures ?

Here it is.

You are right about resolution and image quality is better with Root output, however, a big project will spend long compiling times. I was reading and I found that I could compile the main TeX using makefile in orden to avoid do “recompile” each image.
plastic_Voltage_Adecuado.tex (511 KB)
Root.tex (282 Bytes)
w.eps (161 KB)
w.tex (4.4 KB)
Gnuplot.tex (196 Bytes)

As usual with gnuplot, axis are always labeled from the beginning of the axis up to the end, not doing the axis label optimisation ROOT does … but fine … we know that…

I looked at the file Root.pdf generated when doing “pdflatex Root.tex”. This plot as nothing special which would require the use of the TeX output. I think, if the size is an issue for you, you can use the PDF file generated by ROOT with the “Times” font and you will get something very close to the TeX output (and very compact) …

Thanks Olivier for the replies :smiley: . Yes, size is a really important issue and resolution also; So solution to this “problem” for me is to use TeX ROOT’s output and compiling the main Tex using makefile.
Let’s forget about Gnuplot! :smiley: :smiley:

PS: Sorry for the spelling mistakes.

Two suggestions for Andres:

  1. For very big 2D histograms, pdflatex crashes when compiling. The solution is to use “lualatex” instead. See also Colored 2D histograms in pdf output - #45 by ferhue

  2. In Latex, you can also use “tikzexternal” for not slowing down your compilation time, for example with the mode “list and make”, that saves the temporary pdf images in the subdirectory “build/i/”. This way you separate the translation of the figures to “.pdf” from the actual compilation of your main tex document.

\tikzexternalize[mode=list and make, prefix=i/]

I use TexMaker with the “build” subdirectory option on, and I still use a Makefile for regenerating figures (stored in Figures/ subfolder) if you are modifying them (as tikz only looks if the build/i/.pdf was modified, not the respective Figures/.tex):

ALL_FIGURE_NAMES=$(shell cat build/MyProject.figlist)
ALL_FIGURES=$(ALL_FIGURE_NAMES:%=build/%.pdf)

all: $(ALL_FIGURES)
        
build/i/%.pdf : Figures/%.tex
        pdflatex -shell-escape -halt-on-error -interaction=batchmode -jobname "$(subst build/i/,i/,$(@:.pdf=))" "\def\tikzexternalrealjob{MyProject}\input{MyProject}" 

clean:
        rm -r build
        mkdir -p build/i

Note that you also need to set a link in your main folder:

ln -s build/i/ i/

And to compile everything at the same time

make && pdflatex -shell-escape -synctex=0 -output-directory=build/ -interaction=nonstopmode MyProject.tex

There might be a cleaner option, but this one works fine.

You have not answered my question. I ask again:

Why don’t you use the PDF files directly produced by ROOT ?