Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we convert an array of Unicode values back to it's text form in Julia?

I am learning Julia for my next project because the data really text-heavy and we are looking into making the code run more efficiently and fast. So as experimentation, I am learning Julia.

Now I learned that there is a really nice way to enter the Unicode characters in Julia. For example:

"⎔" can be made using "\hexagon"+tab

Is there a way to get back the textual version of these Unicode characters?

So what I am kind of asking is:

For each of these:

("⬙", "☽", "⎔", "⬟", "◁")

Can I get back:

("diamondbotblack", "rightmoon", "hexagon", "pentagonblack", "triangleleft")

Since we can't save them along with the \ like \pentagon because flags it as: syntax: invalid escape sequence, it's perfectly fine if I can get back an array of strings without \.

Anyone have any idea how to do it? I've already googled this and searched on Stackoverflow, posted in one of the forum too, didn't find any solution yet.

like image 911
Amit Amola Avatar asked Mar 02 '23 19:03

Amit Amola


1 Answers

You can use this:

using REPL
tmp_d = REPL.REPLCompletions.latex_symbols
mapping = Dict(values(tmp_d) .=> keys(tmp_d))

and now you can do:

julia> map(v -> mapping[v], ("⬙", "☽", "⎔", "⬟", "◁"))
("\\diamondbotblack", "\\rightmoon", "\\hexagon", "\\pentagonblack", "\\triangleleft")

I left the leading "\\", but you can remove it if you prefer.

like image 138
Bogumił Kamiński Avatar answered Apr 27 '23 21:04

Bogumił Kamiński