Feature suggestion: SaveAs(".tex")

Every publication and thesis I have ever worked on has at some point had the need to re-plot something for the sole reason of needing to change the labels. This is often an annoyance in my opinion.
Secondly, for the purpose of unified style it can be desirable to have the same font in all labels, legends, plot titles etc. as in the main text body of a document.

My suggestion: Add an option to canvas->SaveAs(“myfile.tex”) in LaTex format.

The resulting file would be a simple LaTex document which when compiled with latex or pdflatex would reproduce the figure from the canvas. The important part would be that the figure is drawn inside a LaTex ‘picture’ environment where all titles, labels and legends are added with a

or something similar. The point being that it is easy to change these in the .tex file without needing to replot.

The actual figure, i.e. graphs, axes, lines could be drawn by the picture environment also, but it may also be more suitable to just generate a pdf document along with the .tex file that can then be included.

I would have a look at making this myself but don’t have the time right now. So I’m throwing this idea out there in case someone else is interested in a little programming challenge.

We had something like that in the old PAW. I am not sure it was using this picture environment you mention here, but it was using Latex. The text look great but the graphics was ugly.

I would not consider as an issue the fact you want to change labels on existing plots. I would recommend you to re-execute the macro with produced the plot and modify it. Or even the ROOT file containing the ROOT canvas and modify it.

The look of the formulae is something else. We are now working on a new class called TMathText which render the Latex text much better than TLatex (it looks really like the real Latex). There is still work to do but we are already able to see the plot results on screen and in PS files (which cover a large part of the need)

I just found out that inkscape now provides a command-line option which does exactly what I was suggesting but starting from a .svg file. So there does seem to be a use-case after all.

see this tutorial ftp://ctan.tug.org/tex-archive/info/svg-inkscape/InkscapePDFLaTeX.pdf

It is now possible to export any .svg file to two files, one pdf file containing only the graphics, and one .tex file containing all the labels. This way it is possible to typeset the labels on the graphics in a consistent format.

Making something that looks really like latex is great, but if I am already using LaTeX for my document, why should I not also use it for my labels.

BTW, I have tested this with the a .svg output from ROOT and it works fine. I can use this work-flow in the future, but I still think this would be a nice feature to have in ROOT.

I used a similar functionality in gnuplot, which produced an eps file just the graphics and a corresponding .tex snippet containing just the text elements (including axes, labels, etc). You would then include them in your latex document using \input. Then all your labels and axes follow the style of the containing LaTeX document.

I would very much appreciate this kind of functionality in ROOT.


So you would like that all the lines, filled area, and markers go in one file (pdf or eps) and that the text go in a latex file ?
I am not really sure how to do that … in particular how to make sure that the text will be in the right place when you superimpose the to files… Well may be the best is to look at what this tutorial ftp://ctan.tug.org/tex-archive/info/svg … FLaTeX.pdf does…

I will test with an SVG root file

The problem with this method is that on the screen you will get the Latex marksup. They will be interpreted only at the LaTex compilation time …
If that method works with SVG ROOT files may be that’s good enough ?

I have tested some more. It is possible to do this transformation with inkscape also starting from a .pdf as well as a .svg. It literally just pulls all text out of the pdf and puts it in a Latex picture environment with x-y offsets using a ‘put’ command. This includes all titles, labels, legends and axis units.

I have tried it on an example ROOT plot and encountered the following issues:
[li]Text that has been typeset using Latex maths environment such as “#beta^{2} value” will appear in several different text boxes, one for the “#beta”, one for the “2” and one for the " value".[/li]
[li]Greek letters are simply in their unicode format. Latex cannot handle this in the input, so the beta from above has to be converted back into a “$\beta$” before Latex will parse the tex file.[/li]
[li]Text sizes are not preserved. All text in the “picture” environment is normal text size. This might be a bug or a feature because the above tutorial states that the idea behind the functionality is consistent typesetting in a Latex document, so one might exactly want the text to be typeset the same as the document text. The reason it is an issue it the next point:[/li]
[li]All text is aligned to its bottom left corner. This would be fine if all text sizes were preserved, but is an issue as soon as text sizes change, because it messes up, for example, the centering of titles etc.[/li][/ul]

Here is how I would address these issues if I knew where all the relevant code is: I assume all text comes from a TText or something of the sort. That is where this method should differ from normal pdf rendering. Text from one TText should come out into one single ‘put’ command. Maths items can be translated to real Latex maybe. Secondly, somehow save the alignment. It is possible to generate Latex that aligns a text to a corner or to the center for any text size, as long as the anchor point is known.

If these issues were addressed I think the result would be much more usable than what Inkscape generates.

In inkscape the output file name is given as “name.pdf” and inkscape then generates “name.pdf” and “name.pdf_tex”. The naming is fine I think, ROOT might have something like SaveAs(“name.pdf_tex”) to generate the same two files. However, I think that the .pdf_tex file should be made such that it is typesettable straight away, i.e. it should contain a full document. This would allow one to check the result more quickly.

I realise that the result would never be identical to the image that is seen on screen on the TPad. I do not think that this is an issue, although others may disagree of course. The user can always chose to SaveAs(".pdf") if a more precise result is required.

Although I am an experienced user of ROOT, then entire graphics part its a complete black box to me. I don’t know if would be as straight forward to implement this as I am imagining.

Surely not straight forward …

I need to understand what this inkscape does, I had no time to try. I am not sure I fully understand what you are requesting from ROOT.
I am surprised you have alignment issue with PDF because this is treated before the PDF generation and in the PDF file itself all the text is bottom left …

Ok I will try to see how this inkscape works …

Can you provide an example of you would like ?
The eps file, the tex file with text and the Latex file in which is included the picture.
So I can try myself and see what to do… It looks like you have this already … that will same me some time.

Maybe I’ve got another question.
Why do you say that LaTeX doesn’t support UTF?
As far as I remember, there exists:

BTW. The possibility of getting a separate external LaTeX file with “descriptions” would probably allow one to “overwrite” ASCII characters in figures with any national characters (as ROOT itself supports iso8859-1 encoding only).

we are working on a new class called TMathText which does that. See the attached picture

Here are the snippet and pdf image file produced by the gnuplot “epslatex” terminal.

The forum wouldn’t allow me to upload the original .eps file, and annoyingly I had to rename the .tex file to .tex.txt.
f_n_plots.pdf (8.63 KB)
f_n_plots.tex.txt (4.5 KB)

But how these two files should be used ? what would be the Latex file including them ?

Just a small note: the “.eps” and “.tex” attachment extensions should be allowed now.

For the two files that I posted, I include them in a full LaTeX document with:

\caption{Probability density functions for ionization event distances
  along the track.}

I think that the graphicx package is required, and maybe amsmath for symbols too.

I’m not 100% sure, but I think if I have the figures as both .eps and .pdf available, then the document compiles fine with latex (to dvi) or pdflatex (to pdf). I think the f_n_plots.tex snippet is smart enough to use the right one. This is because the snippet doesn’t contain the string “eps” or “pdf” anywhere, it just has this line:


I have now also attached the original .eps file produced by the gnuplot “epslatex” terminal, which also produced the f_n_plots.tex snippet. The pdf file I attached earlier was made using “epspdf”.

Also some relevant links about the gnuplot epslatex terminal:
stuff.mit.edu/afs/athena/softwar … de373.html
gnuplot-tricks.blogspot.ca/2009/ … it-is.html
f_n_plots.eps (31.5 KB)

I need to understand what this inkscape does, I had no time to try. I am not sure I fully understand what you are requesting from ROOT.
I am surprised you have alignment issue with PDF because this is treated before the PDF generation and in the PDF file itself all the text is bottom left …

Ok I will try to see how this inkscape works …[/quote]

Let me first of all emphasize that this is a suggestion, not a request. This is lowest priority IMO. It is merely an idea.

Here are some examples to work with:


void makeplot(){
    TCanvas *tc = new TCanvas("c","c",400,300);
    TH1 *h = new TH1D("h","My Histogram of beta;beta;#beta^{2}",100,0,1);
    TH1 *h2 = new TH1D("h2","My Histogram of #beta_{MS}^{2};#beta^{2};forgot braces #beta^2",100,0,1);




mkdir tmp; cd tmp
root -q -b ../makeplot.C 
inkscape -D -z --file=nice_root.pdf --export-pdf=nice_inkscape.pdf --export-latex
inkscape -D -z --file=nasty_root.pdf --export-pdf=nasty_inkscape.pdf --export-latex
pdflatex -jobname nice_final "\def\infile{nice_inkscape.pdf_tex}\input{../document.tex}"
pdflatex -jobname nasty_final -halt-on-error "\def\infile{nasty_inkscape.pdf_tex}\input{../document.tex}"

Put all three files in one directory and execute runall.sh. The final line will fail.

for me the result nice_final.pdf looks terrible with inkscape flipping the coordinates and cutting parts of the figure off. I have included the result here for reference. Of course nasty_final.pdf doesn’t even compile because of the unescaped special characters.

Notice the absence of the beta character from nice_final.pdf. Trying the inputenc line I get this error:

! Package inputenc Error: Unicode char \u8:β not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
l.66 ...ebox{-180}{\makebox(0,0)[lb]{\smash{β}}}}
? ^D
! Emergency stop.

My thought was mainly that it would be possible to get a better result if going from ROOT directly.

This was my example of the status quo. I may get 'round to making a nice-to-have example in a few days, but I’m really busy right now with writing my thesis so don’t hold your breath :wink:

oops, forgot to include the file like I said. Here it is.
nice_final.pdf (21 KB)

@jfcaron: it does not show any picture.

\title{ROOT LaTex output ?}
\author{Olivier Couet}
\date{October 2012}

\caption{Probability density functions for ionization event distances along the track.}


I don’t know what to tell you couet, I put the exact LaTeX from your post into a document and compiled it with pdflatex. The image shows up on the second page. I have both f_n_plots.eps and f_n_plots.pdf in the same directory (it must be using the pdf image, since it’s pdflatex), along with f_n_plots.tex.

I attached the outputted files (with .txt appended to the log files).

textdoc.aux.txt (191 Bytes)
textdoc.log.txt (7.23 KB)
textdoc.pdf (49.9 KB)

I am using plain Latex on mac …