# Laprint causing end of file during psfrag call

I am attempting to create and use file in my TeX document using laprint.m. The laprint function call produces the .tex and .eps files as expected. When I try to use \input{filename} though I get an error:

File ended while scanning use of \@@@psfrag \input{SparsAvgPerf}
followed by:
\begin{psfrags} on input line 14 ended by \end{document}. \end{document}


Both errors point to \end{document} in the uppermost file. The errors do not change whether the \input call is inside or outside of my figure environment. This is my first experience with laprint and psfrag, so I am not even sure where to begin debugging.

Edit:

    \documentclass{thesis}
\usepackage{psfrag}
\usepackage{graphicx}
\usepackage{color}
\begin{document}
\input{SparsAvgPerf}
\end{document}


A TeX file of only that produces the same errors, where SparsAvgPerf.TeX is in the same directory, and is the unmodified file created by laprint.m

-
Can you give a minimal example? You can't upload the EPS file, but you can show us the least amount of code producing the error. –  Torbjørn T. Dec 14 '11 at 15:36
As a side note, I'd rather use matlab2tikz I think. –  Torbjørn T. Dec 14 '11 at 15:38
A similar example, albeit with the article class and not some thesis class, worked fine for me, so I'm guessing that it's either something with the file generated by laprint, or some issue with the class (know idea what that could be though). –  Torbjørn T. Dec 14 '11 at 16:10
I tried as well with the standard article class and it caused the same problems. The matlab2tikz works beautifully though, so it looks as though I will be using that as an alternative. Thank you. –  Godric Seer Dec 14 '11 at 16:16
I added that as an answer then. If you still want an answer to the laprint issue, you should probably post either the SparsAvgPerf file, the .m file that created the file, or even both. –  Torbjørn T. Dec 14 '11 at 16:23

Another way of getting nice plots from MATLAB to a LaTeX document is to use matlab2tikz, which creates a TikZ/PGFplots figure that can be input to your document.

This has the added benefit of working with pdflatex as well.

## A simple example

While the use is fairly straightforward, I thought I might add an example.

Below is a very simple MATLAB script, the TikZ/PGFplots file generated by this, and a minimal LaTeX document, where it is used. matlab2tikz must of course be in MATLABs path. Add the folder to the path by selecting File --> Set path in MATLAB.

Specifying the width and height of the plot in the MATLAB script isn't necessary. Neither is using custom macros, e.g., \plotw and \ploth to define the width and height. The manual of matlab2tikz mentions this, so that it's a notch easier to change the parameters from within the LaTeX document. And if you have several figures that should be the same size, it is definitely convenient.

The .m-file

x = -10:1:10;
y = x.^2;
plot(x,y)
xlabel('x')
ylabel('x^2')
title('Lovely plot')
matlab2tikz('demo.tex','width','\plotw','height','\ploth')


demo.tex

% This file was created by matlab2tikz v0.1.4.
% Copyright (c) 2008--2011, Nico Schlömer <nico.schloemer@gmail.com>
%
%   http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
% where you can also make suggestions and rate matlab2tikz.
%
\begin{tikzpicture}

\begin{axis}[%
scale only axis,
width=\plotw,
height=\ploth,
xmin=-10, xmax=10,
ymin=0, ymax=100,
xlabel={$x$},
ylabel={$x^2$},
title={Lovely plot},
axis on top]
color=blue,
solid
]
coordinates{
(-10,100)(-9,81)(-8,64)(-7,49)(-6,36)(-5,25)(-4,16)(-3,9)(-2,4)(-1,1)(0,0)(1,1)(2,4)(3,9)(4,16)(5,25)(6,36)(7,49)(8,64)(9,81)(10,100)
};

\end{axis}
\end{tikzpicture}


LaTeX document

\documentclass{article}
\usepackage{pgfplots}
\usepackage{kantlipsum} % for a little dummy text
\newcommand\plotw{8cm}
\newcommand\ploth{4cm}
\begin{document}
\kant[1]
\begin{figure}[h]
\centering
\input{demo}
\caption{Plotting}
\end{figure}
\kant[2]
\end{document}


-