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'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"]];
NotebookWrite[nb, Cell[BoxData@ToBoxes@TraditionalForm@"HI", "Text"]];

I get the following:

nb output

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?

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

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:

enter image description here

share|improve this answer
add comment

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, 
Cell[BoxData@ToBoxes@TraditionalForm@"HI", "Output"]];
share|improve this answer
    
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
    
@RiemannZeta you should try to be clearer as to what you want that is not satisfied by tis answer. I am not understanding. Maybe posting images even if necessary. Or the cell expression of a cell that shows like you intend –  Rojo Jan 18 '13 at 23:38
    
@Rojo see my edit above. Thanks. –  Chip Hurst Jan 18 '13 at 23:59
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.