Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subscript multiple characters in Julia variable name?

Tags:

unicode

julia

I can write:

x\_m<TAB> = 5

to get x subscript m as a variable name in Julia. What if I want to subscript a word instead of a single character? This

x\_max<TAB> = 5

doesn't work. However,

x\_m<TAB>\_a<TAB>\_x<TAB> = 5

does work, it's just very uncomfortable. Is there a better way?

like image 481
becko Avatar asked Apr 01 '16 13:04

becko


Video Answer


2 Answers

As I noted in my comment, not all ASCII characters exist as unicode super- or sub-scripts. In addition, another difficulty in generalizing this tab completion will be determining what \_phi<TAB> should mean: is it ₚₕᵢ or ? Finally, I'll note that since these characters are cobbled together from different ranges for different uses they look pretty terrible when used together.

A simple hack to support common words you use would be to add them piecemeal to the Base.REPLCompletions.latex_symbols dictionary:

Base.REPLCompletions.latex_symbols["\\_max"] = "ₘₐₓ"
Base.REPLCompletions.latex_symbols["\\_min"] = "ₘᵢₙ"

You can put these additions in your .juliarc.jl file to load them every time on startup. While it may be possible to get a comprehensive solution, it'll take much more work.

like image 122
mbauman Avatar answered Sep 17 '22 15:09

mbauman


Since Julia 1.6 this works for subscripts (\_) and superscripts(\^) in the Julia REPL.

x\_maxTAB will print out like this: xₘₐₓ.

x\^maxTAB will print out like this: xᵐᵃˣ.

like image 32
Brian Guenter Avatar answered Sep 20 '22 15:09

Brian Guenter