Can you use the `format` style string formatting rather than `%` style.  Be warned, it is going to look like `'${pre_factor:d}\frac{{{numer:d}}}{{{denom:d}}}\pi$'.format(pre_factor=_r2[0], numer=_r2[1], denom=_r.denominator)`