9

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?

a06e
  • 18,594
  • 33
  • 93
  • 169
  • 7
    Unfortunately, not all ASCII characters exist as unicode sub- or super-scripts, so in general this won't work. Notably missing are superscript `CFQSXYZq` and all subscript capital letters, along with subscript `bcdfgqwyz`. Don't ask me why the unicode consortium decided `Fₓ` should work but not `Fy` or `Fz`. Crazy unicode. https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts#Other_superscript_and_subscript_characters – mbauman Apr 01 '16 at 15:14
  • @MattB. Maybe they could only chose a limited number of characters, and thus had to drop some deemed less useful, such as subscript y. Anyway, what I want is to put several *of the supported characters* in the subscript. – a06e Apr 01 '16 at 15:23
  • `x_max` doesn't seem *that* bad. – Imanol Luengo Apr 01 '16 at 15:33
  • @imaluengo You could say the same of `x\_1` ... it's just cooler ;) – a06e Apr 01 '16 at 15:35
  • 2
    @becko: my understanding is that it was actually a willful refusal to have a complete set lest people begin to use this as a markup mechanism. Which, of course, begs the question of why have any at all? – StefanKarpinski Apr 01 '16 at 15:39
  • @MattB. you should just post your comment as an answer. – StefanKarpinski Apr 01 '16 at 15:40
  • “Which, of course, begs the question [...]” — Latin-1 has some superscript characters, so Pandora's Box had to be opened for Latin-1 compatibility if nothing else. – Guildenstern Sep 23 '16 at 17:02

2 Answers2

13

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.

mbauman
  • 30,958
  • 4
  • 88
  • 123
  • 4
    I think it's not ambiguous. `ₚₕᵢ` is `\_phi`, and `ᵩ` should be `\_\phi` – a06e Apr 01 '16 at 15:55
  • Can this sort of definition be part of a script, rather than in a ``.juliarc.jl`` file and run each time, to ensure portability of the code across machines and sharing across users? Thanks. – PatrickT Jun 01 '17 at 04:06
  • https://stackoverflow.com/a/17909597/565879 It seems not all characters can be used as subscripts. This is a Unicode limitation, not a Julia limitation. See also: https://stackoverflow.com/questions/6613197/utf8-symbols-for-subscript-letters – Buttons840 Jan 25 '20 at 20:28
3

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ᵐᵃˣ.