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
$\begingroup$ $\endgroup$
2 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$Domen– Domen2023-01-16 15:41:52 +00:00Commented Jan 16, 2023 at 15:41 - $\begingroup$ Of course you are right. Thanks. $\endgroup$Kvothe– Kvothe2023-01-16 15:42:59 +00:00Commented Jan 16, 2023 at 15:42
Printbehaves without having to change the code that usesPrint? $\endgroup$Printand not change any other part of the code. $\endgroup$Print? $\endgroup$