Coder Social home page Coder Social logo

nabla.nvim's Introduction

nabla.nvim

Take your scentific notes in Neovim.

The colorscheme used here is tokyonight.

An ASCII math generator from LaTeX equations.

Requirements

Install

Using vim-plug
Plug 'jbyuki/nabla.nvim'
Using packer.nvim
use 'jbyuki/nabla.nvim'
Using the built-in package manager
  • Create a folder pack/<a folder name of your choosing>/start

  • Inside the start folder git clone nabla.nvim

    • git clone https://github.com/jbyuki/nabla.nvim
  • In your init.lua, add the pack folder to packpath (see :help packpath)

    vim.o.packpath = vim.o.packpath .. ",<path to where pack/ is located>"
  • git pull in the plugin folder to update it. You want something more viable though, that's why package managers are useful.

Configuration

Bind the following command:

nnoremap <leader>p :lua require("nabla").popup()<CR> " Customize with popup({border = ...})  : `single` (default), `double`, `rounded`

See here for virt_lines support.

Usage

  • Press leader + p while the cursor is on a math expression to open floating menu

Reference

See test/input.txt for examples.

Note: If the notation you need is not present or there is a misaligned expression, feel free to open an Issue.

Credits

  • Thanks to jetrosut for his helpful feedback and bug troubleshoot.
  • Thanks to nbCloud91 for pointing me to VIM conceals.
  • Thanks to clstb for giving suggestions on how to enhance the interaction.
  • Thanks to aspeddro for adding preview popups.
  • Thanks to Areustle for adding more than 500 new symbols.
  • Thanks to kkharji for pointing out virt_lines.
  • Thanks to max397574 for a proper treesitter implementation.

Contribute

See here.

nabla.nvim's People

Contributors

areustle avatar aspeddro avatar beastwick18 avatar cochaviz avatar danickblouin avatar danie-1 avatar gaodean avatar jbyuki avatar josephhand avatar max397574 avatar xxiaoa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nabla.nvim's Issues

attempt to index global 'exp'

...nvim/site/pack/packer/opt/nabla.nvim/lua/nabla/ascii.lua:1262: attempt to index global 'exp' (a nil value)
this makes sense because that variable isn't defined anywhere
so this is a mistake made in the lua.t file or by ntangle
some exampels:
(H_A+x^x)+\sqrt{x}
\alpha_{\omega}(x)

Error: attempt to perform arithmetic on local 'srow' (a nil value)

Hi! I've just installed this plugin but I couldn't get it to work. When I pressed <leader>p, an error occurred. This was the error message:

E5108: Error executing lua ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:730: attempt to perform arithmetic on local 'srow' (a nil value)
stack traceback:
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:730: in function 'popup'
        [string ":lua"]:1: in main chunk

Expected behavior: An error doesn't occur
Actual behavior: An error occurred

Request for \choose syntax support

How should the input text representation look like

{5 \choose 3}

How should the ASCII art output look like

⎛ 5 ⎞
⎝ 3 ⎠

Describe in what context you would use this notation

Discrete Math, Probability, Counting, Statistics

Additional context
Given the design of the "choose" notation adding a third, middle row is also an option.

⎛ 5 ⎞
⎜   ⎟
⎝ 3 ⎠

unparsed equation

perhaps this is out of the scope of this plugin
...nvim/site/pack/packer/opt/nabla.nvim/lua/nabla/ascii.lua:1761: Unknown block expression aligned

\[
    \left[
    \begin{aligned}
        x &=p_x+t{\cdot}v_x\\
        y &=p_y+t{\cdot}v_y
    \end{aligned}
    \right]
\]

would give
Screenshot 2022-10-09 at 14 26 52

Request for in-latex text block support

