Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'd like to write output in TraditionalForm into external text files ofile.txt. I tried to use

s = OpenWrite["/home/tigerhead/log/ofile.txt", FormatType -> TraditionalForm];
$Output = s;
<run various Mathematica programs>
Close[s];

but get errors:

Intersection::normal: 
   Nonatomic expression expected at position 2 in 
    Intersection[{StandardForm, TraditionalForm}, FormatType].
Options::optnf: 
   FormatType is not a known option for 
    Intersection[OutputStream[/home/tigerhead/log/ofile.txt, 21], {OutputStream[/home/tigerhead/log/ofile.txt, 20], OutputStream[stdout, 1], 
      OutputStream[stderr, 2], OutputStream[/home/tigerhead/<<38>>.txt, 
       21], stdout, stderr}].

Any one has a clue?

share|improve this question
2  
What do you expect to see when you open the txt file with a text editor? –  belisarius Jul 25 '12 at 16:15
    
And compare with this Sin[x] Tan[x]/x^2 // TraditionalForm –  belisarius Jul 25 '12 at 16:17
    
@MaThEmAtika If you need just plain text why not to use InputForm or OutpuForm? Why do you need TraditionalForm - it's just for displaying thing nicely, which is the opposite of plain text. Could you please explain. –  Vitaliy Kaurov Jul 25 '12 at 19:07
    
InputForm writes " unnecessarily in many places and make the text harder to read. OutputForm is the thing I just tried while replying @Heike. Unfortunately, it didn't fix the errors I reported in the OP. –  Problemaniac Jul 25 '12 at 20:01

2 Answers 2

up vote 2 down vote accepted

Not a full solution, but to get rid of the error you could try setting (note the curly brackets)

$Output = {s} 

or even

$Output = Append[$Output, s] 

if you want the output to be printed to sdout as well. Note that this still writes expressions to the file in OutputFormat by default even with FormatType -> TraditionalForm in s.

share|improve this answer
    
+1 for the Append[] idea. –  Problemaniac Jul 25 '12 at 17:29
    
After using $Output = Append[$Output, s], I still get the same errors. Now the output is not only written to the file but also displayed on screen, which is good but doesn't solve the original problem. –  Problemaniac Jul 25 '12 at 18:10

I am not sure what exactly you are trying to achieve, because to see TraditionalForm formatting you need Mathematica Front End. .TXT format is hardly suitable for that. Yet we can do something like this:

Consider an expression:

TraditionalForm[HoldForm[D[Integrate[f[t, x], x], t]]]

enter image description here

How do you intend to see that in .TXT format? Mathematica will still try though. Create and open a new stream for writing:

 s = OpenWrite["testfile.txt"]

OutputStream["testfile.txt", 120]

Write an expression to the stream:

Write[s, TraditionalForm[HoldForm[D[Integrate[f[t, x], x], t]]]]

Close the stream:

 Close[s]

"testfile.txt"

Print the resulting file:

FilePrint["testfile.txt"]

enter image description here

See what is really inside it:

Import["testfile.txt"]

enter image description here

share|improve this answer
    
The last image shows what I'd like to have in the text file. I.e. I want a plain text file of output of my M program. –  Problemaniac Jul 25 '12 at 16:55
    
@MaThEmAtika Does it mean I answered your question? BTW what type of output your program produces? - can it be a graphics object? –  Vitaliy Kaurov Jul 25 '12 at 17:06
    
Most are text for indicating the status and progress of my program, some of which can have highlighting using Pane[], Style[] etc. But it occasionally can print some math too. –  Problemaniac Jul 25 '12 at 17:30
    
"it mean I answered your question?" Really? Aer you saying what I was doing is OK? Why the errors then? –  Problemaniac Jul 25 '12 at 17:31
    
@MaThEmAtika If you need just plain text why not to use InputForm or OutpuForm? Why do you need TraditionalForm - it's just for displaying thing nicely, which is the opposite of plain text. Could you please explain. –  Vitaliy Kaurov Jul 25 '12 at 19:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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