Home > Net >  How to print index with decreased font size?
How to print index with decreased font size?

Time:12-12

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 ?

CodePudding user response:

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
  • Related