22
$\begingroup$

I have updated my OS to macOS 10.14 Mojave. I found whenever I export a plot into a PDF file, the font of the label and ticks are automatically replaced into a bold font. I use Mathematica 11.3.

Any idea to fix it?

In the notebook, the figure looks like

enter image description here

In the exported PDF file, it becomes

enter image description here

$\endgroup$
  • 2
    $\begingroup$ This started happening to me only after upgrading to macOS 10.14. On my Mac that still runs 10.13.6 (with the same version of M) I do not experience this, with identical graphics. I'd report this to Wolfram, it looks like Mojave caused a regression. $\endgroup$ – user6014 Oct 3 '18 at 22:31
  • 2
    $\begingroup$ Just to confirm, I have the same problem. Using Mma 11.3.0.0 and Mac OS 10.14. $\endgroup$ – abwatson Oct 15 '18 at 21:37
  • $\begingroup$ Also see a discussion here mathematica.stackexchange.com/questions/183488/… $\endgroup$ – honeyclover Oct 22 '18 at 23:49
  • $\begingroup$ I also have this same problem. Under Mac OSX High Sierra there was no problem $\endgroup$ – hippo3773 Oct 25 '18 at 17:07
  • $\begingroup$ I have the same problem, after mojave update I can't export my plots properly anymore. Please report the bug here: wolfram.com/support/contact/email/?topic=Feedback $\endgroup$ – Fraccalo Nov 19 '18 at 11:41
7
$\begingroup$

Too long for a comment: I wrote MMA support and they got back to me with this answer:

It does appear as though there is an incompatibility between Mathematica 11.3 and macOS Mojave in regards to exporting PDFs. I was able to reproduce the issue in this environment, but not with earlier versions of macOS.

I have found one potential workaround, which instead of Exporting the graphics as a PDF, might be to save the graphic as a PDF from the Print dialog. To do so:

1) Create your graphic in the notebook

2) Select the graphic, go to File -> Print Selection, and from the lower left of the dialog, select "Save as PDF"

3) Use the Save dialog to save the created PDF somewhere on your computer.

This seems to prevent the extra bold fonts from my tests.

We are working to address this issue in our next release.

$\endgroup$
  • 1
    $\begingroup$ How does one manipulate this command so that it prints exactly in size of the graphics selected? I'm getting the right fonts, but cut pdf's using this method. $\endgroup$ – Ranza Nov 22 '18 at 14:01
  • 1
    $\begingroup$ This works. Spent at least 10 hours changing settings trying to fix this. I thought I accidentally changed something and that was causing the issue. Messed up all my student lectures. I should have checked here first. Ugh. It would be nice to get an email from wolfram and a date for the fix when stuff like this happens. : (. It makes me think twice about depending on wolfram at work. $\endgroup$ – Michael McCain Dec 17 '18 at 14:15
  • 2
    $\begingroup$ That's true, I had to convert all my notebooks for my articles figure generation to script, so that I could run them remotely on my lab linux machine which is not affected by this bug. But clearly it's not convenient... Sometimes I don't get (probably because I don't know much about it) how wolfram can so amazing introducing amazing features but so slow in fixing well-known bugs (say for example the error in the position of any plot marker that is not the standard circle, which has been there since I can remember...) $\endgroup$ – Fraccalo Dec 21 '18 at 9:34
5
$\begingroup$

Here's a way to use the OS-level Print > Save As PDF mechanism to get proper PDFs out, the only issue is that it's a truly horrible hack:

getPrintNotebookExpr[expr_] :=
  Switch[
   Head@expr,
   Notebook,
   expr,
   Cell,
   getPrintNotebookExpr@Notebook[{expr}],
   BoxData,
   getPrintNotebookExpr@Cell[expr, "Output"],
   TextData,
   getPrintNotebookExpr[Cell[expr, "Text"]],
   _,
   getPrintNotebookExpr[BoxData@ToBoxes@expr]
   ];
getExprDims[expr_] :=
  Rasterize[expr, "RasterSize"];
Options[printPDFExport] =
  {
   "MediaBoxPadding" -> 3,
   "ScratchFile" -> "~/Desktop/fig.pdf",
   "BasePageSize" -> {612, 792},
   "PrinterPointScaling" -> .72
   };
