Is it possible to print characters on top of each other without erasing the previous one in order to have both superscript and subscript?

Solution 1:

In Jupyter Notebook/Lab this should work:

from IPython.display import Math

Math(r"1.23^{+4.56}_{-7.89}")

For convenience, you can package it in a class:

from IPython.display import Math

class PPrint:
    def __init__(self, base, sub, sup):
    self.base = base
    self.sub = sub
    self.sup = sup
    

    def  _ipython_display_(self):
        display(Math(f"{{{self.base}}}^{{{self.sub}}}_{{{self.sup}}}"))

Then you can create an instance e.g.:

x = PPrint("1.23", "+4.56", "-7.89")

and if you execute in a notebook either x or display(x), it should appear as in your example.