How should the input text representation look like
\text{\# Of People Reading This}=1

How should the ASCII art output look like
# Of People Reading This=1

Describe in what context you would use this notation
Useful when previewing LaTeX in nvim before compiling to the final product.

Additional context
Right now the only thing displayed is text in place of the actual text block. Not sure if this is an option I have to turn off (was unable to find a list of config options) or just nabla doing its best to render an unknown \ command.

Unrecognized tags

If a tag is not recognized, it should output it out verbatim and not remove it.

For example

$x \gets y$

should output

x \gets y

Chemical Notation Support

Hey, thank you for the plugin, I have yet to find anything like nabla.nvim. I am trying to use Vim to take scientific notes, which often contain chemical and mathematical formulas.

Though, the plugin is quite primitive (naturally), so it doesn't really help me to take notes in Vim. See the image below where I am getting an error.

nablaerror

This is how it is supposed to be rendered:
notion

I have to add that the italic letters are of no significance, what's important is formulas like H_{12} to work.

function defined at wrong place

there is a function in nabla/ascii.lua which is called before it's defined
I only encountered that error when trying to implement treesitter though.
But it has nothing directly to do with treesitter.
it's an error in the code
It can be fixed like this:

diff --git a/lua/nabla/ascii.lua b/lua/nabla/ascii.lua
index f78ffd1..8dd34e2 100644
--- a/lua/nabla/ascii.lua
+++ b/lua/nabla/ascii.lua
@@ -7,6 +7,8 @@ local put_if_only_sub
 
 local put_if_only_sup
 
+local to_ascii
+
 
 local style = {
 	plus_sign = " + ",
@@ -1352,7 +1354,7 @@ function put_if_only_sup(exp, g)
   return g
 end
 
-local function to_ascii(exp)
+to_ascii=function(exp)
 	local g = grid:new()
 	if not exp then
 		print(debug.traceback())

Using with markdown in vimwiki

I am trying to use nabla.nvim in a md file. However, it keeps reporting expect a lua number line 482. Are there any solutions ?

image

Support for \left and \right

How should the input text representation look like

\left(\frac{x}{2}\right)^5

How should the ASCII art output look like

⎛x⎞⁵
⎜―⎟
⎝2⎠

Describe in what context you would use this notation
Basic math, especially when raising fractions to a power.

Additional context
The feature already exists to extend the parenthesis, LaTeX just uses \left and \right to do that so they show up as well as the parentheses like this:
2021-11-18-230127_891x244_scrot

Add support for `\mathbb{...}`

How should the input text representation look like

\mathbb(R), \mathbb(Z), ...

How should the ASCII art output look like

ℜ, ℕ, ...

Describe in what context you would use this notation

Mathematics

attempt to perform arithmetic on global 'forward' (a nil value)

Hey @jbyuki,

I'm using nabla after along time, I'm used to nabla.action to toggle the view. Now when I call it I get

...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:879: attempt to perform arithmetic on global 'forward' (a nil value)

Any ideas what may be causing this

Thanks

Error (`srow` nil) when requesting popup

E5108: Error executing lua ...smeer/.local/share/nvim/plugged/nabla.nvim/lua/nab
la.lua:730: attempt to perform arithmetic on local 'srow' (a nil value)
stack traceback:
        ...smeer/.local/share/nvim/plugged/nabla.nvim/lua/nabla.lua:730: in func
tion 'popup'
        [string ":lua"]:1: in main chunk

which seems to appear sometimes? In the examples it happens when I'm in the last column of a line delimited by $, and in general the error appears everywhere outside $ signs including equation environments

Quantifiers

How should the input text representation look like

\forall \exists \in \notin \subset \subseteq \supset \supseteq \cup \cap \setminus \R \N \Z \Q

How should the ASCII art output look like

∀ ∃ ∈ ∉ ⊂ ⊆ ⊃ ⊇ ∪ ∩ ∖ ℝ ℕ ℤ ℚ

Describe in what context you would use this notation

Mathematics

Quantifiers and set-related operators and symbols are often needed in all kinds of different mathematical fields when dealing with sets. There are other important related symbols, these ones just were the ones I tend to use most often right now. They don't require any special formatting but are impossible to type on almost all keyboard layouts, so a simple replacement when converting from LaTeX would be really helpful.

[Feature Request] Multiline expression support

When executing require("nabla").popup() on an markdown latex block:

$$
2 + 2 = 4
$$

I get:

E5108: Error executing lua: ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:643: bad argument #1 to 'len' (string expected,
stack traceback:
        [builtin:len]: in function 'len'
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:643: in function 'popup'
        [string "..."]: in function <[string "..."]:0>
Press ENTER or type command to continue

When executing require("nabla").popup() once nothing happens, after that I get:

E5108: Error executing lua: ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:505: Expected lua number
stack traceback:
        [C]: in function 'nvim_buf_get_extmarks'
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:505: in function 'edit_formula'
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:495: in function 'action'
        [string "..."]: in function <[string "..."]:0>

System Information

:version
NVIM v0.7.0-dev
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by nixbld

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/nix/store/cs0wi57nzwn6729rbfkqq2p4f4hc5qf5-neovim-unwrapped-master/share/nvim"

Run :checkhealth for more info

offset error?

it looks like there is an offset somewhere
when I got an equation in the format $x...$
it says empty expression detected when I'm on x but correctly displays the equation when I'm on the second $

attempt to concatenate field 'sym' (a nil value)

...nvim/site/pack/packer/opt/nabla.nvim/lua/nabla/ascii.lua:1723: attempt to concatenate field 'sym' (a nil value)
some equations where this error occurs:
\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}
\begin{matrix} x^2 & a_H \\ \frac{1}{2} & d^2 \end{matrix}
(from test file)
it seems to occur with every thing that uses pmatrix I'm quite (not 100% though) sure that it didn't occur with my pr before you made it be generated by ntangle

Bug: Fraction bar extends further than it should

Description of the issue
When writing fractions the bar separating the numerator and denominator is longer than it should be to cover the area between the two numbers.

Possible fixes
Use a different character for the fraction bar, or ensure that it does not overlap any other characters.

Additional Information
This may be an error on my end, see the following image for an example of the issue:
2021-11-18-225630_316x164_scrot
I am using the JetBrainsMono Nerd Font font for my terminal and neovim if that helps.

Support equation enviroment

For most of my notes I use the equation environment for numbered equations, etc. Would it be possible for nabla.nvim to support previewing math in an equation? I understand that parsing this could be messy so I'm thinking a good alternative would be to provide a method to preview a visual-selected region of text -- and then the user can map/bind that as they see fit, perhaps with vimtex textobjects or treesitter, etc.

Thanks for the great plugin! If there is a way I can help with this let me know.

request: Support multi-line formulas

I really like this plugin, and I wish I could use it more often. The problem is that although I use LaTeX a lot for typsetting mathematical notation, this is hardly ever done in .tex files. Most of the time it's in .md files, and more recently I've become interested in doing so for .norg files.

At first I thought this would be a feature I could implement in not too much time, but the literate programming style of the project has left me with no idea how to tackle the change I want to make. I did some research online on how this paradigm works, but I haven't found much that could help me, and the code structure doesn't feel intuitive to change to me. This may be a mix of ntangle.nvim not seeming to work for me (It doesn't detect the .t filetype, and seems to not work. There's also not a lot of documentation on how to set it up, so it may be all on me) and me feeling overwhelmed.

I just wanted to open up this issue to request for the feature I wanted: having the toggle_virt work in other filetypes. If implementing it is too much of a chore, I also wouldn't mind being pointed to someplace to better learn how to contribute.

If these types of issues are not permitted (It does not fit with the templates in the project), feel free to delete it.

Regardless, have a nice day.

Request for more vertical spacing support

How should the input text representation look like

f(x) = x^2\: +3x\: +2
f(x) = x^2\; +3x\; +2
f(x) = x^2\ +3x\ +2
f(x) = x^2\quad +3x\quad +2
f(x) = x^2\qquad +3x\qquad +2

How should the ASCII art output look like

f(x) = x^2    +3x   +2
f(x) = x^2     +3x     +2
f(x) = x^2      +3x      +2
f(x) = x^2       +3x       +2
f(x) = x^2        +3x        +2

(see https://de.overleaf.com/learn/latex/Spacing_in_math_mode)

Describe in what context you would use this notation
I use these pretty often because they make stuff look nicer when rendered, having the popup not show up just because they are in an equation blows.

popup immediately disappears

Title says pretty much everything. When i press the binding the popup window flashes for a fraction of a second and then disappears never to be seen again.

Trouble using nabla at the same time as vimwiki

I'm having trouble using nabla with vimwiki, i think it would be very helpfull if these two could work together because one organizes everything and makes it very handy and the other one lets me write my scientific formulas on my notes.

The problem im having is that when i open a file through vimwiki, the F5 doesn't convert the latex syntax into the ASCII formula.
If i try a couple of times it gives an error:
image

I don't know if this can be solved through the init.vim file, im pretty new with neovim.

Thanks in advance.

weird behavior of `virt_lines`

I have the example test file from the repo here
when I comment out everything except for the first three equations and :lua require"nabla".toggle_virt()
I get errors from #46, #47 and #48
when I delete the other equations I don't get problems
is it possible that the virt_lines don't recognize comments?

Math mode with `\( \)` and `\[ \]`

LaTeX math mode is entered using \( \) and \[ \], but I could only get the plugin to work inside $ $ and $$ $$. Also, is it possible to add the math display environments?

Keep getting "Unexpected lua number" in Neorg

Greetings,

I am trying to get this to work with Neorg but keep getting these errors no matter what equation:

E5108: Error executing lua ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:482: Expected lua number

My Neorg doc looks like this:

@document.meta
    title: index
    description:
    author: vm
    categories:
    created: 2021-09-30
    version: 0.1
@end


[Specification for Neorg](https://github.com/nvim-neorg/neorg/blob/main/docs/NFF-0.1-spec.md)

[test](:index:/book_o_everything)

* test
 ** test
  *** Tess

@code latex
  $ \frac{1}{n} $

  $ \left(1+\frac{1}{n}\right)^n $
@end

Any help is deeply appreciated :)

virt_lines support

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.
Works as expected with the new treesitter support.

Options:

require"nabla".enable_virt({
  autogen = true, -- auto-regenerate ASCII art when exiting insert mode
  silent = true,     -- silents error messages
})

TODO:

  • : colorization
  • : disable/enable virt_lines when switching mode insert/normal
  • : support inline conceal as well, so that the preview is not shifted upwards.
  • : virt_lines above and below for the best centering.
  • : multi line

No popup

Tried disabling all plugings except TS and nabla.
I've tried multiple maps, aswel as just writing ":lua require("nabla").popup()" in command mode.
Latex parser is installed.
Canot get any feedback at all.
NVIM 0.7.2

attempt to compare nil with number

...nvim/site/pack/packer/opt/nabla.nvim/lua/nabla/ascii.lua:1423: attempt to compare nil with number
examples:
\sqrt{\frac{1}{2}
\frac{1}{2\xi \sqrt{1+\xi^2}}

Nabla not respecting indention as I would like.

Greetings, I finally got Nabla to work with Neorg (by giving up and coming back to it the next day :p) and have been loving your plugin. I noticed that Nabla doesn't factor in indention outside the first line. I get this isn't a huge issue, especially if you aren't using Neorg or Vimwiki, but I feel like it would be a nice level of polish.
Nabla1
Nabla2

Add support for \mathcal{...}

How should the input text representation look like

Example: \mathcal{F} \mathcal{L}

How should the ASCII art output look like

Example: 𝓕 𝓛

Describe in what context you would use this notation
Symbols I often need to write for notes on eg. lectures.

Example: Fourier or Laplace transform symbol as \mathcal{F} and \mathcal{L}

Additional context
An alternative is to add the \mathscr notation from the mathrsfs package.

Add dots

How should the input text representation look like

$$ T^{i_1 i_2 \dots i_p}_{j_1 j_2 \dots j_q} = T(x^{i_1},\dots,x^{i_p},e_{j_1},\dots,e_{j_q}) $$

How should the ASCII art output look like


   i₁i₂...iₚ  ⎛ i₁      iₚ            ⎞
  T         =T⎜x  ,...,x  ,e  ,...,e  ⎟
   j₁j₂...j   ⎜             j₁      j ⎟
           q  ⎝                      q⎠


Describe in what context you would use this notation
Math

Documentation For Addding Support

Hey! I think it would help you a lot if you gave us documentation on how to add support for certain latex symbols/equations so you don't have to create everything and people can quickly get up and started in contributing.

I'd be more than happy to contribute some symbols. If it's not tedious enough, having that documentation would be awesome!

Support doxygen math blocks

How should the input text representation look like

$\int_0^x y \sin(y) dy $

\f$ \int_0^x y \sin(y) dy \f$

How should the ASCII art output look like

x
∫ ysin(y)dy
0

x
∫ ysin(y)dy
0

Detecting or ignoring doxygen math block would be helpful for documenting source code.

Now, if accidentally trigger plugin on doxygen math block it tries to render all doxygen math blocks in document (and obviously fails.

https://www.doxygen.nl/manual/formulas.html

Vector Support

Hi @jbyuki , is it possible to support vector notation?

Examples
$\vec{p}$
$\overrightarrow{AB}$

Running nabla two times results in cryptic error

  1. Write latex equation
  2. Run :lua require("nabla").place_inline()
  3. Run it again

E5108: Error executing lua ...clstb/.local/share/nvim/plugged/nabla.nvim/lua/nabla.lua:257: bad argument #1 to 'len' (string expected, got nil)

Tried with this latex \frac{ 1 - \sum_{l \leq k+n} (1-p)^{l-1}p }{ 1 - \sum_{l \leq k} (1-p)^{l-1}p }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.