# Is there a package for printing integer as Unicode superscripts

**URL:** <https://discourse.julialang.org/t/is-there-a-package-for-printing-integer-as-unicode-superscripts/87505>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 20, 2022, 8:13am UTC](https://discourse.julialang.org/t/is-there-a-package-for-printing-integer-as-unicode-superscripts/87505 "2022-09-20T08:13:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 20, 2022, 8:13am UTC](https://discourse.julialang.org/t/is-there-a-package-for-printing-integer-as-unicode-superscripts/87505/1 "2022-09-20T08:13:01Z")

</div>

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

```julia
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).

---

<div class="post-metadata">

**Author:** ![Jollywatt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jollywatt/32/202198_2.png) [@Jollywatt](https://discourse.julialang.org/u/Jollywatt)\
**Post date:** [September 20, 2022, 8:26am UTC](https://discourse.julialang.org/t/is-there-a-package-for-printing-integer-as-unicode-superscripts/87505/2 "2022-09-20T08:26:09Z")

</div>

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

```julia
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))])

```
