How can I ensure graphics exported in WMF format don't have text-spacing problems?



A lot of my work involves manipulating data, drawing a pretty plot of it and then inserting that graphic into a report written in Microsoft Word, under Windows.1 The fun comes with the exporting part. If the audience don't have the Mathematica fonts installed, negative signs, parentheses etc will come up as missing-characters in the WMF graphic and in Word.

You can fix this using the PrivateFontOptions option, either in the notebook or in the Options Inspector.

SetOptions[$FrontEnd, PrivateFontOptions -> {"OperatorSubstitution" -> False}]

But I still find the output a bit disappointing, in that the spacing around parentheses and other characters in the WMF file looks wrong (sorry, I can't show the whole graphic because the data are confidential).

enter image description here

The code to produce the graph above rests partly on a package, so here is a minimal example:

 test = Grid[{{DisplayForm[
  Style["Source: REDACTED (confidential)", 13, 
   FontFamily -> "Arial", Black], 
        BoxMargins -> {{3, 0}, {0, 0}}]]}}]

enter image description here

This is how it looks in Win7 and Office 2010: the first two are with operator substitution ON, the second pair are with operator substitution OFF. There is still a bit too much space but it is better than in Word 2007.

enter image description here

As highlighted, there is just too much space between the text and the closing parenthesis. This is not apparent in the Mathematica notebook, where it looks just fine. It must be something to do with Mathematica's WMF export routine: other applications with WMF export don't do this.

Is there any way of automatically ensuring that the spacing around letters in the resulting WMF file is a bit more acceptable? Some kind of auto-kerning option? Ideally it should be something I can set in a package so my colleagues don't have to know the internals of how to do it.

1Actually I have people to do that now, but you get the idea.


Posted 2012-01-18T02:13:47.467

Reputation: 33 191

Here is a shot in the dark. Please see if it has any effect: SetOptions[$FrontEndSession, ConversionOptions -> {"ExportOptions" -> {"WMF" -> {"IncludeSpecialFonts" -> True}}} ] – Mr.Wizard – 2012-01-22T19:02:05.170

@Mr.Wizard that sounds like it should work, but in a comparison of pairs of WMFs with operator substitution off, or with it on, I cannot tell the difference. There is still a bit of a gap. This is under Word 2010 and 2007. – Verbeia – 2012-01-22T21:54:18.483

Could you please show your complete code (including export) which results in a bad WMF and then convert/screenshot your WMF to PNG/JPG and post it here? I'd be nice if you could also circle in Windows Paint the bad areas of the image. – Vitaliy Kaurov – 2012-01-18T03:58:23.973

@Verbeia these don't appear to be Mathematica fonts causing this problem. i.e. you are using Arial which is a system font isn't it? If you don't have the private font options set what font is used when others open the WMF? What happens if you do not have an adjustment box (there are other methods to indent if this is the problem). Is there always an adjustment box when these font issues arise? The parts of the plot you cannot show that have problems: are these plot or line labels? – Mike Honeychurch – 2012-01-18T06:43:51.877

@MikeHoneychurch they are text areas in cells - e.g. PlotLabel, but I haven't tested line labels yet. Perhaps I should edit the question a bit further - I might not have been clear that the problem is with non-Mathematica fonts like Arial, when "OperatorSubstitutions" is set to False. – Verbeia – 2012-01-18T06:51:31.823

3Your SetOptions construction is wrong. It should be either SetOptions[$FrontEnd, PrivateFontOptions -> Append[DeleteCases[ PrivateFontOptions /. Options[$FrontEnd, PrivateFontOptions], _[ "OperatorSubstitution", _]], "OperatorSubstitution" -> False]] or shorter CurrentValue[$FrontEnd, {PrivateFontOptions, "OperatorSubstitution"}] = False – Sjoerd C. de Vries – 2012-01-18T11:12:20.200

@Sjoerd I think that over complicates it (the first solution anyway). SetOptions[$FrontEnd, PrivateFontOptions -> {"OperatorSubstitution" -> False}] will suffice which you can check using Options[$FrontEnd, PrivateFontOptions]. I am assuming @Verbeia is doing this already and the code in the question was a typo because it generates a syntax "warning" for insufficient arguments. – Mike Honeychurch – 2012-01-18T12:05:49.590

