How to format mathematical expressions?

I think we were looking at this from the angle of: is there a tool that will format the code reasonably well so we never have to think of this problem ever again. So far, yapf seems the most promising.