printPDFExport[
  pdf_String?(StringEndsQ[#, ".pdf"] &), 
  expr_,
  ops : OptionsPattern[]
  ] :=
 Module[
  {
   nb = StringReplace[pdf, ".pdf" -> ".nb"],
   nbex,
   dims,
   exists,
   nbobj,
   targetFile = OptionValue["ScratchFile"],
   openR,
   str,
   openW,
   pdfMarginL,
   pdfMarginB,
   mag = OptionValue["PrinterPointScaling"],
   pageSize,
   initSize = OptionValue["BasePageSize"],
   pageDiff,
   boxPad = OptionValue["MediaBoxPadding"]
   },
  nbex = getPrintNotebookExpr[expr];
  dims = getExprDims[expr];
  exists = FileExistsQ@nb;
  pageSize = mag*dims;
  pageDiff = initSize - pageSize;
  {pdfMarginL, pdfMarginB} = Floor[pageDiff/2];
  nbobj =
   CreateDocument[nbex, 
    {
     Visible -> False,
     WindowSize -> dims,
     PrintingOptions -> {
       "FirstPageFooter" -> False,
       "FirstPageHeader" -> False,
       "RestPagesFooter" -> False,
       "RestPagesHeader" -> False,
       "PageSize" -> pageSize,
       "PaperSize" -> pageSize/mag,
       "PrintingMargins" -> {{0, 0}, {0, 0}}(*Floor[{{pdfMarginL, 
       0}, {pdfMarginB, 0}}*.72]*)
       },
     WindowElements -> None,
     NotebookFileName -> nb,
     StyleDefinitions ->
      Notebook[{
        Cell[StyleData[StyleDefinitions -> "Default.nb"]],
        Cell[
         StyleData[All], 
         CellMargins -> {{0, 0}, {0, 0}},
         ShowCellBracket -> False
         ]
        }],
     WindowTitle -> FileBaseName[pdf]
     }
    ];
  NotebookPrint[nbobj, Interactive -> True];
  NotebookClose[nbobj];
  If[! exists, Quiet@DeleteFile[nb]];
  If[FileExistsQ@targetFile,
   RenameFile[targetFile, pdf, OverwriteTarget -> True];
   openR = OpenRead[pdf, BinaryFormat -> True];
   str = ReadString[pdf];
   Close[openR];
   openW = OpenWrite[pdf, BinaryFormat -> True];
   WriteString[pdf, 
    StringReplace[str, 
     Shortest["/MediaBox " ~~ "[" ~~ __ ~~ "]"] :> 
      "/MediaBox [ " <>
       StringRiffle[
        Join[
         {pdfMarginL, pdfMarginB} - boxPad,
         {pdfMarginL, pdfMarginB} + pageSize + boxPad
         ]
        ] <> " ]"]
    ];
   Close[openW];
   pdf,
   $Failed
   ]
  ]

You must save the file from Save as PDF to the path specified in the "ScratchFile" option, which has a horribly botched page size by default no matter what I try. So then I literally edit the PDF text so the "MediaBox" setting is the right size.

As I say, it's a terrible hack, but until WRI pushes a paclet to fix this we're stuck.

On the plus side, this does work, so I don't need to find a way to revert my OS upgrade to get working PDFs again.

$\endgroup$
3
$\begingroup$

What solved the problem for me was deactivating the bold font weight:

Close Mathematica -> go to Applications -> Font Book -> deactivate the Bold font weight by selecting "Disable ..." from the options for "Bold" in the dropdown menu (see screenshot attached below).

After exporting your figures, you can just reactivate the font weight.

Example

$\endgroup$
  • 1
    $\begingroup$ This worked for me; however, in Mojave Font Book does not allow disabling system- or application-installed fonts. I had to resort to the technique described here: apple.stackexchange.com/a/338056/86933 $\endgroup$ – Simon Rochester Feb 18 at 7:15
0
$\begingroup$

Not sure if this issue is solved now in v12, but after struggling with using few suggestions here, I found that exporting EPS and than converting to PDF using e.g. epstopdf, works ok for me.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.