Message Boards Message Boards

0
|
5355 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to force output style of printing from within a Module?

I need to organize a printing from within a Module function before finale output (return) from the function. The simple example is here: TestF[t_] := Module[{t0}, Print[{t,t+1,t+2}]; t0=t+1];

All works fine, but result of Print[{t,t+1,t+2}] is a cell having input style (in red frame in the illustration):

enter image description here

The function's return, as always, has output style. I wish the printing inside the function to have output style too.

Unfortunately, OutputForm also doesn't solve the problem. Is it possible to obtain output style in some way?

POSTED BY: Konstantin Nosov
2 Replies

The Print function is primarily used as a debugging tool. There are generally much better ways to get output if that's your goal in a given situation. One way is to put the relevant data into a data structure--a List for example--and then output that at the end.

But. let's take your simple example and try to do what you want using a better tool: CellPrint along with TextCell (or you could use ExpressionCell if that's what is more pertinent). Try this: it CellPrints in the "Output" CellStyle since that is what the TextCell's CellStyle is set as:

TestF[t_] := 
 Module[{t0}, CellPrint[TextCell[{t, t + 1, t + 2}, "Output"]]; 
  t0 = t + 1]
POSTED BY: David Reiss

Thank you, David. This works properly as I need. For some reasons it is more desirable to have an intermediate output, but not finale output of the function.

POSTED BY: Konstantin Nosov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract