4
$\begingroup$

I often copy-paste things from LatexIt or OmniGraffle into Mathematica notebooks. The results are GraphicsData objects which don't render in the Wolfram Cloud. Is there an easy work-around?

Since bitmaps render properly, perhaps there's some way to automatically convert all GraphicsData objects in the notebook into bitmaps?

Here's example notebook:

https://www.wolframcloud.com/obj/yaroslavvb/newton/graphics-data-example.nb

How it looks locally

enter image description here

$\endgroup$
2
  • $\begingroup$ You should email WRI about this bug $\endgroup$
    – M.R.
    Commented Dec 19, 2019 at 6:20
  • $\begingroup$ It's not a bug per se, just a really old Mac behavior. Those programs are emitting PDF to the clipboard instead of a bitmap. And the Mac FE was the only one really capable of handling that particular format. For instance, the Windows FE is not capable of rendering those cells either. $\endgroup$
    – ihojnicki
    Commented Dec 19, 2019 at 14:03

1 Answer 1

2
$\begingroup$

I don't know how to convert the given GraphicsData objects into vector graphics, but you can use Rasterize to convert them into bitmaps. Here is a function that does this:

rasterizeGraphicsData[Cell[g:GraphicsData["PDF", __], "Graphics", OptionsPattern[Cell]]] := Module[{size},
    size = OptionValue[Cell, ImageSize];
    Cell[
        BoxData @ ToBoxes @ Rasterize[
            Cell[g, "Graphics"], 
            ImageSize -> size,
            RasterSize -> 5 size
        ],
        "Output"
    ]
]

Now, we need to apply the above function on each of the GraphicsData cells. We can do that with the following function:

convertNotebookGraphicsData[nb_] := With[
    {cells = Cells[nb, CellStyle -> "Graphics"]},
    NotebookWrite[#, rasterizeGraphicsData @ NotebookRead[#]]& /@ cells
]

Use Notebooks to find the notebook object to process and then use convertNotebookGraphicsData[nb] where nb is the NotebookObject corresponding to your notebook.

$\endgroup$

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.