# How to adapt MSPToExpression function in $PrePrint? I am introducing the mathematica Security (MSP module) to our system. The Document suggests use MSPToExpression as followed: Needs["MSP"] SetSecurity[]; $$var = "5+7"; MSPToExpression[$$var] (*the output is 12*)  But when I tried to adapt this function to $PrePrint with scripts:

$PrePrint = With[{$$var = ToString[#, InputForm]}, MSPToExpression[$$var]] &; (*or*)$PrePrint = With[{expr = #}, MSPToExpression[expr]] &;
(*or*)

$PrePrint = With[{$$var = #}, MSPToExpression[$$var]] &;  Input: 5+7 there's same error says: It can't recognize $$var as symbol, can anyone help me on this? Many thanks! :) • What if you use Module? With injects expressions to held slots. – Kuba Nov 27 '15 at 7:49 • @Kuba Hi, Could you please paste the full script ? I am a real newbee for mathematica. – Michael Nov 27 '15 at 7:57 ## 1 Answer I suppose this is what you need. So the first thing is to use Module since With injects values into held expressions. Moreover PrePrint is probably to late to catch "5+7". So I'd go with $Pre:

$Pre = Function[expr, Module[ {expr$ = ToString[Unevaluated[expr], InputForm]},
MSPToExpression[expr\$]
],
HoldAllComplete
]

• Thanks! It works well. it's what I was looking for . – Michael Nov 27 '15 at 8:29
• Watch out when using HoldAll instead of HoldAllComplete in such functions! Evaluate[5 + 7] then evaluates to MSPToExpression["12"]` – Jacob Akkerboom Nov 27 '15 at 11:33
• @JacobAkkerboom good point. – Kuba Nov 27 '15 at 11:57