# Programmatically writing to a notebook in TraditionalForm

I'm trying to get a Cell to appear in TraditionalForm when using NotebookWrite. Here is the closest I can get:

nb = CreateDocument[];
NotebookWrite[nb, Cell["Hello", "Section"]];


I get the following:

What do I need to do to get "HI" to appear in TraditionalForm?

Edit:

Here's a better example:

nb = CreateDocument[];
NotebookWrite[nb, Cell[BoxData[ToBoxes[Sin[x]^2]], "Output"]];


gives

whereas I'd like the output to look like

Is there a specific option I need?

-

ToBoxes takes a second argument where you can specify the form that you desire. In your case, use TraditionalForm:

nb = CreateDocument[];
NotebookWrite[nb, Cell[BoxData[ToBoxes[Sin[x]^2, TraditionalForm]], "Text"]];


Note that the styling will also depend on how the cell style treats TraditionalForm text. For instance, change the cell style from "Text" to "Output" in the above and you get:

-

I'm not quite sure what TraditionalForm has to look like, but maybe setting the type to "Output" does what you want:

nb = CreateDocument[];
NotebookWrite[nb, Cell["Hello", "Section"]];
NotebookWrite[nb,

Thanks, this is better but not quite what I'm after. I'd prefer it to look like TraditionalForm["HI"] instead of "HI". –  Chip Hurst Jan 18 '13 at 23:16