# NotebookWrite Cell with Grid

I'd like to NotebookWrite a Cell in StandardForm with a Grid to a new document. What I'd like to copy is

toCopy = TraditionalForm@Grid[{{a^2, b^2, c^2}, {d^2, e^2, f^2}}]


If I now use the following code

NotebookWrite[
CreateDocument[]
, toCopy]


I get a red rectangle in the new Notebookbook. I've tried to change all letters a to f to "a" ... "f", but nothing changed.

I am somewhat puzzled... What I missing here? Thanks for all help, as always!

Edit: With the answer of Alexey, it works good to copy the Grid to the new Notebook. But the TraditionalForm is lost: I get InputForm. Even using

NotebookWrite[
CreateDocument[],


doesn't seem to work. Any more help, as always, very much appreciated!

-

You should pass boxes as the second argument to NotebookWrite:

toCopy = Grid[{{a^2, b^2}, {c^2, d^2}}];
NotebookWrite[CreateDocument[], ToBoxes@toCopy]


Answering your second question, it is sufficient to wrap the expression by TraditionalForm to get it in TraditionalForm:

NotebookWrite[CreateDocument[], ToBoxes@TraditionalForm@toCopy]


But it still gives you an "Input" Cell. If you wish to generate an "Output" Cell, you should specify it explicitly:

NotebookWrite[CreateDocument[],


P.S. Also, see relevant discussion in this thread: "Programmatically writing to a notebook in TraditionalForm."

-
Thanks, this works good for the copying, but changes back to InputForm (I think), and not TraditionalForm. I appreciate any help for this problem! –  Gabriel Nov 9 '13 at 10:22
@Gabriel Please see updated answer. –  Alexey Popkov Nov 9 '13 at 15:57
Thank you for the update! –  Gabriel Nov 10 '13 at 10:34

I found the solution analysing the output of Mathematica with "Show Expression".
To display the contents of a Cell in TraditionalForm, one has to use a
FormBox[ ..., TraditionalForm] around the boxes given to Cell (for example, using ToBoxes,
as follows:

NotebookWrite[
CreateDocument[],
Cell[ FormBox[ ToBoxes @ Grid[{{a^2, b^2}, {c^2, d^2}}], TraditionalForm] ]
]


Thanks for informing if I misunderstood somewhere along the lines... Hope this helps to other Mathematica users.

-