When you export a figure to .eps in MATLAB, it will only use a small number of allowed fonts, even if the user has changed these fonts to something specific to their system. In most cases, you'll end up with 'Helvetica' specified in the resulting eps file. That is, if you import this file into Illustrator and have no font exactly called 'Helvetica' then you will end up substituting something else for it, often times doing bizarre things to your kerning, etc. like moving your subscripts to Siberia.
This script writes the .eps as usual, but figures out what font you actually used in the figure and does a find and replace to place your font (presumably actually resident on your system) back into the file. Currently this does not discriminate between the axis font and other text fonts in the figure (i.e., the title and added text), so everything gets changed to the axis font.
This is just a workaround until Mathworks decides their .eps exporting is problematic.
Run into two bugs:
- font names with a space (Minion Pro) do not convert properly, and the eps cannot be opened with Illustrator.
- Title of plot is not centered anymore after replacing of fonts, can this be fixed?
Any way good Job, and Matlab should fix this long-time issue
Works well. I would repeat the comment of Nick Gravish below, with regards to exact font name. I wanted all text in my exported EPS to be Arial, and I had to make actualfont = 'ArialMT'; for this to work. Setting actualfont = 'Arial' made the EPS have courier fonts.
Another comment, printeps can be called on an EPS figure made by export_fig, which for me is the perfect way to create vector figures from MATLAB.
Top job Jose!
Very nice an easy to use.
I found one weird bug that is not important I guess. The text field of the y-label is sometimes split into two text fields. Here the example code:
ylabel('amplitude [µV]', 'FontSize', 11);
xlabel('test label [µV]');
set(0, 'DefaultAxesFontName', 'Arial');
if you change the ylabel to the following everything is ok:
ylabel('amplitude [µV] ', 'FontSize', 11);
using Matlab 2012b on Windows 7.
Thanks for the tool!
I have the problem that when I look at the eps version of a plot produced with printeps, the text in the title and in the legend get cut off. Does anyone have a good idea of how to fix that? Thanks!
Thanks Jose for saving me some time finding out what Matlab should make clear in documentation. (Wish I'd spotted your contribution a couple of days ago!). The fonts actually supported in PRINT or SAVEAS in espc2 formats is apparently version- and platform-dependent.
On MATLAB Mac OS X Version: 10.6.7 Build: 10J869, the only fonts I could find that wound up in eps files were these: 'Courier' 'Helvetica' 'Palatino' 'Symbol' 'Times' 'Times New Roman' 'Zapf Dingbats'
Both Times New Roman and Times showed up as 'Times-Roman' in the eps file, but at least they weren't changed to 'Helvetica'.
I work with eps figures in adobe illustrator and it has been a continual pain reconfiguring the fonts from matlab exported eps files. Thanks for the function.
One comment for illustrator users. Adobe illustrator (at least on my system) uses the times new roman font TimesNewRomanPSMT, so embedding the actual font name "Times New Roman" returned from get(gca,'FontName') still gives an error in illustrator. My workaround was to hard code actualfont = 'TimesNewRomanPSMT' since I always work with times. Just a heads up for anyone in a similar position.
Thank you, I assumed this is how MATLAB should have worked, and I was confused why I was having problems.... Works great with this.
works like a charm
Simple, but it works. Thanks for solving this annoying problem.
I have exeprienced continuous problems to introduce matlab .eps files in latex ducments! You provided a simple solution, and exactly what I was looking for! Thank you very much.
Thank you,this has been driving me nuts. Why cant They sort real issues like this out.
Thanks. It solves the problem!
I haven't checked it thoroughly, but it solved my problem - thanks!