jiggzson / nerdamer

a symbolic math expression evaluator for javascript
http://www.nerdamer.com
MIT License
514 stars 82 forks source link

Sorting terms in a sum #605

Closed szoshi closed 3 years ago

szoshi commented 3 years ago

I am generating a system of equations on the fly for TeX display. However, the generation does not have all the terms in order. Is there a way to sort an equation where the terms are sorted based on an order specified for the variables?

Gor e.g a_2 - 2a_3 + 3a_1 should become 3a_1 + a_2 -2a3.

I can implement it myself but a native function might help a lot of people.

jiggzson commented 3 years ago

@szoshi, unfortunately there's no easy way to achieve this from within the library. At least not that I can think of. It would require moving way too much stuff around. Feel free to share your solution. Maybe I can build on it.

szoshi commented 3 years ago

No wories, I had a feeling it won't be that trivial but just wanted to be sure. Since it is more rlevant to how the output is displayed, I think something can be done external to the library to achieve this goal. I am closing the issue for now.