# Pref::keepOrder

Order of terms in sum outputs

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```Pref::keepOrder(<Always>)
Pref::keepOrder(<DomainsOnly>)
Pref::keepOrder(<System>)
Pref::keepOrder(NIL)
Pref::keepOrder()
```

## Description

`Pref::keepOrder` influences the output order of terms in sums.

Usually, the output system uses its own ordering of the terms in a `sum` to optimize the appearance of the output. This order may be different from the internal ordering of the sum. The output system prefers to re-order the terms such that the first term is positive.

Sometimes it is desirable to see the terms of a sum in the internal order. This can be achieved with `Pref::keepOrder(Always)`.

By default, the term order of polynomials and domain elements is left unchanged.

`Pref::keepOrder(NIL)` restores the default state, which is `DomainsOnly`.

`Pref::keepOrder()` returns the currently set value.

## Examples

### Example 1

Here we create a domain element `e`, an expression `f`, and a polynomial `p` containing sums. With the default setting `DomainsOnly`, only the output of the expression `f` is not in the internal order:

```d := newDomain("d"): d::print := x -> extop(x): e := new(d, b - a): f := b - a: p := poly(1 - x): e, f, p```

With the setting `Always`, `e`, `f`, and `p` are all printed in the internal order:

```Pref::keepOrder(Always): e, f, p```

With the setting `System`, the output order differs from the internal ordering for `e`, `f`, and `p`:

```Pref::keepOrder(System): e, f, p```

`Pref::keepOrder(NIL)` restores the default state; `Pref::keepOrder()` returns the current setting:

`Pref::keepOrder(NIL): Pref::keepOrder()`

## Options

 `Always` The output always corresponds to the internal order. `DomainsOnly` In polynomials and domain elements, the ordering of terms corresponds to the internal order. Other sums may be re-ordered by the output system. This is the default setting of `Pref::keepOrder`. `System` The output order of terms in sums is determined by the output system and does not necessarily correspond to the internal order.

## Return Values

Previously defined value: `Always`, `DomainsOnly`, or `System`.