Prettify formula strings.

Only enclose (sub)formulas in parentheses when necessary.