I should also add that I made a start on this myself some time ago, and I have placed the code in GitHub, https://github.com/maths/moodle-qtype_stack/blob/master/stack/maxima/elementary.mac

There is also a file of "experimental code".

The point of this is to define "elementary rules" which will transform the expression repeatedly.

Start in the Maxima sandbox and

load("elementary");

As an example take your expression,

simp:false;

p:x^2-(-5*x^2-14*x+2) ;

Now, we can apply "rules" such as "distribute unary minus over addition", this is called "negDistAdd"

p:transr(p,"negDistAdd");

this gives

x^2+(-(-5)*x^2-(-14*x)-2)

Next, we need to use associativity of addition, "assAdd"

p:transr(p,"assAdd");

x^2-(-5)*x^2-(-14*x)-2

We continue with a rule which removed "--",

p:transr(p,"negNeg");

x^2-(-5)*x^2+14*x-2

Notice, this sorted out the "-(-14*x)", but not the "-(-5)*x^2", but as I said, this code is experimental and I never finished this off.....

I hope this gives you some idea of the issues involved in making this work. I'm sure it is possible to do, however.

Chris