# Problems with including a tikz tex file generated by Octave (MatLab clone)

I have plotted a figure in Octave and printed it as a TikZ figure (see the device option) to a tex file called comparison_tikz.tex, and I have imported it into my document with the line

\input{comparison_tikz.tex}


I have also included the tikz package in the preamble of my document. However, when I try to compile the document, I get the following errors:

line 17   Use of \tikz@parse@cs@xy polar doesn't match its definition ...gb]{0,0,0}{{25}}}{}{\pgfusepath{discard}}}
line 17   Extra }, or forgotten \endgroup ...gb]{0,0,0}{{25}}}{}{\pgfusepath{discard}}}
line 0    Missing control sequence inserted


I tried to google it but I couldn't find anything about the error. I see that it complains about something with polar coordinates, but the plot I've made doesn't use polar coordinates.

When I double click on any of the error messages, it takes me to line 17 in the generated file (which looks almost exactly like other lines in the file). Anyway, here is the beginning of the file:

% Title: glps_renderer figure
% Creator: GL2PS 1.3.6, (C) 1999-2011 C. Geuzaine
% For: Octave
% CreationDate: Wed Jun 13 08:48:06 2012
\begin{pgfpicture}
{
\pgftransformshift{\pgfpoint{246.399994pt}{73.195633pt}}
{
\pgftransformshift{\pgfpoint{333.199982pt}{73.195633pt}}
{
\pgftransformshift{\pgfpoint{419.999969pt}{73.195633pt}}
{
\pgftransformshift{\pgfpoint{506.799957pt}{73.195633pt}}
\pgfnode{rectangle}{north}{\fontsize{10}{0}\selectfont\textcolor[rgb]{0,0,0}{{25}}}{}{\pgfusepath{discard}}} % This is the line causing the error
{
\pgftransformshift{\pgfpoint{67.799995pt}{78.200020pt}}
{


If I print the plot as a tex figure instead and try to include that it also gives me an error when I try to compile the document; the generated tex file then looks like

% Title: glps_renderer figure
% Creator: GL2PS 1.3.6, (C) 1999-2011 C. Geuzaine
% For: Octave
% CreationDate: Wed Jun 13 08:48:05 2012
\setlength{\unitlength}{1pt}
\begin{picture}(0,0)
\includegraphics{}
\end{picture}% This is the line causing the error
\begin{picture}(576,412)(0,0)
\fontsize{10}{0}
\selectfont\put(246.4,33.1956){\makebox(0,0)[t]{\textcolor[rgb]{0,0,0}{{10}}}}
\fontsize{10}{0}
\selectfont\put(333.2,33.1956){\makebox(0,0)[t]{\textcolor[rgb]{0,0,0}{{15}}}}
\fontsize{10}{0}
\selectfont\put(420,33.1956){\makebox(0,0)[t]{\textcolor[rgb]{0,0,0}{{20}}}}
\fontsize{10}{0}
\selectfont\put(506.8,33.1956){\makebox(0,0)[t]{\textcolor[rgb]{0,0,0}{{25}}}}
\fontsize{10}{0}
\selectfont\put(67.8,38.2){\makebox(0,0)[r]{\textcolor[rgb]{0,0,0}{{0}}}}
\fontsize{10}{0}
\selectfont\put(67.8,95.25){\makebox(0,0)[r]{\textcolor[rgb]{0,0,0}{{0.005}}}}
\fontsize{10}{0}
\selectfont\put(72.8,33.1956){\makebox(0,0)[t]{\textcolor[rgb]{0,0,0}{{0}}}}
\fontsize{10}{0}
\selectfont\put(159.6,33.1956){\makebox(0,0)[t]{\textcolor[rgb]{0,0,0}{{5}}}}
\fontsize{10}{0}
\selectfont\put(67.8,152.3){\makebox(0,0)[r]{\textcolor[rgb]{0,0,0}{{0.01}}}}
\fontsize{10}{0}
\selectfont\put(67.8,209.35){\makebox(0,0)[r]{\textcolor[rgb]{0,0,0}{{0.015}}}}
\fontsize{10}{0}
\selectfont\put(67.8,266.4){\makebox(0,0)[r]{\textcolor[rgb]{0,0,0}{{0.02}}}}
\fontsize{10}{0}
\selectfont\put(67.8,323.45){\makebox(0,0)[r]{\textcolor[rgb]{0,0,0}{{0.025}}}}
\fontsize{10}{0}
\selectfont\put(67.8,380.5){\makebox(0,0)[r]{\textcolor[rgb]{0,0,0}{{0.03}}}}
\end{picture}


line 0    File ' not found.


and when I double click on the message it takes me to line 8 in the generated file.

What is it about these files that LaTeX doesn't like? I think they should work properly since it is Octave that has generated them. Do I need to set up my document in some certain way in order to be able to use the files?

Edit 1 (Solved): Here is a minimal (not) working example for the tex figure:

\documentclass[]{report}
\begin{document}

\input{comparison.tex}

\end{document}


where comparison.tex is the latter of the two generated tex files included above. This gives me the compilation error

line 11   Undefined control sequence ...box(0,0)[t]{\textcolor[rgb]{0,0,0}{{10}}}}
line 13   Undefined control sequence ...box(0,0)[t]{\textcolor[rgb]{0,0,0}{{15}}}}


and so on for the lines 11, 13, 15, ... 35 in comparison.tex. It highlights the \put and the \makebox macros in the code.

Edit 2: And here is a minimal (not) working example for the TikZ figure:

\documentclass[]{report}
\usepackage{tikz,graphicx,color}
\begin{document}

\input{comparison_tikz.tex}

\end{document}


where comparison_tikz.tex is the former of the two generated tex files included above. This gives me the compilation error

line 17   Use of \tikz@parse@cs@xy polar doesn't match its definition ...gb]{0,0,0}{{25}}}{}{\pgfusepath{discard}}}
line 17   Extra }, or forgotten \endgroup ...gb]{0,0,0}{{25}}}{}{\pgfusepath{discard}}}
line 0    Missing control sequence inserted
line 0    \begin{pgfpicture} on input line 5 ended by \end{document}.

