Fixed Py3k compatibility, slow computation in __str__ and _repr_latex_.