1
$\begingroup$

My problem is related to FormatType of the Output of Print[].

Look at this example code

i = 4;
Print["Try", "\tPippo : ", i, "\nPluto"]

The output is

enter image description here

If instead I send the output to another stream through

$Output = OpenWrite["demo.txt"] 

and then I evaluate again the Print command, the output in the file “demo.txt” looks like the following

enter image description here

How can I save the text in the same style it appears in Mathematica?

For example, I want my text file to look like enter image description here

$\endgroup$
5
  • 1
    $\begingroup$ does adding the option FormatType -> OutputForm, that is, using $Output = OpenWrite["demo2.txt", FormatType -> OutputForm] give you what you need? $\endgroup$
    – kglr
    Commented Jan 23, 2018 at 16:00
  • $\begingroup$ @kglr Yes!! Thank you! $\endgroup$
    – apt45
    Commented Jan 23, 2018 at 16:30
  • $\begingroup$ I used FormatType -> OutputForm in the Print[] and it didn't work! thank you $\endgroup$
    – apt45
    Commented Jan 23, 2018 at 16:30
  • $\begingroup$ apt45, i posted the comment as an answer. $\endgroup$
    – kglr
    Commented Jan 23, 2018 at 16:31
  • $\begingroup$ FYI the reason this is not readily found in the Print documentation is that you normally would use Write for direct writing to files. $\endgroup$
    – george2079
    Commented Jan 23, 2018 at 18:10

1 Answer 1

2
$\begingroup$

Using

$Output = OpenWrite["demo2.txt", FormatType -> OutputForm]

gives the desired result.

$\endgroup$
1
  • $\begingroup$ Is there a way to output FullForm. Just putting Value of option FormatType -> FullForm gives "FormatType::ftype: Value of option FormatType -> FullForm is not valid.". $\endgroup$
    – Kvothe
    Commented May 21, 2023 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.