# Saving Canvas in TeX

Being able to generate TeX graphics can be useful for several reasons:

• To have an easy to modify the image, in particular the labels and titles (ASCII file).
• To have the same font in all labels, legends, plot titles etc. as in the text body of a document.
• Render Math formulae using TeX.

The TeX text engine is powerful and can render any complex math formulae. But more tricky is the graphics rendering: lines, polygons, markers etc ... One possibility is to render them using PDF or PostScript and render the text using TeX. But that’s not very practical as two files are needed to render one picture. A better way is to use a dedicated environment like PGF/TikZ.

“ PGF (A Portable Graphic Format for TeX) is a macro package for creating graphics. It is platform- and format-independent and works together with the most important TeX backend drivers, including pdftex and dvips. It comes with a user-friendly syntax layer called TikZ. “  (http://pgf.sourceforge.net/)

The new class TTeXDump allows to generate PGF/TikZ files. To generate a such file in ROOT it is enough to do:

             gStyle->SetPaperSize(10.,10.);
hpx->Draw();


Then, the generated file (hpx.tex) can be included in a LaTeX document (simple.tex) in the following way:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{plotmarks}
\title{A simple LaTeX example}
\date{July 2013}
\author{O.Couet}
\begin{document}
\maketitle
The following image as been generated using the TTeXDump class.
To include it in a LaTeX document it is enough to specify the following
three directives at the top of the LaTex document:
\begin{verbatim}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{plotmarks}
\end{verbatim}
Then to include the picture ({\tt hpx.tex} in this case) in a LateX
document it is done the usual way:
\begin{verbatim}
\scalebox{0.3}{\input{hpx.tex}}
\end{verbatim}
\par
\begin{figure}[htbp]
\begin{center}
\scalebox{0.5}{\input{hpx.tex}}
\caption{Image ({\tt hpx.tex}) generated thanks to {\tt TTeXDump}}
\end{center}
\end{figure}
\end{document}


### pgfplot

This is indeed a great feature. Are there any plans to make optionally use of pgfplot? This would enable us to keep plots from different sources consistent. I understand that the style wont match 1to1, but still it would be an improvement over the current output.

### pgfplot

This pgfplot is based on TikZ, like the TTextDump class in ROOT. It is as the same level as ROOT graphics. An interface to it from ROOT does not look appropriate. May be what you are thinking about is some utility reading ROOT histograms generating pgfplot ? That's totally a different issue. You may even prototype it yourself.

### Thanks for implementing this

Thanks for implementing this option! It makes life so much easier!

However one problem with the tikz export arises, when the #splitline{21 April 2003}{14:02:30} from TLatex is used. This leads to an "Undefined control sequence" in pdflatex.

### Thanks to mention it I will

Thanks to mention it. Now implemented in 5.34 and trunk.

### I'm very happy that this

I'm very happy that this feature is now implemented in root 5.34! However, the description might be misleading. Obviously, you have to create the object hpx with
TTeXDump * hpx = new TTeXDump("filename.tex");
before you can call the function hpx->Draw().
I also experienced that the last few lines in the .tex-file are missing, e.g. the y-axis labels and the \end{tikzpicture}.
Anybody experience with that?

### It is simpler than that ...

You do not need to make a TTeXDump object. As shown in the initial post you only need to print a canvas using Print(). The filename should have the extension .tex. Then include the result in your Latex file as explained above.

### Great news

Many thanks for implementing this feature! I have been waiting for this for a long time. Awesome!

### Many thanks for implementing

Many thanks for implementing this tex engine! Personally, I was always a bit unsatisfied about ROOT not being able to produce nice tex code for graphis. As far as I know under all the plotting tools only Gnuplot had a comparable tex engine so far.

### Thanks for this new feature.

Thanks for this new feature. Some time ago I migrated all my generation of graphs to PGFPlots, which uses pgf internally, for that I had to output my data in tables and afterwards process it with tex. Maybe now I can use the tex file generated by root directly. That would be very nice. I usually have to change my tex memory capacity limits to process tables with more than 2000 lines. If users hit this problem, then the PGFPlots manual explains how to do it. Cheers, Marcelo

### ROOT w/ TeX

I've been a big fan of PGF/TikZ for quite some time now -- it's very nice to see this available as part of ROOT graphics, thanks!

### This is awesome!

(I haven't tried this, yet, but) thanks for making this happen! I don't know that there are many people out there who really care about this, but... great!