Is their a way to print W^{-1} in the console using println(“W…”)?
Is their a unicode character for it?
Is their a way to print W^{-1} in the console using println(“W…”)?
Is their a unicode character for it?
In Superscripts and Subscripts (Unicode block) - Wikipedia and Unicode subscripts and superscripts - Wikipedia they mention a superscript minus and a superscript 1, so you could do W⁻¹, here it looks a bit nicer in code W⁻¹
.
Thanks a lot! I copy and pasted what you wrote, and it works.
Is there a way to type this in the REPL without using copy and paste?
W\highminus<TAB>\^1<TAB>
see Unicode Input · The Julia Language
Easier: W\^-1<tab>
. If you copy-and-paste a symbol into the REPL help, it will tell you how to type it:
help?> W⁻¹
"W⁻¹" can be typed by W\^-1<tab>
If you need the output to be dynamic, you can use these functions I wrote a while ago.
julia> s = "W" * superscriptnumber(-1)
"W⁻¹"
julia> s = "W" * superscriptnumber(-3000)
"W⁻³⁰⁰⁰"
julia> ["W" * subscriptnumber(i) for i in 0:4]
5-element Vector{String}:
"W₀"
"W₁"
"W₂"
"W₃"
"W₄"
"""
subscriptnumber(i::Int) -> s::String
Returns the appropraite unicode string `s` for any numerical subscript `i`.
"""
function subscriptnumber(i::Int)
if i < 0
c = [Char(0x208B)]
else
c = []
end
for d in reverse(digits(abs(i)))
push!(c, Char(0x2080+d))
end
return join(c)
end
export subscriptnumber
"""
superscriptnumber(i::Int) -> s::String
Returns the appropraite unicode string `s` for any numerical superscript `i`.
"""
function superscriptnumber(i::Int)
if i < 0
c = [Char(0x207B)]
else
c = []
end
for d in reverse(digits(abs(i)))
if d == 0 push!(c, Char(0x2070)) end
if d == 1 push!(c, Char(0x00B9)) end
if d == 2 push!(c, Char(0x00B2)) end
if d == 3 push!(c, Char(0x00B3)) end
if d > 3 push!(c, Char(0x2070+d)) end
end
return join(c)
end
export superscriptnumber