Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is there a way to Defer only parts of the expression? For example, I have

a=1;

and then I want the expression to be shown asa = 1;by usingDefer[a = Evaluate[a]],But the actual output is just

a = Evaluate[a]]

Is there away to only Defer part of an expression?

share|improve this question
1  
Maybe Defer[a = x] /. x -> a or Defer[a = #] &[a]? –  kguler May 15 at 19:15
1  
or With[{x = a}, Defer[a = x]]? –  kguler May 15 at 19:20
    
Both solution works, thank you! –  Yituo May 15 at 19:24

1 Answer 1

up vote 4 down vote accepted

You can insert into held expressions in a number of ways:

Using ReplaceAll (/.): Defer[a=x]/.x->a

Using function evaluation: Defer[a=#]&[a]

Using With : With[{x=a}, Defer[a=x]

Example:

a = 2; z = 4; w = 5;
{Defer[a + w = x + z] /. x->a, Defer[a + w = # + z]&[a], With[{x = a},Defer[a + w = x + z]]}
(* {a + w = 2 + z, a + w = 2 + z, a + w = 2 + z} *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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