nabla.nvim icon indicating copy to clipboard operation
nabla.nvim copied to clipboard

virt_lines support

Open jbyuki opened this issue 3 years ago • 13 comments

virt_lines poc

image

requires nvim 0.8.0+

A safe way to get inline visualization. The implementation is currently very simplistic. Enable with:

require"nabla".enable_virt()

Disable with:

require"nabla".disable_virt()

Note: enable_virt only supports the inline syntax which is $ .. $. Currently $$ .. $$ will likely throw an error.

TODO:

  • [x] : colorization
  • [ ] : update the annotations as you type
  • [x] : support inline conceal as well, so that the preview is not shifted upwards.

jbyuki avatar Aug 10 '22 21:08 jbyuki

Nice @jbyuki well done. I wonder if it would be possible to hide $..$ in like normal mode so the buffer will be more readable.

kkharji avatar Aug 11 '22 09:08 kkharji

Conceal is added.

jbyuki avatar Aug 13 '22 00:08 jbyuki

Great @jbyuki will try it out in few days. Thanks.

kkharji avatar Aug 13 '22 00:08 kkharji

I had to chance to interact with math equation. Does the conceal only hides $? if so, sorry I mean't hiding everything between $.

Also it seems I need to call require"nabla".enable_virt() each time I introduce new changes. Maybe on switch to normal mode it could be called automatically?

kkharji avatar Aug 13 '22 02:08 kkharji

I'm not the brightest, yes it makes more sense. Only hiding the $ will not make any difference...

New commits completely hides the equation. But still some work need to be for alignment.

Yes, we could add an autocommand which disable & enable nabla everytime the user enters normal mode.

jbyuki avatar Aug 13 '22 08:08 jbyuki

🤣Not true, happens to the best of us.

image

So this is a quick test of a previous file I shared with current state.

https://gist.github.com/kkharji/39bf5e931534e45a3b7b6ed2ec478273

It seems to ignore spaces between latex element, mathbb key, unable to handle multiple $..$ at the same line and causing crazy amount of space, I'm guessing because the virtual position is relative and only account for $..$ block

kkharji avatar Aug 13 '22 09:08 kkharji

Yeah, the code was just full of bugs. The alignement should now be correct. I'm not collapsing the formulas into a single character because otherwise we get issues with long warping lines and alignement of formulas.

jbyuki avatar Aug 15 '22 21:08 jbyuki

Would it be possible to add toggle_virt() or virt_enabled status flag? The latter would allow for conditional mappings akin to "show popup or refresh virtual text".

Slotos avatar Aug 17 '22 08:08 Slotos

It's added. toggle_virt() and is_virt_enabled().

jbyuki avatar Aug 17 '22 19:08 jbyuki

Im getting

E5108: Error executing lua /Users/skreli/.config/nvim/plugged/nabla.nvim/lua/nabla.lua:140: atte mpt to index local 'g' (a nil value)

andreasusc avatar Sep 07 '22 06:09 andreasusc

@andreasusc

This is not normal. This indicates that the ascii generation failed but it should output an error instead. Could you tell what input/buffer content you used?

jbyuki avatar Sep 07 '22 08:09 jbyuki

Hi, I'm getting the error above as well, seems like single-line expressions are causing the issue.

$$1$$
...
E5108: Error executing lua ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:140: attempt to index local 'g' (a nil value)
stack traceback:
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:140: in function 'colorize_virt'
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:474: in function 'enable_virt'
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:571: in function 'toggle_virt'
        [string ":lua"]:1: in main chunk

The above content will trigger the error on calling :lua require("nabla").toggle_virt(). On changing to inline expressions the error does not occur.

A similar error is triggered on popup():

$$1$$
...
E5108: Error executing lua ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:51: attempt to index local 'g' (a nil value)
stack traceback:
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:51: in function 'colorize'
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:380: in function 'popup'
        [string ":lua"]:1: in main chunk

however still displays the popup with nil as content

image

Hope this helps 😃

samuzora avatar Sep 08 '22 13:09 samuzora

Actually for enable_virt(), it only supports the inline syntax which is $ .. $. I should be more clear about that.

EDIT: I will push a fix for that shortly.

jbyuki avatar Sep 08 '22 14:09 jbyuki

https://gist.github.com/kkharji/39bf5e931534e45a3b7b6ed2ec478273

Hey. Thanks for this nice implementation. There were some typos in the file in the gist. I have fixed them and uploaded an edited version here: https://gist.github.com/krishnakumarg1984/9d311585d96d5f834f200d4163749bc8

krishnakumarg1984 avatar Oct 06 '22 11:10 krishnakumarg1984

would it be possible to ignore $$$$ or [ ] instead of erroring? so if you have a document which has both $$ and the other ones you could use virt_lines for the things which are supported yet?

max397574 avatar Oct 08 '22 11:10 max397574

How to remove spaces to align left?

adoyle-h avatar Oct 24 '22 16:10 adoyle-h

@adoyle-h I have changed the defaults to align left. It's still possible to align in the center with enable_virt({align_center=true}).

jbyuki avatar Oct 25 '22 10:10 jbyuki

@jbyuki LGTM. Thank you. 👍

adoyle-h avatar Oct 25 '22 11:10 adoyle-h

Good day :)

Whenever I use toggle_virt() to enable virt_lines the document automatically reset to nowrap. Is this the intended behavior? If not, are there any configs to turn it off?

ngvt1n avatar Sep 14 '23 09:09 ngvt1n