0

I'd like to print element symbols, with the mass number represented in superscript and the atomic number as a subscript, in the single character space directly preceding the element's letter.

I'm currently using:

SUP = str.maketrans("0123456789", "⁰¹²³⁴⁵⁶⁷⁸⁹")
atom = f"{1}{H}{1}".translate(SUP)
print(atom)

This is better than nothing, but I'd like both numbers to be in line, as they would usually be.

I know that unicode wizardry exists to create fractions. Is there either a python library, or a special unicode character which can do this for me?

Unicode is ideal, because I can rely on it working in my Django templates.

I'd like to be able to create this using unicode or similar, rather than relying on custom tags within the Django template.

Search terms such as 'composite superscript and subscript unicode' and similar have so far yielded nothing.

justajolt
  • 141
  • 11
  • 2
    in this post, I put how to use set up a template tag in my answer (look for EDIT... ) https://stackoverflow.com/questions/58889986/render-different-date-format-depending-on-time-that-passed-either-timesince-o/58890491#58890491 – ha-neul Nov 30 '20 at 17:04
  • I've upvoted both of your responses because they would have been suitable, were it not that I want to be able to pass in a string to my django template, rather than using custom template tags on the template itself. That's my fault, so you can both have an upvote. – justajolt Nov 30 '20 at 23:30
  • hey both comments are by me. I deleted one. It would be great if you can post your answer once you worked it out! – ha-neul Nov 30 '20 at 23:51

0 Answers0