Superscript & Subscript
Convert text to Unicode superscript or subscript characters. Supports digits, letters, and common symbols.
Supported characters:
Digits 0-9: โฐยนยฒยณโดโตโถโทโธโน
์์ฃผ ๋ฌป๋ ์ง๋ฌธ
์ฝ๋ ๊ตฌํ
SUPERSCRIPT = str.maketrans(
"0123456789abcdefghijklmnoprstuvwxyzABDEGHIJKLMNOPRTUVW+-=()",
"โฐยนยฒยณโดโตโถโทโธโนแตแตแถแตแตแถ แตสฐโฑสฒแตหกแตโฟแตแตสณหขแตแตแตสทหฃสธแถปแดฌแดฎแดฐแดฑแดณแดดแดตแดถแดทแดธแดนแดบแดผแดพแดฟแตแตโฑฝแตโบโปโผโฝโพ"
)
SUBSCRIPT = str.maketrans(
"0123456789aehijklmnoprstx+-=()",
"โโโโโโ
โโโโโโโแตขโฑผโโโโโโแตฃโโโโโโโโ"
)
def to_superscript(text: str) -> str:
return text.translate(SUPERSCRIPT)
def to_subscript(text: str) -> str:
return text.translate(SUBSCRIPT)
print(to_superscript("x2 + y2 = r2")) # xยฒ + yยฒ = rยฒ
print(to_subscript("H2O")) # HโOComments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.