### Highlights from LaPrint

4.425
4.4 | 87 ratings Rate this file 96 Downloads (last 30 days) File Size: 97.9 KB File ID: #4638 Version: 1.0

# LaPrint

### Arno Linnemann (view profile)

16 Mar 2004 (Updated )

LaPrint prints a MATLAB figure to file for neat inclusion in LaTeX documents.

File Information
Description

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
http://www.uni-kassel.de/fb16/rat/matlab/laprint/laprintdoc.ps

Acknowledgements

This file inspired Plot2eps, Plot Eps Te X, Plot Pdf Tex, Legend To Latex Converter, Matlabfrag, Export Eps Pdf, and Plot2 La Te X.

MATLAB release MATLAB 7 (R14)
01 Feb 2016 Tobias Birnbaum

### Tobias Birnbaum (view profile)

@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.

Comment only
01 Jun 2015 Gerald

### Gerald (view profile)

@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".

31 May 2015 Emil

### Emil (view profile)

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
'matlab.ui.Figure'.

Comment only
31 May 2015 Emil

### Emil (view profile)

25 Feb 2015 Kerry Bosche

### Kerry Bosche (view profile)

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

25 Feb 2015 Kerry Bosche

### Kerry Bosche (view profile)

11 Dec 2014 benjamin

### benjamin (view profile)

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

09 Dec 2014 Emil

### Emil (view profile)

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

29 Oct 2013 Johannes Schmitz

### Johannes Schmitz (view profile)

On Ubuntu 13.04 I am getting this error:
/usr/bin/gs: /opt/MATLAB/R2013a/bin/glnxa64/libtiff.so.5: no version information
available (required by /usr/lib/libgs.so.9)

I copied the libtiff.so.5.1.0 from my system folder into the Matlab folder and changed the symolic link (libtiff.so.5) from libtiff.so.5.0.5 to libtiff.so.5.1.0 as a workaround.

Comment only
08 Oct 2011 Thomas Clark

### Thomas Clark (view profile)

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.

24 Aug 2011 Pavle Boskoski

### Pavle Boskoski (view profile)

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(zlimmodeauto,'ylimmode','manual')
-set(ztickmodeauto,'ytickmode','manual') -set(zticklabelmodeauto,'yticklabelmode','manual')

to:
+set(zlimmodeauto,'zlimmode','manual') +set(ztickmodeauto,'ztickmode','manual')
+set(zticklabelmodeauto,'zticklabelmode','manual')

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

Great work BTW!

11 Aug 2011 sweta

### sweta (view profile)

11 Feb 2011 Waseem Tahir

### Waseem Tahir (view profile)

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.

03 Nov 2010 hassene

### hassene (view profile)

try this out, very easy and works well !
title('$\hat{a}$','Interpreter','latex')

Comment only
19 Mar 2010 Erik

### Erik (view profile)

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?

Comment only
30 Sep 2009 Emile Demarteau

### Emile Demarteau (view profile)

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.

Comment only
30 Sep 2009 Emile Demarteau

### Emile Demarteau (view profile)

16 Sep 2009 Robert

15 Sep 2009 Tor

### Tor (view profile)

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.

13 Jul 2009 Ty

### Ty (view profile)

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?

Comment only
12 Jun 2009 James Mynderse

### James Mynderse (view profile)

05 May 2009 Pavle Boskoski

### Pavle Boskoski (view profile)

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

GREAT WORK

16 Apr 2009 Mark Verveld

### Mark Verveld (view profile)

I solved the ypower-text issue by adding the folowing lines after line 1563:
set(0,'CurrentFigure',figno)
set(figno,'CurrentAxes',hax(i))
It ensures that the power text is actually printed to the intended axes of the intended figure.

Very good work though, thanks!

14 Oct 2008 Cun Zhang

Great Work!

19 Sep 2008 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.

19 Sep 2008 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
eval(cmd);

Error in ==> laprint at 415
eval(lapcmd)

17 Sep 2008 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.

04 Sep 2008 knowline knowline
04 Sep 2008 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};
leftright=get(hax(i),'yaxislocation');
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 @@
set(htext,'VerticalAlignment','Baseline');
end
end % i
+ axes(ca); % needed to make legend visible again -- any side effect?

31 Jul 2008 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.

30 Jul 2008 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.

Comment only
24 Jul 2008 Olivier Lemaire

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

Love LateX...

19 May 2008 The Rainman

This is actually cool and helpful!

