4
$\begingroup$

When I do...

p=3;
HoldForm[Evaluate[p]-2]

I get:

Evaluate[p]-2

BUT I'd like to get:

3-2

How can I get this result? I want to display the subtraction, unevaluated -- but I want an expression within the subtraction to get evaluated.

$\endgroup$
  • 7
    $\begingroup$ Why not With[]? With[{p = 3}, HoldForm[p - 2]] $\endgroup$ – J. M. will be back soon Mar 15 '16 at 3:25
  • $\begingroup$ @J.M. Yes that is better. Why not add a separate answer? $\endgroup$ – Sean Mar 15 '16 at 3:31
  • 1
    $\begingroup$ Because that bit is also in the thread you linked to, and the threads that thread is linked to. $\endgroup$ – J. M. will be back soon Mar 15 '16 at 3:33
5
$\begingroup$

Here's one way:

HoldForm[p - 2] /. HoldPattern[p] :> RuleCondition[p]
$\endgroup$
  • $\begingroup$ Found after some deeper digging into comments of this question: mathematica.stackexchange.com/questions/75260/… $\endgroup$ – Sean Mar 15 '16 at 3:24
  • 4
    $\begingroup$ Sean, perhaps you could add the With method outlined by J.M. in your answer, since you found it useful as well. (+1 for self-answering!) $\endgroup$ – MarcoB Mar 15 '16 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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