Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to have terms like f[w-c] be formatted like this and not like f[-c + w]. I use Mathematica (7.0) for simplifying and manipulating terms -- so it is really annoying and unnecessarily hard to read/reason about such terms.

Things I found:

  • TraditionalForm: gives almost every time the expected result, but I have to use it manually.
share|improve this question
Thanks a lot - could you post your comment as an answer? – epsilonhalbe Aug 15 '12 at 22:27
Please consider doing that kind of manipulation only when it is strictly necessary.Trying to force Mma to format expressions the way you would can be very frustrating. – Dr. belisarius Aug 15 '12 at 23:07
Yeah i just found out that doing $Preprint = PolynomialFor[#, TraditionalOrder -> True] &; makes the file not open correctly but in a session it works fine. Did not know how fragile Mma was. – epsilonhalbe Aug 17 '12 at 6:16
I wanted to mention that you can also use the commands Find and Replace under Edit. – math-visitor Aug 23 '12 at 6:08
up vote 20 down vote accepted

If you want to order your terms this way but not perform the other formatting that TraditionalForm does, you might like to try the (undocumented) PolynomialForm[expr, TraditionalOrder -> True]. That will change output like this:

(* -> -1+3 x-3 x^2+x^3+3 y-6 x y+3 x^2 y-3 y^2+3 x y^2+y^3 *)

into this:

(* -> x^3+3 y x^2-3 x^2+3 y^2 x-6 y x+3 x+y^3-3 y^2+3 y-1 *)

You will still have to apply it manually, however, unless you do something like:

$PrePrint = PolynomialForm[#, TraditionalOrder -> True] &;

If you choose to use this, you should be aware that it might interfere with the printing of certain objects and forms. TraditionalForm prints with an incorrect font, for instance, because PolynomialForm wraps the output with an additional TagBox that lacks the TraditionalForm tag. Also, some expressions that look like they should be affected by PolynomialForm aren't: it has no effect on Series objects unless you apply Normal first--but this changes the meaning of the expression as well as its presentation.

Moreover, what you see onscreen will no longer be reflective of the real structure, which may be misleading:

f[w - c]
(* -> f[w - c] *)

(* -> f[Plus[Times[-1,c],w]] *)

If you're working with Gröbner bases or similar, things could get seriously confusing. However, as long as you're aware of the limitations and don't depend (mathematically or pattern-wise) on the order of terms, it should be relatively safe to use $PrePrint in this way.

Aside: Although PolynomialForm isn't widely known (being undocumented), it's been mentioned a few times already on Mathematica.SE, as well as on MathGroup. As this is the first question dealing exclusively with this issue, I'm not sure whether it's better closed as a duplicate of a previous question, or (given that this is a common query) turned into a canonical answer. In case of the latter, I edited the title to improve searchability. Other answers, possibly commenting on the wisdom of this undertaking, would be helpful. I hope others will cast their votes, post their answers, and/or make their edits accordingly.

share|improve this answer
at first thanks for the great answer - I especially like it that you point out the features AND the limitations of the solution. – epsilonhalbe Aug 16 '12 at 15:16
Re: your aside, I think this is a good question (with your edits) and your answer is great and could serve as the canonical answer for such questions. I wouldn't vote to close. – R. M. Aug 17 '12 at 1:06

Your Answer


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.