Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latex-renderer throws an error due to width missing field when an equation outside of the visible range is conceal #1379

Open
2 tasks done
jonboh opened this issue Apr 4, 2024 · 1 comment
Labels
bug Issues related to bugs. Please attach a severity, a priority and category with this label.

Comments

@jonboh
Copy link

jonboh commented Apr 4, 2024

Prerequisites

  • I am using the latest stable release of Neovim
  • I am using the latest version of the plugin

Neovim Version

NVIM v0.10.0-dev-00e71d3 Build type: Release LuaJIT 2.1.1693350652

Neorg setup

require('neorg').setup({["load"] = {["core.concealer"] = { },["core.defaults"] = { },["core.dirman"] = {["config"] = {["workspaces"] = {["default"] = "~/doc/vault",["vault"] = "~/doc/vault"}}},["core.integrations.image"] = { },["core.integrations.telescope"] = { },["core.integrations.treesitter"] = { },["core.keybinds"] = {["config"] = {["hook"] = function(keybinds)
  --keybinds.unmap('norg', 'n', '<C-s>')

  keybinds.map(
    'norg',
    'n',
    '<localleader>o',
    ':Neorg return<CR>',
    {silent=true}
  )
  keybinds.map(
    'norg',
    'n',
    '<localleader>j',
    ':Neorg journal today<CR>',
    {silent=true}
  )
  keybinds.map(
    'norg',
    'n',
    '<localleader>c',
    ':Neorg toggle-concealer<CR>',
    {silent=true}
  )
  keybinds.map(
    'norg',
    'n',
    '<localleader><C-l>',
    ':Neorg render-latex<CR>',
    {silent=true}
  )
  keybinds.map(
    'norg',
    'n',
    '<localleader>f',
    ':Telescope neorg find_norg_files<CR>',
    {silent=true}
  )
  keybinds.map(
    'norg',
    'n',
    '<localleader>s',
    ':Telescope neorg find_linkable<CR>',
    {silent=true}
  )
  keybinds.map(
    'norg',
    'n',
    '<localleader>lf',
    ':Telescope neorg insert_file_link<CR>',
    {silent=true}
  )
  keybinds.map(
    'norg',
    'n',
    '<localleader>ls',
    ':Telescope neorg insert_link<CR>',
    {silent=true}
  )
end
}},["core.latex.renderer"] = {["config"] = {["bounded_geometry"] = false,["conceal"] = true,["dpi"] = 300,["render_on_enter"] = false}}}})

Actual behavior

When an equation is outside of the displayed lines of the buffer and you run Neorg render-latex, the latex-renderer will fail to conceal the equation because the image.rendered_geometry == {}, and so image.rendered_geometry.width will be nil, here's the relevant code.

Expected behavior

No error should be thrown.
This could be fixed by getting the width of the image in a different way that does not relay on the image being currently rendered.
A potential solution would be to not conceal equations when width==nil, however in that case the inline_math call should be added to the OnCursorMove event. Currently that change has an unacceptable performance hit.

Steps to reproduce

  $\min_\theta \mathbb{E} -\log p_\theta(x)$

  $\theta$ and $\tau$ and $\pi$ and $\gamma$ and $\epsilon$






  $\min_\theta \mathbb{E} -\log p_\theta(x)$

  $e^{i\pi} + 1 = 0$
  $a^2 + b^2 = c^2$
  $E = mc^2$
  $F = ma$
  $\hat{H}\psi = E\psi$
  $\nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0}$
  $\nabla \cdot \mathbf{B} = 0$
  $dS \geq \frac{dQ}{T}$
                          $\gamma = \frac{1}{\sqrt{1 - \frac{v^2}{c^2}}}$
  $(i\gamma^\mu\partial_\mu - m)\psi = 0$
  $\e$

<add as many lines as needed to push the upper equations outside of the display>

Potentially conflicting plugins

No response

Other information

No response

Help

None

Implementation help

In the branch I'm currently using in my fork I've removed this error, here's the fix, but it relays in the user continuously re-rendering the equations to get the concealment. I can confirm, that with that change the error no longer appears.

@jonboh jonboh added the bug Issues related to bugs. Please attach a severity, a priority and category with this label. label Apr 4, 2024
@jonboh
Copy link
Author

jonboh commented Apr 4, 2024

I'll try to test the change with the addition of render_inline_math inOnCursorMove with the changes that @benlubas has made to image.nvim to improved performance and see if that would be sufficient to solve the issue. In that case I'll send a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues related to bugs. Please attach a severity, a priority and category with this label.
Projects
None yet
Development

No branches or pull requests

1 participant