# How to put the evaluated result in a text cell?

If I use the function Print, the result is not in a text cell. So I wonder If there's a function that I can use to put behind the function Print, to make the evaluated result be placed in a text cell?

Here's the testing code!

1 + x^2 + x^4 /. x^p_ -> f[p] // Print

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Dec 23, 2021 at 12:19

CellPrint[TextCell[1 + x^2 + x^4 /. x^p_ -> f[p], "Text"]]

• Cool, thanks, bravo Dec 23, 2021 at 7:18

If you wish to print into plain text cells, you have the following possibilities:

1. Instead of Printing into usual StandardForm Cell where the parsing and 2D formatting take significant processor's time you can print into plain text Cells:

CellPrint[Cell["stuff=" <> ToString[stuff]]]


Upon printing, you can assign the usual "Print", "Text", "Output" or another style to such a cell without changing its rendering from plain text:

CellPrint[Cell["stuff=" <> ToString[stuff], "Text"]]


The plain text rendering is determined by the fact that the Cell[...] object contains a simple String as the first argument and not a BoxData object.

2. Instead of printing into separate cells you can append the output into the same plain text Cell as described here:

stuff := RandomReal[];
Do[WriteString["stdout", "stuff=" <> ToString[stuff], "\n"], {10}]


This works extremely fast.

Here "stdout" is the name of the standard output stream. You can get the corresponding stream object with Streams["stdout"]. The standard output channel is $Output, which by default sends everything to "stdout". You can read more about them in this tutorial. • Your answer is really informative, which is more than what I expected, really instructive! Dec 23, 2021 at 10:44 • WriteString[channel,expr1,expr2], so the "stdout" means the channel? Actually, I don't know what is channel. Can you give some words about it? Dec 23, 2021 at 10:46 • @Lawrence "stdout" is the name for the standard output stream. You can get the corresponding stream object with Streams["stdout"]. The standard output channel is $Output, which by default sends everything to "stdout". Dec 23, 2021 at 11:16
• @Lawrence You can read more about them in this tutorial. Dec 23, 2021 at 11:31
• Ok, got it, thanks bro Dec 23, 2021 at 12:13