File Exchange

image thumbnail


version (21.6 KB) by Arno Linnemann
LaPrint prints a MATLAB figure to file for neat inclusion in LaTeX documents.


Updated 14 Sep 2004

No License

LaPrint is a MATLAB function to print MATLAB graphics for inclusion in LaTeX documents. LaPrint creates an eps-file and a tex-file. The tex-file contains the annotation of the figure such as titles, labels and texts. The eps-file contains the non-text part of the figure and is called by the tex-file.

The main advantage of using LaPrint is that the annotation can be neatly (e.g., including math mode and fancy font constructs) set within LaTeX. LaPrint can be used from the command line or via a graphical user interface (GUI).

Current Version is 3.16. Matlab 6.1 or above is required.

An Users Guide for LaPrint is available at

Cite As

Arno Linnemann (2021). LaPrint (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (109)

David Schnermann

Hasn't there been an update since 2004?

Change line 786 to: if ~isgraphics(figno,'figure')
That solve the problem.

I've checked that it still does not work with legends.

Ewan Short

Hi Antonio,

Unfortunately I'm getting errors using laprint.m. I'm calling it through the plotpdftex.m package ( and I get the following error.

Error using laprint (line 788)
This is not a figure handle.

I'll post this to the author of plotpdftex.m as well. Cheers,

Ewan Short

Fix for LaPrint '3.16 (13.9.2004)'
To avoid errors in newer MATLAB versions, change:

Line 2451 to: set(LAPRINTHAN.figno,'string',num2str(LAPRINTOPT.figno.Number))

Line 1530 to: label = str2num(ticklabel{k,:});

Line 1790 to: cmd = strrep(cmd,'<figurenumber>',int2str(figno.Number));

To avoid num2str error in newer MATLAB versions, change line 2451:
From: set(LAPRINTHAN.figno,'string',num2str(LAPRINTOPT.figno))

To: set(LAPRINTHAN.figno,'string',num2str(LAPRINTOPT.figno.Number))

Jonas Hahlbohm

Hello, psfrag replace the axis label with pixel font in a mesh. With a normal plot the axis label are vector font.


In new MATLAB releases not only the default text interpreter should be set to none but also the legend interpreter:



@Torsten, I am having the same problem with the legends that are not converted to psfrag objects, as I also running MATLAB 2016a.


Inconsistent axis tick values (math font vs text font)
When using log (base 10) scales in figures, laprint converts these incorrectly into, e.g., \psfrag{x01}[t][t]{$10^{10^{-1}}$}, i.e., a “double base 10”
I could fix this by changing line 1970
fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{$10^{' ...
fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{${' ...

Then laprint converts the log scales into, e.g., \psfrag{x01}[t][t]{${10^{-1}}$}%, which is still not OK. In order to get consistent tick values, it should be converted into \psfrag{x01}[t][t]{$\text{10^\text{-1}}$}%, i.e., no math fonts! The linear scales are also in text font!
I could do this for each figure by hand, however I would like to automate it. Does anybody know what I need to change in the laprint file?

It seems pretty hard to find out how to do this when using log (base 10) scales.

In any case, the following lines, should be changed if there is just a power of 10
Line 1919
'}[Bl][Bl]{$\\times 10^{' ...
'}[Bl][Bl]{$\\times \\text{10}^\\text{' ...

Line 1929
Do oldtl{i}{nlabel(i)} Do '$\\times 10^{'...
Do oldtl{i}{nlabel(i)} Do '$\\times \\text{10}^\\text{' ...

Line 1934
Do oldtl{i}{nlabel(i)} Do '\\\\$\\times 10^{'...
Do oldtl{i}{nlabel(i)} Do '\\\\$\\times \\text{10}^\\text{' ...

Line 1948
Do oldtl{i}{nlabel(i)} Do '\\\\$\\times 10^{'...
Do oldtl{i}{nlabel(i)} Do '\\\\$\\times \\text{10}^\\text{' ...

Line 1952
'}' poss '{\\shortstack{$\\times 10^{' ...
'}' poss '{\\shortstack{$\\times \\text{10}^\\text{' ...

Line 1964
'\\begin{picture}(0,0)\\put(0.5,1.5){$\\times 10^{' ...
'\\begin{picture}(0,0)\\put(0.5,1.5){$\\times \\text{10}^\\text{' ...


I have a problem with legends that are no longer being converted to psfrag objects by laprint. Now running ver. 2016a. Back in 2008 no such problem was experienced.

Tobias Birnbaum

@Gerald: Thank you so much for your tips.
I run Matlab 2015b and got only errors from using the GUI first. After a while I noticed that hf.UserData in the LaPrint figure wasn't set. But it wasn't till much later that I looked in here to search for advice.

The third of your fixes (line 2450) repairs the updategui function which should set that "UserData".

The second fix (line 2450) looks genuine to me.

As in, those two fixes seem to follow the authors intent.

For the first fix (line 1530), I'd suggest using:

label = str2num(ticklabel(k,:)); ==>
label = str2num(ticklabel{k,:});

as your solution seems to miss set the ticklabels by using only the first one.

@Arno: Please take those fixes into consideration, as this superbé script is dysfunctional otherwise.


@Emil: This can be fixed quite easily. There are 3 small errors:
- Around line 1530: label = str2num(ticklabel(k,:)); ==> label = ticklabel(k,:); label=str2num(label{1});

- Around line 1790: cmd = strrep(cmd,'<figurenumber>',int2str(figno)); ==> cmd = strrep(cmd,'<figurenumber>',int2str(figno.Number));

- Around line 2450: set(LAPRINTHAN.figno,'string',num2str(LAPRINTOPT.figno)) ==> set(LAPRINTHAN.figno,'string',num2str(LAPRINTOPT.figno.Number))

DISCLAIMER: This fix works for me, but might not be correct and is definitely not "official".


This script was broken in Matlab 2015a. I guess I will downgrade for now. Using the open source Inkscape is a viable alternative to figures with psfrag editable text.

The error message is:
Undefined function 'abs' for input arguments of type


Kerry Bosche

This is working great, with the exception that dashed lines ('LineStyle','--') are not being preserved. What am I missing?

Kerry Bosche


Very nice function, however, with MATLAB 2014b it seem no longer to work. Any idea why?


Superb function. Perfect for adding symbols to EPS files in Latex. Matlab's defaul EPS generator can't do it properly. This fixes it. 5/5

Johannes Schmitz

On Ubuntu 13.04 I am getting this error:
/usr/bin/gs: /opt/MATLAB/R2013a/bin/glnxa64/ no version information
available (required by /usr/lib/

I copied the from my system folder into the Matlab folder and changed the symolic link ( from to as a workaround.

Thomas Clark

Potentially very useful, as this is an area in which the Mathworks' own solutions are woeful with no signs of improvement. However, with no updates since 2004 I'm not holding my breath for vital fixes to this utility.

For me, the main problems are:
- using texShop on a Mac, and the tags simply aren't being updated so are typeset in the finished document as x01, x02 etc (to be fair this might be a latex issue).
- axes scales (x10^p etc) are placed incorrectly
- legend sizes aren't handled

... and that's before trying anything challenging like having patch objects or 3D plots etc.

Some users may consider googling for psfragx and psfragx.m, which allow overlays of pictures and inclusion of graphics in a more flexible way within latex. Still reliant on Laprint though, so the bugs above won't go away.

Pavle Boskoski

There is a small Bug in the script when using it with 3D plots. The z-axis is not preserved. The solution is:
The lines 1189 to 1191 and 1782 to 1784 should be changed from:
-set(ztickmodeauto,'ytickmode','manual') -set(zticklabelmodeauto,'yticklabelmode','manual')

+set(zlimmodeauto,'zlimmode','manual') +set(ztickmodeauto,'ztickmode','manual')

The only problem was a typo, when setting zticklabel modes the actual property was ylabel.

Great work BTW!


Waseem Tahir

These type of programs seem very nice at first glance, however you come to trouble when it come to real issues. i wasted about 3 hours on laprint, however at end i come to conslusion that title('$\hat{a}$','Interpreter','latex') is the best. you loose flexibility when using laprint.


try this out, very easy and works well !


Would it be possible in a future version to set the width of the picture like this:

laprint(1,nameoffile,'width','.9\linewidth ')

In other words: describe the width not as a number but as a factor of the linewidth?

Emile Demarteau

Great work! This script allowed me to perfectly markup all my figures, so they could be included nicely in my report. @Tor Aksel, I wrote a legend to latex converter to overcome the small box problem.

Emile Demarteau



Extraordinary work. However, I have two problems. The legend box sometimes gets too small, and must be enlarged manually. Also, when the x-axis has ticks as powers of 10, the "x10^n" does not appear in the eps. From inspecting the code, it seems this s only implemented for the y-axis.


I was trying to specify a destination directory with the filename, for example,
laprint(1, './figure/a', 'options', 'factory', 'width', 7.5)

Two files will be generated in directory 'figure', namely, 'a.eps' and 'a.tex'

On the Windows machine, the '\includegraphics{}' (second line from bottom in 'a.tex') will points to the correct path of 'a.eps.'
However, on the Linux and Mac machine, the correct path won't be appended to the argument in '\includegraphics{}.'

Any suggestion?

James Mynderse

Pavle Boskoski

Very valuable script. I can't understand why matworks did't include such script in their package.


Mark Verveld

I solved the ypower-text issue by adding the folowing lines after line 1563:
It ensures that the power text is actually printed to the intended axes of the intended figure.

Very good work though, thanks!

Cun Zhang

Great Work!

Peter B

Sorry for the double post. Here is the last line that should've been in the previous post

??? Error while evaluating uicontrol Callback.

Peter B

I get the following error when I execute laprint and I have no idea what it could be! Can anyone please help?

??? Error: Missing MATLAB operator.

Error in ==> laprint at 1795

Error in ==> laprint at 415

Kevin Mitchell

Beautiful! This is exactly what I need. It works just as advertised. I have yet to find a case where I can't use this package to produce the figure I want.

My only caveat is that as a rule, I generally use 'figcopy','off' to avoid any problems with matlab's object copy function , but I could really care less since I generate any serious figures (i.e., ones that I would actually want to include in a latex document) from scripts anyway.

This package really should be included in the standard Matlab distribution.

knowline knowline

Steve _

y-axis power appears in wrong place when a legend is present (due to the powers tag placed with text() when legend axes is current instead of main axes).

Fixed with the following changes between lines 1560 and 1575 (this may cause unwanted side effects - I've not noticed any yet):

% place text to be replaced by powers on y-axis
+ % Bug fix: when legend is present, powers-string appears on legend axes
+ % instead of main axes; make sure main axes are current when invoking text();
+ % at the end, make legend axes current to make legend visible again
+ ca = gca; % if legend present, this is probably legend axes
for i=1:na
allxyz = { 'x', 'y', 'z' };
ixyz=2; % x,y,z
xyz = allxyz{ixyz};
if powers(i,ixyz) & ~is3d(hax(i)) & isequal(leftright,'left')
+ axes(hax(i)); % make the axes current
powertext = ['ypower' int2str(i)];
xlimit = get(hax(i),'xlim');
ylimit = get(hax(i),'ylim');
@@ -1575,6 +1587,7 @@
end % i
+ axes(ca); % needed to make legend visible again -- any side effect?

ich aus Hannover

In general this is a very useful tool. But the proramm do not place the powers on the y-axis (ypower) correctly. And that is quite laborious to change the files by hand.

Ivo visitor

Actually, I cannot use this on Ubuntu/Matlab 7.5 because the placeholders are not replaced correctly by the generated .tex file. I use texlive and the psfrag package. There are no errors on compilation with LaTeX but the labels are just not located at the correct positions. Also the 'straight line' from the user manual is printed horizontally, whereas it is the y-axis label (just following the example in the manual).
Is this a known problem? I have seen this on more than 1 computer).

Are there any thoughts on this? I would really like to use this tool.

Olivier Lemaire

perfect !!
This is exactly what I need. Thank you so much.

Love LateX...

The Rainman

This is actually cool and helpful!

Jacob Huijssen

I love this function, very happy to discover it at the start of writing my PhD thesis!!

Dai Jessop

Decent function, but one can achieve the same result using
> print -depsc <filename>

Eric Johnson

An impressive and useful piece of work, indeed. After some head scratching, I found that the size of legends gets screwed up in MATLAB 7.4 if the figure is copied before doing the text replacements. To avoid this, use the 'figcopy', 'off' option from the command line or uncheck the "Copy figure and modify that copy" option in the gui. With that option set, the text in your original figure gets changed into the psfrag tags, but the legend size comes out correct.

Rob Stanson

Helpful tool, but I had to make a change in order to be able to use ist with legends in Matlab 7.1:

I replaced line 1563
for i=1:na
for i=na:-1:1

because it placed the ypower-text into the legend's axes, not into the normal axes.

Paul Miller

Excellent program. I would like to be able to specify a default font size for all labels, etc. For example, add \footnotesize to all tick labels.

Javier Barragán

Is it possible to eliminate the warning of line 64 with this?

In the beginning of the function:

At the end or before any "return" or "error":

Thank you!

Mark Morelande

Thank you for writing this excellent function. I have found it to be extremely useful.

Jean-Christophe OLIVIER

Thank you very much for this powerfull function! All well work!

S. Hoffmann

SUPERB TOOL! Only thing I am missing is the turning of axis lables in 3d plots. I also like to modify the distance of tick lables to the axis, because by default laprint sets them a little too far away from the axis (in my opinion). Nevertheless, greatly helpful! Thanks!

sssssssss sas


Jason Venkiteswaran

What about axis labels? I can't find an 'as on screen' option. This is important for converting EPS files to PDF for use with pdftex.

Kyriakos Chourdakis

Excellent! Thanks a lot for that Arno

Gernot Hassenpflug

To add to my previous review. I discovered belatedly that the renderers -zbuffer and -opengl store binary data, only -painters stores vector data and therefore only the latter can be used with LaPrint. This is not a bug, and I apologize for not having noted this in my first review. If one requires -opengl rendering then one will need to overlay plots in LaTeX using I suppose the pstricks and graphicx packages.

Gernot Hassenpflug

I found this utility useful for simple plots, but I discovered that unfortunately it does not appear to work for renderers -opengl and -zbuffers. If one is forced to use -painters, then shading and lighting is lost in 3-D graphics. I could not discover where the problem lies, but since the .tex output appears the same, I surmise it is the .eps file format. I wish I had the ability to fix this, but for the moment I need to look for alternative tools.

sara tamer


Dimas Mavares

Extremely useful

Guillaume Jacquenot

Excellent work. You spare me a lot of time!!

Leopold Pede

I am student and like to learn Matlab

murtaza kemal

a lot of things

popo sskkd

Le Chen

It is very cool and useful!

Jim Hoyes

Specifically, problems seem to arise when using different renderers.
I have problems when using zbuffer or opengl.

Anyone got any advise?

Jim Hoyes

I am having problems using it for 3D plots.
Has anyone else had problems?
Or found any solutions?

Ed Neson

Beautiful piece of work, I wish that it was available for octave.

Lucien de Vaucanson

Very very very useful !

tiago castro


Sebastian Trimpe

Great help! Easy to use function!

Thiago Fontes

ejan ajan

I tried to use it for importing my matlab 7.1.xx figures into latex. I referred to the manual and tried out different preferences, but still result not usable without considerable alterations that would cost too much time. Problem: labels and axes are not appropriately titled.

Benjamin Auffarth

I tried to use it for importing my matlab 7.1.xx figures into latex. I referred to the manual and tried out different preferences, but still result not usable without considerable alterations that would cost too much time. Problem: labels and axes are not appropriately titled.

Joe Dash

pipe espinoza

poienar marius

poienar marius

poienar marius

Patrick Egan

Fantastic file for dissertaions and reports.

It does not appear to work well with legends in Matlab 7.1.

jkh lhl


GOOD & REAL work/job/etc.... u r the one... Thankx...

uuyhruyr rtur

tyh t6y7 t6y7 6t 56y

tyuhtuy trytrt

yuyjhyuuyj tyt t5ytyty

Jeroen Brunnenkreef

This can be used to get rid of the psfrag:

baptiste auguie

Hi, very nice tool indeed!

as I use pdflatex, I've had to change a few lines and use a small trick which might be useful:

first, I change these lines in laprint.m, to uncomment the \documentclass and \begin{document} lines, I add a \thispagestyle{empty} command and I get rid of the \include{file}:

fprintf(fid, ' \\documentclass{article}\\usepackage{');
if color
fprintf(fid, ',psfrag}\n');
fprintf(fid,[ ' \\begin{document}\n\\thispagestyle{empty}\n' ]);
In the end, I had the \end{document} command.
fprintf(fid,[ '\\end{document}\n' ]);

This laprint.m modified file generates both .eps and .tex files, but the latter may now be interpreted by a simple 'latex' command. It generates a .dvi file with all psfrag replacements made, which can be converted in .pdf by eps2pdf command line tool. The following script does all the process for one file:

latex unnamed.tex
dvips -E unnamed
epstool --copy --bbox unnamed.eps
epstopdf unnamed.eps

fe ffe

Alexander Gahr

Verry Good tool. I love it.

But ...
it uses psfrag wich is not aviable for pdflatex
so i must use latex. I hope to find a good way of including matlab figures with pdflatex.

james buck

Nice one!

Axel Junge

Impressive. I am using psfrag with my figures for a long time already, but was making adjustments by hand. For Matlab figures, this gives the automation I always dreamed of.

Jonathan Sievers

Thank you so much! Wish I had known about it years ago.

John Harrold

I really like this program. I've used it for every paper I've submitted, and now I'm using it for my dissertation. It makes figures very professional looking by providing font consistency throughout a document.

Uli Theune

Now, that's a code I wish I had discovered BEFORE writing my thesis! Very good and very useful!

Do Wan Kim

Very Very exellent!

Bülent Yagim

Wie geil ist das denn?

Juha Mäkipelto

Ho Jae Lee

A definite solution to LaTeX figure with MATLAB!!

Rahul Premraj

Brilliant piece of work. Produces crisp graphics for inclusion in publications. Sometimes not very clever with resizing legends.

Jebbe van der Werf

Great stuff!! I can now finish my PhD in a wonderful way.

Daniel Sandberg

This is definately a useful utility for Matlab. I am going to use this all the time for my work!

Troy Henderson

Awesome utility. Make psfrag super easy!

Francisco Beron-Vera

Wonderful program. By far much more flexible than the LaTeX interpreter in Matlab 7+.

Karsten Quint

I used psfrag manually before. Now LaPrint really eases my work!

Ana Santos

Kuldeepsinh Rana

Excellent program and a very well written guide to explain even the newbies! It was very useful in writing my thesis.

Devon Yates

A really well put together program. I have struggled to make my matlab figures look decent with matlab, and Laprint makes them look great.

Daniel Czarkowski

Daniel Czarkowski

Well, I strongly recomend to update from version 2.03 (19.1.2000) to 3.15

Kostas Kakoyiannis

Nice job Arno! Working with figures can be really disappointing for novice LaTeX users, but all that can change now if you're a MATLAB afficionado as well.

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!