5
$\begingroup$

I am trying to use NotebookWrite to paste a plot into another notebook. The code looks something like:

ptemp = Show[Plot[x^2,{x,-2,2}],Plot[x^3,{x,-2,2}]]; nb = CreateDocument[]; NotebookWrite[nb,ptemp];

But when I run the code I get an error message: An unknown box name (Graphics) was sent as the BoxForm for the expression.

Is there any way to use NotebookWrite to insert a graphic? Does there exist any sort of wrapper for Graphics that would make it NotebookWrite-able?

$\endgroup$

1 Answer 1

11
$\begingroup$

Use :
NotebookWrite[nb, ToBoxes[ptemp]]

With NotebookWrite[], you must use boxes ("low-level-box-language"), not Graphics (which belongs to normal Mathematica language, like nearly everything). The "box-language" is what you see when you type ctrl-shift-E on a cell. ToBoxes transforms pTemp to a box. NotebookWrite[] inserts automatically the data (the box) in a Cell[] (see doc) and inserts the Cell[..data..] in the notebook.

$\endgroup$
2
  • $\begingroup$ +1, and it's good to note explicitly that this applies to everything, not just graphics. Everything needs to be converted to boxes before using them in NotebookWrite. $\endgroup$ Commented Apr 26, 2013 at 19:22
  • $\begingroup$ @Szabolcs Thanks. I have improved my answer. Hope it's clear. $\endgroup$ Commented Apr 26, 2013 at 19:42

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.