15 Apr 2008 Jacob Huijssen

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

31 Jan 2008 Dai Jessop

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

28 Jan 2008 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.

10 Nov 2007 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
by
for i=na:-1:1
axes(hax(i));

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

27 Oct 2007 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.

10 Oct 2007 Javier Barragán

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

In the beginning of the function:
"interpreter=get(0,'defaulttextinterpreter');"

At the end or before any "return" or "error":
"set(0,'defaulttextinterpreter',interpreter)"

Thank you!

24 Sep 2007 Mark Morelande

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

17 Sep 2007 Jean-Christophe OLIVIER

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

13 Jul 2007 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!

01 Jul 2007 sssssssss sas

sssssssssssssssssss

27 Jun 2007 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.

Comment only
18 Jun 2007 Kyriakos Chourdakis

Excellent! Thanks a lot for that Arno

Comment only
12 Jun 2007 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.

08 Jun 2007 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.

11 May 2007 sara tamer
10 May 2007 D T
04 May 2007 Dimas Mavares

Extremely useful

13 Apr 2007 Guillaume Jacquenot

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

07 Mar 2007 Leopold Pede

I am student and like to learn Matlab

Comment only
04 Feb 2007 murtaza kemal

a lot of things

04 Jan 2007 popo sskkd
23 Nov 2006 Le Chen

Thanks
It is very cool and useful!

07 Nov 2006 Jim Hoyes

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

07 Nov 2006 Jim Hoyes

I am having problems using it for 3D plots.
Or found any solutions?
Thanks.

31 Oct 2006 Ed Neson

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

26 Oct 2006 Lucien de Vaucanson

Very very very useful !

07 Oct 2006 tiago castro

good

23 Sep 2006 Sebastian Trimpe

Great help! Easy to use function!

21 Aug 2006 Thiago Fontes
07 Aug 2006 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.

Comment only
04 Aug 2006 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.

11 Jul 2006 Joe Dash
10 May 2006 pipe espinoza
09 May 2006 poienar marius
09 May 2006 poienar marius
09 May 2006 poienar marius
08 May 2006 Patrick Egan

Fantastic file for dissertaions and reports.

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

10 Apr 2006 jkh lhl
26 Mar 2006 Mustafa YILDIRIM

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

03 Mar 2006 uuyhruyr rtur

tyh t6y7 t6y7 6t 56y

03 Mar 2006 tyuhtuy trytrt

yuyjhyuuyj tyt t5ytyty

08 Feb 2006 Jeroen Brunnenkreef

This can be used to get rid of the psfrag:

http://www.gts.tsc.uvigo.es/~fiz/unpsfrag

28 Jan 2006 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{');
fprintf(fid,package);
if color
fprintf(fid,',color');
end
fprintf(fid, ',psfrag}\n');
fprintf(fid,[ ' \\begin{document}\n\\thispagestyle{empty}\n' ]);
[...]
In the end, I had the \end{document} command.
[...]
fprintf(fid,'\\end{psfrags}%%\n');
fprintf(fid,'%%\n');
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:

%--------script EpsPdf.sh-----------
latex unnamed.tex
dvips -E unnamed
epstool --copy --bbox unnamed.ps unnamed.eps
epstopdf unnamed.eps
%-----------------------------------

18 Jan 2006 fe ffe
20 Nov 2005 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.

08 Nov 2005 james buck

Nice one!

27 Oct 2005 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.

25 Aug 2005 Jonathan Sievers

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

06 Jul 2005 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.

17 Jun 2005 Uli Theune

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

22 May 2005 Do Wan Kim

Very Very exellent!

21 May 2005 Bülent Yagim

Wie geil ist das denn?

29 Apr 2005 Juha Mäkipelto
16 Mar 2005 Ho Jae Lee

A definite solution to LaTeX figure with MATLAB!!

28 Feb 2005 Rahul Premraj

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

03 Dec 2004 Jebbe van der Werf

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

10 Nov 2004 Daniel Sandberg

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

08 Nov 2004 Troy Henderson

Awesome utility. Make psfrag super easy!

21 Oct 2004 Francisco Beron-Vera

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

19 Sep 2004 Karsten Quint

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

18 Aug 2004 Ana Santos
29 Jul 2004 Kuldeepsinh Rana

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

03 Jul 2004 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.

21 Jun 2004 Daniel Czarkowski
12 May 2004 Daniel Czarkowski

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

26 Mar 2004 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.