Autocompletion for existing latex symbols

Hello everyone,

I’m not sure, if this is the right category and if the system already exists but I would find it amazing if the Auto-Complete would also consider the latex name of symbol. For example, in case you have a code file containing latex symbols like

α = 2

then it would be super convenient, if you type ‘alpha’ it would recognize it as the symbol defined earlier.
Does anyone know, if this is already possible with an add-on or does it require changes to the Julia language server? I think it would definitely be a nice feature that could save a lot of time and boost the usage of unicode-latex symbols.

You get auto-complete of these symbols by using the \ prefix, for example \al + TAB will propose \aleph, \allequal, \alpha. Writing \alpha + TAB will replace it with the Unicode symbol. See the documentation for details.

Do you have something else in mind?

1 Like

Yes, I’m referring to the autocomplete of the code editor for already defined symbols in the current scope. E.g. if I define something

theta_0 = ...
θ₀ = ...

and I want to reference it some lines later. In VS-Code, if start typing the, it would show me theta_0 in the autocompletion list but not θ₀. Even if I type \the it would not show me θ₀.

So, at the moment the only way to write θ₀ is to retype \theta TAB \zero TAB all over again, every time that variable is used (or copy paste a lot). Therefore in my scripts I stopped using latex/unicode and switched back to theta_0 because of the autocompletion. But I would love to switch back unicode, because I think it is such a nice idea to have it.

I guess this would require some changes to the Language Server of Julia (not sure about that though) so that θ₀ is matched by the sequence theta_zero or theta_0.

How do you handle these problems? Does it work for others or in other editors?

3 Likes

Ah I see, yes that could be nice to have… Note that completion already works on Unicode symbols:

julia> θᵝ₃ = 2
2

julia> θ # Pressing TAB here will complete θᵝ₃

so what you’re asking is just to match \theta when the user completes the for example?

3 Likes

Oh thats nice, I didn’t know that this is possible. Does it also work in VS-Code (for me it only worked in the REPL)

Yes exactly. If have a defined variable name θᵝ₃ and I type theta (or the or thet and so on) I would love to see the suggestion θᵝ₃ in the autocomplete overlay. I’m not sure if it is possible at the moment.

The unicode name should autocomplete fine when you have part of the identifier typed
image

It might be possible to trigger the same autocompletions when typing theta, I’ll look into that.

5 Likes

Any change this could work in julia-vim? Another related improvement would be to be able to write, for instance

\theta^\beta_3 TAB

or

\theta_{123} TAB

to get θᵝ₃ and θ₁₂₃

meaning, to have a more sophisticated latex-to-unicode translation. This site, for example, does that quite well, maybe it may provide some inspiration.

3 Likes

Thanks!

Please let me know, if you find something. I’m fairly new to Julia but would love to learn more about it and also maybe helping implementing it (if it is a new feature and others consider it useful too). However I wanted to ask here, if someone knows more about it before posting issues to the vs-code extension or LanguageServer.jl repositories.

This seems like a wanderfull feature. However, I do agree that you’ll still have to type the backslashes for the autocomplete to work. E.g, the TAB should not autocomplete, but \th TAB should.

I also agree that the latex-to-unicode could be more greedy, e g \theta_\bet TAB should autocomplete at once, even if \beta is not completely written.