TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.



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

share|improve this question
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
up vote 2 down vote accepted

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;
title('Lovely plot')


% This file was created by matlab2tikz v0.1.4.
% Copyright (c) 2008--2011, Nico Schlömer <nico.schloemer@gmail.com>
% All rights reserved.
% The latest updates can be retrieved from
%   http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
% where you can also make suggestions and rate matlab2tikz.

scale only axis,
xmin=-10, xmax=10,
ymin=0, ymax=100,
title={Lovely plot},
axis on top]
\addplot [


LaTeX document

\usepackage{kantlipsum} % for a little dummy text

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.