title: Python: scientific notation with superscript exponent
body: <p>I'm attempting to format numbers in scientific notation with exponents of base 10, e.g. write 0.00123 as 1.23x10<sup>–3</sup>, using python 3. </p>
  
  <p>I found this great function which prints 1.23x10^-3, but how can the caret-exponent be replaced with a superscript?</p>
  
  <pre><code>def sci_notation(number, sig_fig=2):
      ret_string = "{0:.{1:d}e}".format(number, sig_fig)
      a,b = ret_string.split("e")
      b = int(b)         # removed leading "+" and strips leading zeros too.
      return a + "x10^" + str(b)
  
  print(sci_notation(0.001234, sig_fig=2))      # Outputs 1.23x10^-3
  </code></pre>
  
  <p>The function is modified from <a href="https://stackoverflow.com/a/29261252/8542513">https://stackoverflow.com/a/29261252/8542513</a>.</p>
  
  <p>I've attempted to incorporate the answer from <a href="https://stackoverflow.com/a/8651690/8542513">https://stackoverflow.com/a/8651690/8542513</a> to format the superscript, but I'm not sure how sympy works with variables:</p>
  
  <pre><code>from sympy import pretty_print as pp, latex
  from sympy.abc import a, b, n
  
  def sci_notation(number, sig_fig=2):
    ret_string = "{0:.{1:d}e}".format(number, sig_fig)
    a,b = ret_string.split("e")
    b = int(b)             #removed leading "+" and strips leading zeros too.
    b = str(b)
    expr = a + "x10"**b    #Here's my problem
    pp(expr)               # default
    pp(expr, use_unicode=True)
    return latex(expr)
  
  print(latex(sci_notation(0.001234, sig_fig=2))) 
  </code></pre>
  
  <p>This returns: TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'</p>