4
$\begingroup$

I am using Mathematica 13.2 on Ubuntu. I was trying to reproduce a plot that I made using Mathematica 12, but text symbols seem to not export correctly to PDF. This issue seems to apply to all non-letter/numerical symbols (e.g. parentheses, pound-signs, etc.)

I have boiled my problem down to a minimal-ish working example. Consider this simple plot of $\sin (x)$.

Plot[Sin[x], {x, -3, 3}
  , ImageSize -> Large
  , TicksStyle -> Directive[FontSize -> 25]
  , LabelStyle -> {Directive[FontSize -> 40, FontColor -> Black], 
    Directive[FontSize -> 40]}
  , AxesLabel -> {"x", 
    "\!\(\*SubscriptBox[\(\[Psi]\), \(\[Pi]\)]\)(x)"}
  , PlotRangePadding -> {0.2, 0.2}
  , PlotStyle -> {{Red, AbsoluteThickness[t1*1.5]}}
  , PlotLegends -> 
   LineLegend[{Directive[Red, AbsoluteThickness[t2]]}, 
    Style[#, 35, 
       FontFamily -> "Latin Modern Math"] & /@ {"Test (blep)"}, 
    LegendMarkerSize -> l]
  ] /. {t1 -> 3, t2 -> 6, l -> 40}

The plot that is generated in the Mathematica notebook is perfectly correct.

enter image description here

I then export this plot to PDF using the following command:

Export["/home/myComputer/test.pdf", %, "PDF"]

The plot in the generated PDF file does not have correct axes & legend labels. All symbols appear to be screwed up.

enter image description here

Any idea how to correct this?


Edit:

I have noticed that the error does not exist with other non-vector graphic types. For example, if I export to jpeg, gif, or png, the symbols show up correctly.

$\endgroup$
6
  • $\begingroup$ There were some problems reported here before with pdf exporting on Linux with some fonts not showing correctly. Your example works fine on windows 10. Linux always had problem with fonts. $\endgroup$
    – Nasser
    Commented Mar 2, 2023 at 19:59
  • $\begingroup$ @Nasser Oh wow that's interesting. I have actually tried changing to various different fonts in my plot and the problem persists. It seems to not be related to the specific font on my computer. $\endgroup$ Commented Mar 2, 2023 at 20:05
  • $\begingroup$ Well, if you google linux font problem you'll see. Here is one example. Linux after 30 years still can't figure how to handle fonts right, for some reason. I do not think it is Mathematica's problem, but ofcourse I can't be sure. btw, I use Linux more than windows myself, but I only use the terminal/bash (via Vbox) and all my main GUI apps I use are on windows. $\endgroup$
    – Nasser
    Commented Mar 2, 2023 at 20:10
  • $\begingroup$ Maybe try PrivateFontOptions e.g. SE post $\endgroup$ Commented Mar 2, 2023 at 20:19
  • $\begingroup$ @Nasser I never had this issue with previous versions of Mathematica though. I have only ever used Mathematica on my current computer, which has always ran on Ubuntu. $\endgroup$ Commented Mar 2, 2023 at 21:58

2 Answers 2

1
$\begingroup$

Don't know if this is any help: I just had a knock-down-drag-out-fight with Mathematica on this kind of problem in Fedora 37. Every time I saved a notebook as PDF or used the Print preview feature, half the text would come out garbled. I went through some of my old notes, and discovered that when I had this problem before, I was able to solve it by uninstalling the Adobe SourceCode fonts. Mathematica has its own version of those fonts that is somehow different from whatever the Fedora folks package up. Your problem seems to be related to the Latin Modern fonts which I believe are part of TeX. I suspect that TeX fonts are encoded some way that Mathematica is not expecting, so maybe try changing the font on your plot to something like Times New Roman?

$\endgroup$
4
  • $\begingroup$ Thanks Garrett, I have tried a zillion different fonts (including Times New Roman) and the problem persists. $\endgroup$ Commented Mar 20, 2023 at 22:42
  • 1
    $\begingroup$ Hmm. I experimented with your example just now on Fedora 37, Mathematica 13.1, and the exported file was produced correctly, no garbled symbols. I tried it with both the "default" and "journal article" style sheets and both worked. I've uninstalled the Adobe Source Code fonts, which were definitely resulting in garbled exported PDFs, and then restarted Mathematica. $\endgroup$ Commented Mar 21, 2023 at 14:09
  • $\begingroup$ How did you uninstall this? (I'm using Ubuntu 20.04 and never actively installed such a thing but perhaps it came with it? I have no idea how I would find it and uninstall it.) $\endgroup$
    – Kvothe
    Commented Apr 20, 2023 at 13:06
  • $\begingroup$ On Fedora, there's an RPM package for the Adobe SourceCode fonts, and you use dnf or Gnome Software to remove it.I haven't found an Ubuntu package for them. It seems that you have to install them manually on Ubuntu. If you didn't do that, they may not even be installed on your machine, which would indicate that your problem has a different source than mine. Look in ~/.fonts/ and /usr/share/fonts and see if there are files named something like SourceCodePro-xxx.otf. You can try moving them out of the way, and see if Mathematica produces correct exported graphics. $\endgroup$ Commented Apr 21, 2023 at 18:35
1
$\begingroup$

I fixed this problem by installing the font Source Code Pro. I make the download by https://fonts.google.com/specimen/Source+Code+Pro and use the font-manager for installation.

$\endgroup$
1
  • $\begingroup$ I upvoted this a few hours ago, because I thought it provided a solution for me - but it did not: The only real solution was to revert from MMA 13.3 to MMA13.2.1 on my Ubuntu 18.04 as 13.2.1 is the latest version of MMA that is officially supported on Ubuntu 18.04. After I did this, all pdf related problems vanished $\endgroup$ Commented May 7 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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