Skip to main content
added 76 characters in body
Source Link
István Zachar
  • 47.2k
  • 20
  • 147
  • 307

Using OwnValues and HoldForm:

{a = 7, b = 5, c = 6};   HoldForm[(a + b)/c] /. OwnValues@a /. OwnValues@b /. OwnValues@c 
(7 + 5)/6 
With[{a = a, b = b, c = c}, HoldForm[(a + b)/c]] 
(7 + 5)/6 

Assuming that variables are already defined and you don't want to bother with separate OwnValueslisting the symbols, and you want to have a function that does it in one go:

Attributes[hold] = {HoldAll}; hold[x_] := HoldForm@x /. Cases[Hold@x, s_Symbol :> (HoldPattern@s -> s), Infinity]; hold[(a + b)/c] 
(7 + 5)/6 

Using OwnValues and HoldForm:

{a = 7, b = 5, c = 6}; HoldForm[(a + b)/c] /. OwnValues@a /. OwnValues@b /. OwnValues@c 
(7 + 5)/6 

Assuming that variables are already defined and you don't want to bother with separate OwnValues, and you want to have a function that does it in one go:

Attributes[hold] = {HoldAll}; hold[x_] := HoldForm@x /. Cases[Hold@x, s_Symbol :> (HoldPattern@s -> s), Infinity]; hold[(a + b)/c] 
(7 + 5)/6 

Using OwnValues and HoldForm:

{a = 7, b = 5, c = 6};   HoldForm[(a + b)/c] /. OwnValues@a /. OwnValues@b /. OwnValues@c 
(7 + 5)/6 
With[{a = a, b = b, c = c}, HoldForm[(a + b)/c]] 
(7 + 5)/6 

Assuming that variables are already defined and you don't want to bother with listing the symbols, and you want to have a function that does it in one go:

Attributes[hold] = {HoldAll}; hold[x_] := HoldForm@x /. Cases[Hold@x, s_Symbol :> (HoldPattern@s -> s), Infinity]; hold[(a + b)/c] 
(7 + 5)/6 
added 229 characters in body
Source Link
István Zachar
  • 47.2k
  • 20
  • 147
  • 307

Using OwnValues and HoldForm:

{a = 7, b = 5, c = 6}; HoldForm[(a + b)/c] /. OwnValues@a /. OwnValues@b /. OwnValues@c 
(7 + 5)/6 

Assuming that variables are already defined and you don't want to bother with separate OwnValues, and you want to have a function that does it in one go:

Attributes[hold] = {HoldAll}; hold[x_] := HoldForm@x /. Cases[Hold@x, s_Symbol :> (HoldPattern@s -> s), Infinity]; hold[(a + b)/c] 
(7 + 5)/6 

Using OwnValues and HoldForm:

{a = 7, b = 5, c = 6}; HoldForm[(a + b)/c] /. OwnValues@a /. OwnValues@b /. OwnValues@c 
(7 + 5)/6 

Using OwnValues and HoldForm:

{a = 7, b = 5, c = 6}; HoldForm[(a + b)/c] /. OwnValues@a /. OwnValues@b /. OwnValues@c 
(7 + 5)/6 

Assuming that variables are already defined and you don't want to bother with separate OwnValues, and you want to have a function that does it in one go:

Attributes[hold] = {HoldAll}; hold[x_] := HoldForm@x /. Cases[Hold@x, s_Symbol :> (HoldPattern@s -> s), Infinity]; hold[(a + b)/c] 
(7 + 5)/6 
Source Link
István Zachar
  • 47.2k
  • 20
  • 147
  • 307

Using OwnValues and HoldForm:

{a = 7, b = 5, c = 6}; HoldForm[(a + b)/c] /. OwnValues@a /. OwnValues@b /. OwnValues@c 
(7 + 5)/6