General subscripts in symbols?

I was just playing around with subscripts in symbol names:

Δx₂ = 123

It’s cool that you can do this, but I’m restricted to Unicode it seems.

I’m curious, is there a way to write a general subscript? Like the way you can in HTML:

foo<sub>123</sub>

Some kind of delimiters in the symbol name, which would disappear when rendered in an editor?

I’m new to Julia and not saying it should be this way. Just wondering.

1 Like

Julia source code is encoded in UTF-8, so only Unicode characters are supported. There’s no markup language layer on top of the raw unicode characters. If we had this, most text editors wouldn’t be able to render Julia source code!

Most letters and numbers are available as unicode subscript characters, so in this particular case you can just write foo₁₂₃.

This needs to be typed as foo\_1<TAB>\_2<TAB>\_3<TAB> though, which is quite inconvenient.

Actually with this in mind it would be a cool extension to the Julia REPL to allow a tab completion of this identifier as the latex-like foo\_{123}<TAB>. (If this was in the main REPL, the various editor plugins would also probably support it fairly quickly.)

1 Like

Some people want to propose a change to unicode for arbitrary sub/superscripts but I haven’t seen progress on it.

https://github.com/stevengj/subsuper-proposal

1 Like

Haha, I started looking at implementing this, but it turns out it’s already done and available in Julia 1.6!

1 Like

exactly:

help?> foo₁₂₃
"foo₁₂₃" can be typed by foo\_123<tab>
1 Like