Automatic breaking/wrapping of long equations (like clang-format) [duplicate]

When using C++, I already became somewhat dependent on clang-format which uses Dijkstra's algorithm (like LaTeX) to tune the whitespace in C++ code. It is amazing, I am not looking back to doing this manually.

LaTeX uses the Dijkstra algorithm every since and the results are gorgeous. The thing that I still have to do is breaking my equations per hand. I do this with align and \\ & \quad usually. Now I was wondering: Could the equations be broken/wrapped automatically with some similar approach?

The obvious problem is that mathematical formulas do not have a rigorous grammar like C++. For instance, there is no clear distinction whether $H(t - t_0)$ is a function $H$ evaluated at the time difference or whether this is just a multiplication. Perhaps one can just break equations at a top-level plus sign or break parentheses over multiple lines.

Is there something out there already that could break equations dynamically depending on \linewidth?

• breqn? or you meant regardless from \linewidth? – Cfun Jul 7 '16 at 21:16
• Looks promising! I will look into that. – Martin Ueding Jul 7 '16 at 21:53