1@Mike Strange, I thought this would overwrite the other options that are also in PrivateFontOptions. Apparently it doesn't. Anyway, $FrontEnd should have been included. – Sjoerd C. de Vries – 2012-01-18T12:13:30.273

1Is WMF the best choice for importing graphics into Word? I never used to like anything but EPS or PDF when I was doing it for a living... (I suspect that this doesn't seem like a helpful comment. If so, sorry .) – cormullion – 2012-01-18T15:40:48.923

@cormullion it's not a stupid question but yes we have thought of that. WMF is the only thing that looks decent in Word on Windows, both on screen and in print. – Verbeia – 2012-01-18T20:06:25.043

@Verbeia I sympathise... :) There are eps-to-wmf converter programs, I believe, which might work around Mathematica-WMF-export errors. But it's not an office-friendly solution. – cormullion – 2012-01-18T20:29:52.647

@SjoerdC.deVries I've fixed that typo, thanks and sorry. – Verbeia – 2012-01-20T23:03:10.663



I can only guess that the following could be a work-around for you (I don't have Windows). Define the following wrapper function for Export:

outlinedExport[name_, gr_, opts : OptionsPattern[]] := 
  First@ImportString[ExportString[gr, "PDF"], "PDF", 
    "TextMode" -> "Outlines"], opts]

On my Mac, I cannot export to WMF so I'll have to trust that it will work the same way it does with SVG which I did try. Assuming your graphics object is g, you would do something like this:

outlinedExport["output.wmf", g, ImageSize -> 600]

There is no need to embed any fonts because they have all been replaced by outlined paths (again, not sure if Mathematica on Windows does this properly). The downside is that the file size increases, but the upside is that you'll never have any font headaches again.


Posted 2012-01-18T02:13:47.467

Reputation: 93 191

Late comment, but this works on Windows too. The final format probably ought to be EMF rather than WMF, though. – Oleksandr R. – 2013-01-14T01:43:58.983


If the missing fonts are the problem, one thing you could do is have your recipients download MMA's fonts from the appropriate support page (windows, unix, macintosh). Installing the CDF-player also installs MMA's fonts.

If this is not feasible a robust option is to export as bitmap. You're guaranteed to have no font problems. Obviously that means it doesn't scale, but I found that quite often you don't need that (like in Powerpoint presentations).

On my computer, copying the text from your example to Word2010 and using paste special / picture (metafile enhanced) doesn't give me this problem. But that may be because the fonts are installed on this PC. I'll try to install a virtual machine with Word to see whether it's the same there.

Mathematica graphics


Powerpoint and Word 2010 have the options to embed fonts: Mathematica graphics

Mathematica graphics.

BTW, I tried your example in a virtual machine Win7-64 installation without a trace of Mathematica or its fonts and it does look normal, i.e. the parenthesis close without the extra space. So, your problem may be caused by a pre 2010 version of Word.

Sjoerd C. de Vries

Posted 2012-01-18T02:13:47.467

Reputation: 63 549

@verbeia Please see update. One problem that I see is that the bounding box of the area copied is apparently one pixel too small. It looks like Word slices off the upper part of the letters. – Sjoerd C. de Vries – 2012-01-22T14:31:53.657

"Install the fonts" would definitely be a part of the answer but (a) I can't rely on the IT staff to get this right and (b) this will fail for PowerPoints shown externally. – Verbeia – 2012-01-20T23:01:11.697

@Verbeia AFAIK PowerPoint is able to embed the font into the document (for portability) – Szabolcs – 2012-01-20T23:09:06.660

@Szabolcs - if you can construct this as an answer with an example it might be the one I will end up accepting - but I will have to test it next week at work. It's the weekend here and my home machine is a Mac. – Verbeia – 2012-01-20T23:13:53.267


I suggest to Magnify the output before exporting it to WMF/EMF or increase the ImageSize because metafiles are sampled at screen resolution fidelity (see examples here). I also advise to use the EMF (Enhanced Metafile Format) format which is much better than the old WMF (Windows Metafile Format) developed originally for Windows 3.11...

Alexey Popkov

Posted 2012-01-18T02:13:47.467

Reputation: 50 220