3

I use export_fig (link) to export my figures to PDF. Ghostscript is needed for this: I have v9.15 installed. All my PDFs result in having the Courier font for any text, e.g. axes labels, titles and legends. This happens regardless of any font I specify for the labels.

A similar question exists (link) with an answer (link) that is based on a MATLAB documentation page that has changed since then. The answer lists a few fonts that should be compatible with the painters renderer, which is used when producing PDF files. Among them: Helvetica, which is the default font for text in MATLAB figures, so I would expect the exporting would not change the font at all. However, the font changes to Courier, no matter what font I use from the supposedly compatible fonts list.

An example that produces a PDF with Courier for me (you need export_fig in your path and Ghostscript installed on your system).

figure
plot(peaks)
title title
xlabel xlabel
ylabel ylabel
legend legend
export_fig test.pdf

Does this produce a PDF with Courier for you too? What could be causing this behaviour on my machine?

Community
  • 1
  • 1
Erik
  • 4,305
  • 3
  • 36
  • 54
  • Interesting. However in the code you show you are not specificity any font. – Ander Biguri Mar 25 '15 at 14:16
  • @AnderBiguri - That is because even then the default font is substituted with Courier. – Erik Mar 25 '15 at 14:18
  • I guessed, but have you tried forcing by code to get another font? Maybe the font type is passed to GhostScript as "default" and courier is default to GhostScript – Ander Biguri Mar 25 '15 at 14:19
  • 1
    How would I force that? Do you mean using (e.g.) `ylabel ylabel fontname helvetica`? If I do that, it doesn't help... Or do you mean using some Ghostscript commands (which I don't know)? – Erik Mar 25 '15 at 14:23
  • Yes I mean that. Try other than Helvetica (as it is the default). Do something like: `xlabel('youstring','FontName','Cambria')` and see what happens. – Ander Biguri Mar 25 '15 at 14:25
  • 1
    Nope, Cambria doesn't help, but it is not on the list I mention in my question. But other fonts that are on the list give me Courier too. – Erik Mar 25 '15 at 14:28
  • 1
    Weird. I dont know how to help. Good luck. – Ander Biguri Mar 25 '15 at 14:29
  • What version of Ghostscript do you have installed ? If Ghostscript is a requirement, then at some point it seems likely that PostScript is being generated and fed to Ghostscript, you need to capture that PostScript and the command line being sent to Ghostscript. Armed with that I may be able to shed more light on the problem. You'll probably have to talk to someone that knows about export-fig to find out how to get that information though. – KenS Mar 25 '15 at 15:00
  • @KenS - See the second sentence of my question! – Erik Mar 25 '15 at 15:02
  • OK I missed that, but I would still need the PostScript file and ideally the Ghostscript command line being used. My guess is similar to AnderBiguri, you simply haven't specified a font for the label, the default font in PostScript is Courier. I would not use 'Cambria' for the font name though, try Helvetica or Times, Cambria isn't part of the standard Ghostscript distribution, you would have to add it to Ghostscript's font list, unless export-fig is embedding the font, but it seems likely that it is not. – KenS Mar 25 '15 at 15:04
  • Tried that, but doesn't help, unfortunately. I'm suspecting something else is wrong, maybe Matlab can't find and set those fonts? I found that when I use Times, the font is exported to the PDF correctly. – Erik Mar 25 '15 at 15:06
  • So Times works ? I'd suggest that Matlab/export-fig does not need to find the fonts, because it does not send them, it relies on Ghostscript being able to find the font using the font name. Ghostscript is (normally but it depends on the package on Linux) supplied with the standard 'base 14' fonts, which includes the fonts listed in your link. So if that's the case, any of those fonts 'should' work. But I'd really need to see the input (probably PostScript) being sent to Ghostscript, I'm stabbing in the dark here. – KenS Mar 25 '15 at 15:09
  • Ok, this is strange: I believe it is not a problem with Ghostscript, but with MATLAB. When I open the plot tools (last button in toolbar of a figure), I can manually edit the figure. If I then select a text, e.g. title, I can select the font from a drop-down menu. This menu lists all fonts on my system, but the fonts listed [here](http://stackoverflow.com/a/16847610/3169029) as well! Some of those fonts are *not* installed on my system, e.g. Avant Garde. When I select such a font, the text is displayed in a general (the default?) font. Times is installed on my system, so maybe that solves it. – Erik Mar 25 '15 at 15:25
  • However, why does Helvetica not work? I have Helvetica on my system and I know what it looks like, so I can be certain a text in a figure is typeset in Helvetica. Exporting with Helvetica does produce Courier PDFs, however... – Erik Mar 25 '15 at 15:27
  • I don't know the answer to that, I'd have to see the input PostScript to Ghostscript and probably know the command line and possibly even some details of the way that Ghostscript is set up on your system. – KenS Mar 25 '15 at 15:53
  • see also http://stackoverflow.com/questions/29402479/how-to-prevent-matlab-printing-false-space-and-use-wrong-fonts – Jonas Stein May 03 '16 at 17:50

0 Answers0