Stopping Mathematica from reordering expressions [duplicate]

I want Mathemtica to stop manipulating my polynomials! I mean, I want the output of

Print[3 x + 5 + x^2]


to be just $3x+5+x^2$, not $5+3x+x^2$ as Mathematica returns.

How can I do this?

-

marked as duplicate by Mr.Wizard♦Jul 4 '14 at 0:30

Maybe wrapping it in Defer[] will do what you want? (I guess it will depend on how you want to use the expression.) – Daniel Lichtblau Jul 3 '14 at 22:05
@Behzad You can't both have and not have evaluation ... What is your use case for this exactly? Understand that will help come up with a solution. Generally, consider everything you enter into Mathematica as program code, not a mathematical expression. The way Mathematica works implies that this transformation will take place and it's not a good idea to try to change that. What I suggest instead is to have two steps: 1) one processing step where you manipulate symbolic expressions, letting Mathematica work the way it does 2) and a formatting step where you print them to specification. – Szabolcs Jul 3 '14 at 22:17
Specifically for your example, With[{a=3}, Print@HoldForm[a x - 5 + x^2]] does work, but I don't know if it's general enough for your use case. – Szabolcs Jul 3 '14 at 22:19
Related: 9570, 20714 – Michael E2 Jul 4 '14 at 0:17
Also related: (6358), (7880), (15744), (21519), (22431), (30216), (31974), (40165), (46535) – Mr.Wizard Jul 4 '14 at 0:27

Will

a = -3; Print[Defer[\[FormalA] x + 5 + x^2] /. \[FormalA] -> a]


-3 x + 5 + x^2

work for you?

-
it may not work for 1 or 0. but don't know what's OP need. – Kuba Jul 4 '14 at 0:05

Print[HoldForm[3 x + 5 + x^2]]

Well, if we have parameters, there will be another problem: commands a=-3; Print[HoldForm[ax-5+x^2]] yield $ax-5+x^2$, not $-3x-5+x^2$. – Behzad Jul 3 '14 at 22:13
@Behzad There will always be a problem unless you post full context :) this answer fits the question. You can use With to inject in held expressions but I suppose it may still be a problem with sign marks. With[{a = -3}, HoldForm[a x - 5 + x^2]] – Kuba Jul 3 '14 at 22:19
@Kuba Interesting question though, because fun = 3 x + 5 + x^2; and then Print[HoldForm@fun] doesn't work. – eldo Jul 3 '14 at 22:26
@eldo With Set it is already lost so even if you inject it it will be formated :) but with SetDelayed you can do: ClearAll[fun]; fun := 3 x + 5 + x^2; and then HoldForm[fun] /. OwnValues@fun – Kuba Jul 3 '14 at 22:30
@kuba Brilliant ! If OP wants this, he could even append a // Print after /. OwnValues@fun. – eldo Jul 3 '14 at 22:44