File Exchange

## plot2eps

version 1.3.0.0 (31.6 KB) by Mark Verveld

### Mark Verveld (view profile)

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

Updated 20 May 2009

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.

Philip Main

### Philip Main (view profile)

Does not appear to work with new versions of matlab!

Dylan

### Dylan (view profile)

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?

Peter Jakobsen

Peter Jakobsen

### Peter Jakobsen (view profile)

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!!!

M'Hamed-Ali

### M'Hamed-Ali (view profile)

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

Jushi Hakinen

### Jushi Hakinen (view profile)

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.