Skip to main content
1 of 2
Kuba
  • 138.9k
  • 13
  • 297
  • 803

This is quite nice and general approach:

SetAttributes[mySequence, HoldAllComplete]; mySequence[args__] := RawBoxes[ MakeBoxes[{args}][[1, 2]] ]; y = 7; Hold[{1, x, 2, x, 3}] /. x :> RuleCondition @ mySequence[y, 1+2] 
 Hold[{1, y, 1 + 2, 2, y, 1 + 2, 3}] 
Kuba
  • 138.9k
  • 13
  • 297
  • 803