Using the CreateDocument Function in Mathematica Without Losing Formatting

I want to create a formatted document from a list of expressions. One of the expressions on this list is the following:

text = Style["a\n\tb\n\t\tc", FontSize -> 17, FontFamily -> "Monaco"] 

And it will be formatted as planned:

enter image description here

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

 CreateDocument[{text}] 

I got it:

enter image description here

Is there a way to preserve string formatting when using "CreateDocument" to create a document programmatically?

Software platform: I am running Mathematica 8.

Thanks.

+6
source share
1 answer

When you only pass a string to CreateDocument (even if it is wrapped in Style ), Mathematica creates a new document with a string inside a TextCell . This is why you see the letter string "a\n\tb\n\t\tc" .

On the other hand, your formatted result is Output . Therefore, you need to indicate that a new document should be created using TextCell , which is formatted in the "Output" style.

Below is what you want:

 CreateDocument[TextCell[text, "Output"]] 

enter image description here

+10
source

Source: https://habr.com/ru/post/901370/


All Articles