I am having some trouble setting the width of my output. I have some very long expressions, and I would like to output them as strings of maximum length 80 characters. For example, I have a very long expression "beta" and I would like to output to a file "RGEs_nicks.txt". So I have tried
streamM = OpenWrite["RGEs_nicks.txt", PageWidth -> 80];
WriteString[streamM, ToString[beta // InputForm]];
Close[streamM];
However, this is not putting in any line breaks, and the output is just one very long line. How do I get this to be formatted output? It works fine if I use just Write
instead of WriteString
, but I want to be able to add some other tricky stuff before and after so I need the WriteString
. Any clues would be much appreciated!
#<>"\n"&/@StringPartition[ToString[beta // InputForm],UpTo[80]]
is what you need? $\endgroup$StringPosition[ToString[beta // InputForm], " "]
. Then choose from that positions those near to desired length of multiples of 80, andStringInsert[ToString[beta // InputForm], "\n", {<positions>}]
. $\endgroup$