# Save a gretl graph in TikZ format

Tikz is a very powerful language for describing graphical objects, which integrates very well with LaTeX.

Here are a few instructions on how to use gretl for producing TikZ files and inserting them into a LaTeX file.

Warning: this works on Linux but is untested on OSX and Windows.

# Creating the TikZ file: the slow easy way

• First, create your graph, via a script or interactively. For example, if you run the script below, you should have a decently-looking picture of the trade balance in the Euro area between 1970 and 1998:
open AWM --quiet
series tbal = XTN - MTN
list X = XTN MTN tbal

plot X
option with-boxes=tbal
literal set key below
options time-series with-lines
end plot --output=display

which should look more or less like this:

• Right-click on your graph and choose "Save your session as icon".
• At this point, you will need to modify the gnuplot source to your graph; right-click on the graph icon and choose "edit plot commands". Insert these two lines at the beginning:
set terminal lua tikz createstyle

Running this script (click on the "gears" icon) will create a file called tradebal.tex, which contains the TikZ code, plus a bunch of other auxiliary files, among which one named gnuplot-lua-tikz.sty.

# Creating the TikZ file: the fast easy way

If you use a script, you can combine all the above in a script file and include the extra gnuplot command in your plot environment, as follows:

plot X
literal cd "@workdir"
literal set terminal lua tikz createstyle
option with-boxes=tbal
literal set key below
options time-series with-lines
end plot --output=@dotdir/empty.ps

The --output=@dotdir/empty.ps bit is to trick gretl into calling gnuplot, but no real output should be produced. At the end of this you should end up with a zero-byte file in your gretl temporary directory, and the relevant files in your working directory.

Update 21-11-2015 Allin just made a commit to git: with gretl 2015e you can just do

plot X
option with-boxes=tbal
literal set key below
options time-series with-lines

Warning: this is a good time to inspect your TikZ file. For example, check if there's anything that may confuse the TeX interpreter, like percent signs or dollars in the gnuplot labels.

After that, there are basically two things that you have to take care of:

1. put the \usepackage{gnuplot-lua-tikz} command in your preamble;
2. include your TikZ picture in your LaTeX document, either by inserting the contents of the file you just created into your document or (better) by using the LaTeX \include or \input commands.

For example:

\documentclass[a4paper]{article}
\usepackage{gnuplot-lua-tikz}
\begin{document}
\begin{figure}[htbp]
\centering