How to print index with decreased font size?

Question:

I want to print equation on screen and print the indexes with decreased font size.

For example (i and i-1 have smaller font):

enter image description here

How can I do it ?

Asked By: user3668129

||

Answers:

You can use maketrans and translate

def get_sub(x):
    normal = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-=()"
    sub_s = "ₐ₈CDₑբGₕᵢⱼₖₗₘₙₒₚQᵣₛₜᵤᵥwₓᵧZₐ♭꜀ᑯₑբ₉ₕᵢⱼₖₗₘₙₒₚ૧ᵣₛₜᵤᵥwₓᵧ₂₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎"
    res = x.maketrans(''.join(normal), ''.join(sub_s))
    return x.translate(res)
  
# display subscript
print('A{} = A{} + 10'.format(get_sub('i'),get_sub('i-1')))

#output
Aᵢ = Aᵢ₋₁ + 10
Answered By: Talha Tayyab
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.