Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the "CreateDocument" function in Mathematica without losing the formatting

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:

enter image description here

But when I executed the following command to try to generate a document:

CreateDocument[{text}]

I got this:

enter image description here

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.

like image 946
Ning Avatar asked Nov 13 '11 06:11

Ning


1 Answers

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"]]

enter image description here

like image 86
abcd Avatar answered Oct 18 '22 19:10

abcd