I am making some random algebra equations, and I want to have the ordering be random too, such that if my random equation generator makes x+1
, the output stays x+1
, without reverting to 1+x
.
I have tried ClearAttributes[Plus, Orderless]
, but it simply did not work - entering x+1
returns 1+x
.
The following sort-of works:
Unprotect[Plus];
Format[Plus[a_, b_]] := ToString@a <> " + " <> ToString@b
But it uses Unprotect
, converts everything to strings, and also doesn't work when b
is a fraction (fractions p/q
are represented as p\n--\nq
).
Is there a nicer way to do this?
Also, I plan to convert everything to TraditionalForm
at the end, so using that to control ordering won't work either.
Rasterize[TraditionalForm[a]]+Rasterize[TraditionalForm[b]]
$\endgroup$plus = Row[{#1, " + ", #2}] &;
was what I was looking for:x~plus~1 // TraditionalForm
gives exactly what I want. $\endgroup$