Your Ad Here

How to Use LaPrint to Create LaTeX Labels in MATLAB Figures

In a previous post I described how to customize and improve MATLAB figures for publication. That guide showed how to create a high quality eps figure that is easily integrated into a LaTeX document or sent off to a publisher. Today I will show how to use LaPrint, a MATLAB function that allows all figure titles, axis labels, labels, and other text to conform to LaTeX typesetting standards, including math mode. LaPrint was created by Ando Linnemann and is available for download here. Note that LaPrint only works with MATLAB 6.1 or above.

For this post I am going to assume that you have used my previous MATLAB figure guide to produce a figure that looks like this:
Figure1ChangeTicks

When you have download LaPrint make sure to save it in the same folder with your other figure-making files. Now I will add labels to my figure, and with LaPrint I will be able to make the text have any number of properties including being bold, italics, or even showing an equation. I will still use the typical MATLAB axis labeling commands, but I will use LaTeX-style commands:

xlabel( ‘\textbf{Time} \it{(Days)}’ );
ylabel( ‘Population in Millions $\phi$’ );

Notice that I want the word ‘Time’ to appear in bold font, and the word ‘Days’ to be in italics. I have also designated the math symbol phi to denote the population. Zooming in on the newly labeled x-axis of the figure we see this:
LatexXAxisLabel

Yes, this is the actual label that is printed on the MATLAB figure, and it doesn’t look pretty at all! This is when the LaPrint comes into play. Add an extra line of MATLAB code to your mfile to call LaPrint:

laprint( 1, ‘Figure1′ ); % Function call is laprint(fig. num. , filename)

This code creates two new files: 1) an eps file of a modified MATLAB figure (Figure1.eps) having tags wherever there should be and 2) a tex file (Figure1.tex) that interprets those tags from the modified eps figure. You really don’t need to worry about these two documents and what they look like so I won’t go into more detail about them here.

To integrate your MATLAB figure (with nice looking text features) into your LaTeX document first make sure that you have included the psfrag package in your preamble. Then add this line of code into your LaTeX file

\input{ Figure1.tex }

Now when you compile your LaTeX document your final product will include Figure 1 with all text and annotations printed in the LaTeX style:

LatexFinalFigure

Notice that the bold and italics font styles that I incorporated into my axis label commands in MATLAB have now been integrated into my figure. Even the Tick Labels {1, 2, etc.} are consistent with numbers typeset in LaTeX.

Important Note: In this post I have just scratched the surface as to the power of LaPrint. Read the documentation to discover more options. It is also important to realize that if you use LaPrint to alter the fonts and add equations in your figures, then you will not have an eps file of your figure.


Trackbacks

close Reblog this comment
blog comments powered by Disqus

© Copyright Zaphu 2007. All rights reserved. -- Valid XHTML

Sitemap XML Sitemap XHTML