5

According to the MATLAB manual, when you save a figure using print or by choosing file|save, if you choose the painters renderer and save to PDF or EPS vector formats, all fonts get substituted. Is there a way to get around this limitation?

Whenever I output a figure, whether I use print or export_fig, the fonts get substituted, and so they no longer match the fonts in the document that I plan on putting the figure into. I would prefer to keep them in a vector format, because I use LaTeX and so I want to be able to use the same figures in my documents as in my beamer presentations and have them scale nicely without bloating the file size.

craigim
  • 3,884
  • 1
  • 22
  • 42
  • EPS file is a text script and you can try to change font-name yourself with search-and-replace. I had to do this when had got codepage problems. – Dmitry Galchinsky May 31 '13 at 00:06

2 Answers2

4

If I'm reading that link correctly, not all fonts get substituted. From 'Choosing a Printer Driver':

The table below lists the fonts supported by the MATLAB PostScript and Ghostscript drivers when generated with the Painters renderer (fully vectorized output). This same set of fonts is supported on both Windows and UNIX:

AvantGarde
Helvetica-Narrow
Times-Roman
Bookman
NewCenturySchlbk
ZapfChancery
Courier
Palatino
ZapfDingbats
Helvetica
Symbol

So, if you use one of the above fonts, the output vector-format figure should maintain the correct font. See for example:

list_fonts = listfonts
figure('renderer','painters'),
plot(peaks),
xlabel('this font is Helvetica','fontname','Helvetica','fontsize',24)
set(gcf,'paperpositionmode','auto')
print(gcf,'-depsc2','test1.eps')

Which produces:

example output

So, choose one of the fonts from the list above, and the font will be output correctly. Otherwise, change the font in your presentation to match one of the above fonts.

David_G
  • 1,127
  • 1
  • 16
  • 36
  • 1
    There are two problems with that. First, the figures are for a scientific journal, and I have to follow their font guidelines. Second, I don't have those fonts. If I try to open the resulting PDF in Illustrator, for instance, I get an error saying that Helvetica is not available. Obviously they have to be on my computer somewhere, but I do not know how to make them visible to the rest of my computer. Besides the fact that there are much better fonts out there, especially if I want to include mathematical notations in my figures. – craigim May 30 '13 at 23:52
  • @craigim a jury rigged solution... why don't you export them with courier font (or a font that your computer is guaranteed to have access to), then open the figure in illustrator/inkscape and change the font? Or, export the figure without labels, and add them afterwards in illustrator/inkscape? – David_G May 31 '13 at 00:13
  • That's what I've been doing. I was hoping to figure out a way to skip that step. Ideally, I would be able to have a script that would take my data, do whatever manipulation and analysis needed to be done to it, and spit out a journal-ready figure, so that when I need to make changes, I just have to tweak the script and re-run it without having to start from scratch on the fonts, since the substituted fonts all have different size and spacing than the originals, so I can't just search and replace, but have to realign the labels with the tick-marks and axes. – craigim May 31 '13 at 01:58
  • Out of interest, what font guidelines does the journal specify? – David_G May 31 '13 at 04:26
  • 8
    The presentation templates for my organization use Electra and Avenir fonts, as do the internal report templates. American Physical Society journals use RevTeX which uses Computer Modern. Which is all sort of besides the point, because in 2013 and for the money my organization pays for MATLAB, I should not be limited to the fonts that were hard-coded into postscript printers 20-30 years ago. – craigim May 31 '13 at 15:11
  • @craigim - Totally agree with that statement. A dodgy way of fixing it would be taking the Electra and Avenir fonts, renaming them Helvetica and Courier and replacing the official fonts (don't forget to back them up though!)..... then run your plotting script again and see if it works? – David_G Jun 03 '13 at 05:54
  • 2
    + for providing this list – embert Feb 14 '15 at 18:07
0

I also encountered this problem for many times, and I have an simple but effective way that never fails me (on Windows, need GSview).

1) save fig as PDF

2) save PDF as ps

3) open ps with GSview, then click "File->PS to EPS", specify a file name and done.

Hope this helps.

Bloodmoon
  • 1,308
  • 1
  • 19
  • 34