Code covered by the BSD License  

Highlights from
plot2eps

4.0

4.0 | 4 ratings Rate this file 14 Downloads (last 30 days) File Size: 31.6 KB File ID: #23698

plot2eps

by

 

14 Apr 2009 (Updated )

Function to streamline the workflow of converting plots to eps files for inclusion in LaTeX.

| Watch this File

File Information
Description

Requires plotepstex.m and laprint.m (included)

PLOT2EPS() If all input arguments are omitted, the function will run in user input mode prompting the user for the appropriate inputs.

PLOT2EPS(FIGNAME) Converts all figures in the FIGNAME.FIG file. Other arguments are set to defaults. eps2pdf.bat is generated to convert the eps files to pdf if the user wishes.

PLOT2EPS(FIGHANDLE) Converts all figures in the FIGHANDLE vector. Other arguments are set to defaults. eps2pdf.bat is generated to convert the eps files to pdf if the user wishes.

PLOT2EPS(FIG,'Option',value,...) Specifies one or more of the following options:
'filename': Specify a cell row vector with filenames for the eps figures. The cell vector should have the same number of cells as there are figures to be converted. If not specified, plot2eps will attempt to derive filenames from the figure titles. When more than one subplot is present, the title of the last subplot is used.
'ratio': Specify the figure width/height ratio as a scalar if all are the same or as a vector to set different values for each figure.
'deletetitle': Boolean value to be able to delete the title from figures. This may be desirable in a LaTeX document where captions are used to describe the figures.
'dir': Specify a full path to the location where the eps files should be saved. Leave blank for saving in the current directory.

This archive includes versions of plotepstex and laprint in which certain issues are fixed (it seems that there are bugs related to compatibility with newer versions of matlab) and features added. I have modified these files to suit my needs and I publish them only as is. Use what changes you like.

Acknowledgements

La Print and Plot Eps Te X inspired this file.

MATLAB release MATLAB 7.6 (R2008a)
Other requirements laprint, plotepstex, latex
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
22 Mar 2010 Dylan

I haven't tested this extensively, but I've come across the following bugs/issues:

The batch file doesn't work with file names that contain spaces.

To fix this, add double quotes around the eps filename on line 272 so that it reads:

fprintf(fid, 'epstopdf.exe "%s.eps"\n', filename{1,index});

Also, I found legend2latex to do a better job of converting the legends than plot2eps. See my comment in the File Exchange page for legend2latex for info on how to get it to work with plot2eps (and plotepstex).

Finally, at line 192 I added

fprintf(fid,'\\usepackage{siunitx}\n');

since I often want to include units in my axis labels and siunitx is my preferred package for rendering units with LaTeX.

Already, I can envision wanting other packages or new commands available for use in the axis labels or legends in order to maintain continuity with the rest of my document. I suppose this is why Arno chose to provide the .tex and .eps files separately in his original LaPrint.m, since LaTeX will interpret everything correctly only if you include the figure.tex file in your document.tex file.

For example, I have defined a new command called \conc:

\newcommand{\conc}[1]{[#1]}

If I want to write \conc{K} in the xlabel of my matlab plot and have LaTeX properly interpret it, then I have to either add that \newcommand call into the plotepstex (or laprint) code so that it is present in every new .tex file that plotepstex (or laprint) makes, or I have to use the \include function in my main latex file and I don't end up with an eps file of the figure in which the properly interpreted labels have replaced the psfrags.

After thinking about it for a minute I haven't come up with a nice clean solution for getting this final eps without having to manually add necessary commands or packages to .tex file that laprint normally generates. Anyone have any ideas?

20 Nov 2009 Peter Jakobsen  
18 Nov 2009 Peter Jakobsen

Fine work!

However, how am I supposed execute eps2pdf.bat? I suspect it might work on a Windows OS, but it doesn't work on Linux/Unix!!!

03 Nov 2009 M'Hamed-Ali

Very nice work thanks a lot. It saves a lot of work !!
However, I have some troubles using the @...@ text.
Could you put a simple example to illustrate the method.
On my side I have the following line:
$x_{\text{ter}}$ @xter@
At the end, the legendbox is still too large. I do not understand where is my mistake. For information, I use the MATLAB Version 7.8.0.347 (R2009a).
Thanks in advance.

22 May 2009 Jushi Hakinen

Nice work, thanks.
Now I can call one function in my script file to process all the plots and have them saved in the folder where my latex document is.
If something is changed in my results, I only have to run the script and compile my latex and voila I'm done.
Really saves a lot of work!

I did get an error when trying the @...@ text, but it was without having a $...$ mathcode in the string, so you can only use them together.

Updates
14 Apr 2009

Corrected a bug when no path was specified.

Added fontsize and figure width options. Although figure width can easily be changed in latex, I have found that some figures need some more room to allow all the labels to print correctly.

16 Apr 2009

legend box width in plotepstex, added lines to set CurrentFigure and CurrentAxes in the powertext code, figuresize in plotepstex, figcopy off, full path support in plotepstex

20 May 2009

open source BSD license

Contact us