-
Could you provide us with a 'complete' minimal (not) working example? This is: plot a line with octave and show us all the files you obtain and how do you include them in a complete .tex document (from \documentclass{} to \end{document} with all necessary \usepackage.) –  Ignasi Jun 13 '12 at 11:05
@Ignasi: Fixed. I don't really know which packages the generated code expects so I didn't include any. Heck — it doesn't work anyway. –  StrawberryFieldsForever Jun 13 '12 at 11:42
Which TikZ/PGF version are you using? –  Martin Scharrer Jun 13 '12 at 14:15
@Martin: How can I find that out? All I know is that I'm using TeXstudio 2.3 which I installed a few weeks ago. I don't even remember if I've installed MikTeX manually, but I see that MikTeX 2.9 is installed on the computer. –  StrawberryFieldsForever Jun 13 '12 at 14:59
Package versions are independent from the MiKTeX version. The simplest way is to look in the log file, especially if you use \listfiles. The MiKTeX package manager will also tell it and can be used to update the package if it is too old. –  Martin Scharrer Jun 13 '12 at 19:50

Your MWE uses commands from the graphicx and color packages but does not load them so produces errors about undefined commands. So it needs to be

\documentclass[]{report}
\usepackage{graphicx,color}
\begin{document}

\input{comparison.tex} % Uses commands from the graphicx and color packages

\end{document}


Then line 7 of the included file is

 \includegraphics{}


which is nonsense, including a graphic without specifying a file name, so you get an error about a missing file.

If you change that to

%\includegraphics{}


It runs without error.

-
Thanks! It's strange though that Octave would generate tex code that won't compile. –  StrawberryFieldsForever Jun 13 '12 at 14:54

I found a partial solution to the TikZ issue. The Octave documentation says that FLTK produces PGF code. That means all plots created while using FLTK for the graphics will be saved as a PGF picture. On the other hand gnuplot will create TikZ pictures. These do compile if you do the following:

1. Find gnuplot-lua-tikz.sty. The path should be something like C:\octave\gnuplot\share\texmf\tex\latex.
2. Add the directory called texmf to the list of registered root directories via MiKTeX Options.
3. Add \usepackage{gnuplot-lua-tikz} to the preamble of your document.
4. In Octave, execute graphics_toolkit('gnuplot') before you do any plotting. Then save your plots using the -dtikz option as before, and \input the created file.

The PGF code generated by FLTK remains an unresolved issue.

-
If I replace the pgfpicture environment with tikzpicture environment and don't touch the content in the question it compiles properly. But for such operations I would recommend exporting the data and using pgfplots as is evident from the plot that the code is far from optimized. –  percusse Dec 21 '12 at 17:41
Funny you should mention that you found a partial solution the same day I found this page. It is an octave script that generates TeX code using the pgfplot package, and it works if all you want is to do basic curve plotting, and the results look quite okay. It needs some modification though if you want to use some of the more advanced features of pgfplot. –  StrawberryFieldsForever Dec 22 '12 at 14:00
The solution I found was to use this octave script which generates TeX code using the pgfplots package. It's limited, but it can do basic curve plotting, but needs some modification if you want it to support the more advanced features of pgfplots.
If you are interested in this kind of conversion, you may want to take a look at the matlab2tikz` project. Perhaps it works for octave as well - and it allows quite sophisticated results. –  Christian Feuersänger Jan 26 '13 at 20:57