# Gray background in export pdf

I am trying to output a simple plot with a legend and the output keeps coming out with a gray background. A simple example is the following:

Plot[{Sin[x], Cos[x]}, {x, 0, 2*3.14}, PlotStyle -> {Red, Blue},
PlotLegends -> SwatchLegend[{Red, Blue}, {"sin(x)", "cos(x)"}]]
Export["trig.pdf", %]


which outputs (notice the gray background!),

$\hspace{1cm}$

I have tried setting "Background->White" in different places, but only managed to have certain regions to get a white background. How can I get an export the image with a white background (and keeping it in pdf format)?

I am using Mathematica V9 on Linux.

Edit:

1. I just upgraded to V10 with hopes that it would fix the issue and the problem still persists.
2. pdf and eps both show the gray background while image formats such as jpg don't. Oddly enough svg also doesn't show the gray background.
3. I'm using Ubuntu 14.04 with Intel 4th generation graphics card.
4. I tried using different pdf viewers and they all showed the same gray background.
• Doesn't happen with M9.0.1 on OSX – halirutan Apr 4 '14 at 13:46
• I cannot reproduce this with M9.0.1 on Linux. Are you using a non-default style sheet in your notebook? – Szabolcs Apr 4 '14 at 14:02
• I sometimes have problems with pdf exports. Not the same. Have you tried exporting it to another format and get the same problem? – Mockup Dungeon Apr 4 '14 at 14:39
• FWIW, I have the same problem with MMA 9.0.0 on Win7 64bit. Shows grey in both SumatraPDF and Adobe Reader. I assumed it might be fixed with 9.0.1... – tkott Apr 4 '14 at 16:57
• @JeffDror If you are around, would you mind joining Mathematica Chat to discuss this problem? – halirutan Jul 15 '14 at 2:16

After a rather long debugging session in our chat we could determine the reason of the problem and come up with a workaround.

In short, we first tried whether the issue appears for the most basic Graphics[], which it didn't. As it turned out the gray background is introduced by using PlotLegends as in the example above. We went further by comparing AbsoluteOptions of the created graphics and the Options[SwatchLegend] settings. Everything looked the same on the OP's and my machine.

I then kind of remembered (guessed, whatever) that graphics export is done with the printing style sheet and we tried to set Format => Screen Environment to Printout. This was the first success, because this turned the graphics indeed gray.

Now, we knew the reason, but we couldn't find the exact source. Making a complete diff between our Core.nb stylesheet files showed nothing at all. I guess that this setting can be found somewhere else, although the OP stated that this issue persists for over 2 years and has survived even complete operating system changes.

The workaround is as simple as it is intuitive. Open the Preferences and then the Options Inspector and set the PrintingStyleEnvironment to Printout Gray (Is this awesome? It is, isn't it?)

If this issue would appear on my machine, I would probably take a closer look at my

FileNameJoin[{\$InstallationDirectory,"SystemFiles","FrontEnd","StyleSheets"}]


directory and grep through the Default.nb and the other things to find where this is set. I hope the workaround and the information help someone to track this down.

• I have exactly the same problem, and also only with PlotLegends.. However I don't get your workaround to work, the only three options for PrintingStyleEnvironment are "SlideShow", "Working", and "Printout". None of these three solve the problem, neither does manually typing "Printout Gray". Did I need to install another stylesheet first to get that to work? – freddieknets Dec 4 '17 at 10:58
• @freddieknets It is really hard to say what is happening on your machine. You don't need to install a style-sheet. The problem should be in your existing one. What exact operating system and Mathematica version are you using? – halirutan Dec 4 '17 at 12:56
• I am using Mathematica 11.1.0.0 on macOS 10.12.6 – freddieknets Dec 4 '17 at 14:15
• Unfortunately, I have only 11.1.1.0 on my OSX here. Otherwise, if we had the exact same versions, you could send my your stylesheet directory packed as zip and I would try to make a complete diff of the files. Do you have the possibility to update to 11.2 or 11.1.1? – halirutan Dec 4 '17 at 14:29
• Unfortunately I don't have premier service, so no (unless I am misunderstanding conditions to upgrade). – freddieknets Dec 5 '17 at 19:27

I recently encountered this problem, and none of the above solutions solved my problems (on version 10.3.1.0). However, I have found a solution which worked for me and should be independant of version.

On my version, the problem specifically occurred when using the Report stylesheet, but vanished with the Default one. The trick was to make a custom stylesheet that includes all of the style definitions from Report except the offending Graphics cell definition.

To achieve this practically, I switched to the Default stylesheet on the target notebook, opened a new mathematica notebook with a Report stylesheet , went to Format > Edit stylesheet on both and clicked Report/StandardReport.nb on the latter to load the Report's default cell definitions. Then I copied all the Report's cell definitions over to the Private Style Definitions for XXX.nb notebook and then went in and removed the offending local definition for graphics in Styles for Input and Output Cells as well as changing the background color for Output to white (select the cell then Format > Background Color > White).

Graphics now have a white background for both the image and text labels (an issue raised in another StackMMA question).

This new stylesheet can then be saved Default by following these instructions.