In the output of a script that calls Mathematica I would like to be able to differentiate lines printed by mathematica from lines printed by something else. I thought of prefacing lines printed by Mathematica with for example "m:". Is this possible?
1 Answer
As suggested by Szabolcs, I used the Villegas-Gayley method
Unprotect[Print];
Print[args___]:=Block[{$inMsg=True},
Print["|m:>",args,"<:m|"]
]/;!TrueQ[$inMsg]
Protect[Print];
This works well. Ideally I could do the same also for warning messages but I haven't quite figured out yet what the appropriate change would be to Message.
-
$\begingroup$ Just a small comment: you don't need
result
, just writePrint["|m:>", args, "<:m|"];
. $\endgroup$– DomenJan 16 at 15:41 -
Print
behaves without having to change the code that usesPrint
? $\endgroup$Print
and not change any other part of the code. $\endgroup$Print
? $\endgroup$