I want to create a formatted document from a list of expressions. One of the expression in this list is the following:
text = Style["a\n\tb\n\t\tc", FontSize -> 17, FontFamily -> "Monaco"]
And it gets formatted as planned:

But when I executed the following command to try to generate a document:
CreateDocument[{text}]
I got this:

Is there any way that we can keep the formatting of the string when using "CreateDocument" to generate document programmatically?
Software platform: I am running Mathematica 8.
Thanks.
When you pass just a string to CreateDocument (even if wrapped in Style), Mathematica creates a new document with the string inside a TextCell. This is why you see the literal string "a\n\tb\n\t\tc" displayed.
On the other hand, your formatted result is an Output. So you need to specify that the new document be created with a TextCell that is formatted with the style "Output".
The following gives what you want:
CreateDocument[TextCell[text, "Output"]]

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With