Is there a package for printing integer as Unicode superscripts

I keep copy-pasting code for printing stuff like the digits in ℝ². It usually goes like

const _SUPERSCRIPT_DIGITS = ['⁰', '¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹']

function print_unicode_superscript(io::IO, k::Integer)
    @argcheck k > 0
    if k < 10
        print(io, _SUPERSCRIPT_DIGITS[k + 1])
    else
        for d in digits(l)
            print(io, _SUPERSCRIPT_DIGITS[d + 1])
        end
    end
end

The question is: I could not find a package that does this, wanted to check before packaging it up myself. Of course it could be extended a bit (subscripts, print to strings).

1 Like

Haha, I’m in the same boat! I keep reusing these lines:

const SUPERSCRIPT_DIGITS = collect("⁰¹²³⁴⁵⁶⁷⁸⁹")
const SUBSCRIPT_DIGITS   = collect("₀₁₂₃₄₅₆₇₈₉")
superscript(n::Integer) = join(SUPERSCRIPT_DIGITS[begin .+ reverse(digits(n))])
subscript(n::Integer)   = join(SUBSCRIPT_DIGITS[begin .+ reverse(digits(n))])
3 Likes