Myriad-Dreamin / tinymist

Tinymist [ˈtaɪni mɪst] is an integrated language service for Typst [taɪpst].
https://myriad-dreamin.github.io/tinymist
Apache License 2.0
824 stars 35 forks source link

Add unicode input by symbol expansion #778

Open owiecc opened 2 weeks ago

owiecc commented 2 weeks ago

Motivation

It would be nice to be able to use the typst symbol input and be able to expand it to the corresponding glyph. This way equations like this: $ nabla dot.c E = rho / epsilon_0 $ can be converted to a simpler notation: $ ∇·E = ρ / ε_0 $. Both produce the same output but the latter is far more readable.

Description

Typing dot.c<TAB> converts the dot.c to · in the source document.

Examples/Questions

This is a similar idea to the way one can input symbols in Julia with completion.

I have proposed this feature to the, now deprecated, typst-lsp: https://github.com/nvarner/typst-lsp/issues/49 previously.

Relevant discussion on Julia discourse: https://discourse.julialang.org/t/unicode-autocomplete-howto/96752/2

Relevant typst extension: https://github.com/supersurviveur/typst-math

I am willing to set up a bounty for this feature.

Myriad-Dreamin commented 2 weeks ago

I have considered this feature again and again, but I have a few unsure things on it:

Therefore, insteadly I'm considering some other inline previewing that won't insert many such unicodes in text documents, such as inlay hints on equations, like the following screenshot:

image

What's your opinion about it?

owiecc commented 2 weeks ago

I think starting with manual expansion with a <TAB> and testing the possibility of automating it is the easiest way to implement it. Manual expansion has none of the drawback that you mentioned and people can choose when to use it. Nothing changes for current users, they will not even notice the change. Once implemented the auto-expansion can be implemented on top of it.

From my experience with Julia, the <TAB> is not that problematic. Adding one keystroke is not a lot when most symbol names in Typst have few to dozen characters. Remember that not all symbols need to be expanded. Maybe it is beneficial to expand only a few characters in key places to increase readability of an equation.

Enter-tainer commented 2 weeks ago

Maybe it is beneficial to expand only a few characters in key places to increase readability of an equation.

this might be a good idea. we may firstly adopt symbol list from typst-math extension

Eric-Song-Nop commented 2 weeks ago

I am not sure what are u really looking for? Is it more like an input method for unicode or an immediate renderer for a subset of math mode? If the first solution, as an ime, is what u need, it is a common pattern to implement this mode with an extra trigger. I believe in Julia or Lean or Agda extension, start with \ triggers such an ime, and we can begin with general symbols in typst.

Eric-Song-Nop commented 1 week ago

BTW, I also made a nvim-cmp source for this purpose: https://github.com/Eric-Song-Nop/cmp-typst-symbols