Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

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.

share|improve this answer
    
+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. –  Szabolcs Apr 26 '13 at 19:22
    
@Szabolcs Thanks. I have improved my answer. Hope it's clear. –  andre Apr 26 '13 at 19:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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