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

 , 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

  ToBoxes[toCopy, TraditionalForm]]

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:

 Cell[BoxData@ToBoxes@TraditionalForm@toCopy, "Output"]]

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

|improve this answer|||||
  • $\begingroup$ Thanks, this works good for the copying, but changes back to InputForm (I think), and not TraditionalForm. I appreciate any help for this problem! $\endgroup$ – Gabriel Nov 9 '13 at 10:22
  • $\begingroup$ @Gabriel Please see updated answer. $\endgroup$ – Alexey Popkov Nov 9 '13 at 15:57
  • $\begingroup$ Thank you for the update! $\endgroup$ – 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:

    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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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