I'm working on mathematical models using many alphabets and Greek characters as parameters or variables. However, The outputs show them in undesired order. Here are some examples:

(1/2)*(\[Beta]^2*(-A + m*\[Delta] + \[CapitalDelta])^2*\[Theta]1 + k*(m^2*\[Beta]^2 - 8*\[Beta]*\[Theta]1 + 2*m*\[Beta]*\[Lambda]1 + \[Lambda]1^2)) enter image description here

this $(-A+m \delta+\Delta)^2$ should have been written like this $(A - m\delta - \Delta)^2$

or this $1/2 (-m \beta + \lambda1)$ should be like $1/2 (\lambda1-m \beta)$

How can I get the entire notebook's output in the desired order?

  • 4
    $\begingroup$ Edit your question to include the Mathematica code (InputForm) for your expressions so that they can be copy and pasted into a notebook $\endgroup$
    – Bob Hanlon
    Commented Dec 12, 2022 at 2:39
  • $\begingroup$ expr /. (z_)^2 :> (-z)^2 $\endgroup$
    – Bob Hanlon
    Commented Dec 12, 2022 at 4:25
  • $\begingroup$ To make a simpler example, the input b-a returns -a+b. That is because Plus has attribute Orderless and uses a certain built-in ordering. I would not try to change that. It is not important and not worth it. Just accept the built-in ordering when you do calculations. If you have to include a result in a paper, you can change it then if you can't help it. $\endgroup$
    – user293787
    Commented Dec 12, 2022 at 6:19
  • $\begingroup$ Just to add on the comment above b-a returns -a+b and a - b returns a-b because Mathematica is imposing a canonical order which might make it easier to match patterns and possibly also simplify. The order of a and b in the expression is the same as Sort[{b,a}]. This automatic sorting can also make pattern matching a bit more difficult when the pattern is inside an even function such as Cos. An example of that is given here $\endgroup$ Commented Dec 12, 2022 at 6:31

1 Answer 1


The ordering of terms in expressions is not aesthetic but functional. Terms are reordered as part of expression canonicalization. This cannot be changed.

You can change how expressions are displayed (not stored) to some extent. Applying TraditionalForm produces an output with a more pleasing order, usually avoiding leading minus signs.

You can change the default format type for a notebook. In the Option Inspector, choose to change settings for the current notebook, then search for CommonDefaultFormatTypes and change "Output" to TraditionalForm. Doing this may not always be productive as TraditionalForm is not always unambiguous. I would suggest applying TraditionalForm manually to selected outputs. Command-Shift-T converts a cell to TraditionalForm.

  • $\begingroup$ I now realize that this doesn't answer the question directly. I won't delete it just yet in case there's something helpful in here. $\endgroup$
    – Szabolcs
    Commented Dec 12, 2022 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.