lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.51k stars 389 forks source link

VimtexInverseSearch crashes LunarVim #2863

Closed karmatothex closed 9 months ago

karmatothex commented 9 months ago

Description

So, I'm currently trying to set up vimtex forwardsearch and inversesearch with Zathura. Forwardsearch works like a charm, while inversesearch does not. To narrow down the problem I reinstalled LunarVim, this is my current config:

vim.g['vimtex_view_method'] = 'zathura'
vim.g['vimtex_view_general_viewer'] = 'zathura'

lvim.plugins = {
        {
            "lervag/vimtex",
            config = function()
                vim.cmd("call vimtex#init()")
            end,
        },
}

Since the inversesearch from Zathura to Lunarvim (ctrl + click on a line in the PDF) does not work, I tried this Zathura command: zathura -l debug -x "/usr/bin/nvim/bin/nvim --headless -c \"VimtexInverseSearch %{line} '%{input}'\"" --synctex-forward 1:9:'/home/max/LaTeX/hello_world.tex' 'hello_world.pdf'& which opens the PDF at the desired line. When I try to invoke the inversesearch using ctrl click in the PDF, I get this error:

    Error detected while processing command line:
    E492: Not an editor command: VimtexInverseSearch 23 '/home/max/LaTeX/./hello_world.tex'

So there seems to be an issue with VimtexInverseSearch. When I open the .tex file using lvim hello_world.tex and then run :VimtexInverseSearch 10 hello_world.tex LunarVim instantly shuts down.

Steps to reproduce

No response

Expected behavior

No response

Actual behavior

No response

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: Ubuntu 22.04 LTS
  Vim version: NVIM v0.9.5
  Has clientserver: true
  Servername: /run/user/1000/lvim.15237.0

VimTeX project: hello_world
  base: hello_world.tex
  root: /home/max/test/LaTeX
  tex: /home/max/test/LaTeX/hello_world.tex
  main parser: fallback current file
  document class: scrartcl
  packages: epstopdf-base footmisc graphics graphicx inputenc keyval scrbase scrkbase scrlfile scrlfile-hook scrlogo tocbasic trig typearea xcolor
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
    job: 
      jobid: 7
      output: /tmp/lvim.max/a8Bngk/0
      cmd: max_print_line=2000 latexmk -verbose -file-line-error -synctex=1 -interaction=nonstopmode  -pdf -pvc -pvctimeout- -view=none -e '$compiling_cmd = ($compiling_cmd ? $compiling_cmd . " ; " : "") . "echo vimtex_compiler_callback_compiling"' -e '$success_cmd = ($success_cmd ? $success_cmd . " ; " : "") . "echo vimtex_compiler_callback_success"' -e '$failure_cmd = ($failure_cmd ? $failure_cmd . " ; " : "") . "echo vimtex_compiler_callback_failure"' 'hello_world.tex'
      pid: 15249
  viewer: Zathura
    xwin id: 0
    cmd_start: zathura  -x "/usr/bin/nvim/bin/nvim --headless -c \"VimtexInverseSearch %{line} '%{input}'\"" --synctex-forward 1:1:'/home/max/test/LaTeX/hello_world.tex' 'hello_world.pdf'&
  qf method: LaTeX logfile
clason commented 9 months ago

Do not lazy-load VimTeX (at all); this will prevent it from working and is not necessary (it lazy-loads itself, as plugins should).

karmatothex commented 9 months ago

Lunarvim uses folke/lazy.nvim. Is there any setting I could use, so vimtex it not lazy loaded?

clason commented 9 months ago

I cannot give advice on Lunarvim (except don't use it). If you use lazy.nvim itself, you should consult the docs.

lervag commented 9 months ago

So, I'm currently trying to set up vimtex forwardsearch and inversesearch with Zathura. Forwardsearch works like a charm, while inversesearch does not.

The common reason for this is that people lazy load VimTeX. It is quite easy to check this. If you open Neovim from a terminal with nvim, it should show an empty buffer (or a start buffer). Can you do :VimtexInverseSearch now? If not, then you are lazy loading VimTeX.

Another way to check: Run :scriptnames after starting neovim. If you don't find any vimtex scripts, you are lazy loading.

this is my current config: …

You should NOT use vim.cmd("call vimtex#init()")!!!!!!

Try this:

lvim.plugins = {
  {
    "lervag/vimtex",
    lazy = false,
    init = function()
      vim.g.vimtex_view_method = 'zathura'
    end,
  },
}

Notice that we specify to not lazy load and that configuration is added in the init function. Also, you don't need to set vimtex_view_general_viewer.

    Error detected while processing command line:
    E492: Not an editor command: VimtexInverseSearch 23 '/home/max/LaTeX/./hello_world.tex'

That indicates that you are lazy loading stuff.

So there seems to be an issue with VimtexInverseSearch. When I open the .tex file using lvim hello_world.tex and then run :VimtexInverseSearch 10 hello_world.tex LunarVim instantly shuts down.

That is expected. You should not use :VimtexInverseSearch yourself unless you know what you are doing. :)

karmatothex commented 9 months ago

Thank you for the detailed answer.

I have adjusted my config as you suggested

lvim.plugins = {
  {
    "lervag/vimtex",
    lazy = false,
    init = function()
      vim.g.vimtex_view_method = 'zathura'
    end,
  },
}

Unfortunately, the behavior is still the same. Forwardsearch works just fine, inversesearch not.

Also, when I run :scriptnames after starting neovim I get this: image

There are some vimtex scripts, but probably not all?

It looks to me as if the lazy=false option is not working. Maybe this is a specific Lunarvim problem. I also have an issue open here Issue #4455/LunarVim but have not yet received any feedback.

lervag commented 9 months ago

What happens if you run /usr/bin/nvim/bin/nvim in a terminal? Do you get your expected lunarvim version of neovim running with your config?

karmatothex commented 9 months ago

What happens if you run /usr/bin/nvim/bin/nvim in a terminal? Do you get your expected lunarvim version of neovim running with your config?

No, this will open vanilla neovim. To run LunarVim I have to use the lvim command.

I was able to fix my issue by switching to LazyVim and using the vimtex settings that you recommended. Thank you for your help, I really appreciate it!

lervag commented 9 months ago

What happens if you run /usr/bin/nvim/bin/nvim in a terminal? Do you get your expected lunarvim version of neovim running with your config?

No, this will open vanilla neovim. To run LunarVim I have to use the lvim command.

Ok! In this case, you have to set the g:vimtex_callback_progpath variable to lvim or to the full path (found e.g. by which lvim in a terminal).

I was able to fix my issue by switching to LazyVim and using the vimtex settings that you recommended. Thank you for your help, I really appreciate it!

Glad to hear it!

estrac commented 8 months ago

Thank you so much @lervag! I had exactly the same problem in LunarVim and setting vim.g:vimtex_callback_progpath to the full path to lvim solved my issue.

I'll note that lazy loading was not the problem (using the "standard" way to load plugins worked fine in LunarVim).

Finally, I'll add that I'm running Wayland, so I also needed to set vim.g.vimtex_view_method = "zathura_simple"

lervag commented 8 months ago

Thank you so much @lervag! I had exactly the same problem in LunarVim and setting vim.g:vimtex_callback_progpath to the full path to lvim solved my issue.

Great, glad to hear it! If there's a LunarVim wiki or something similar where people share things related to configuring plugins in LunarVim, perhaps this is relevant stuff to add there?

I'll note that lazy loading was not the problem (using the "standard" way to load plugins worked fine in LunarVim).

Lazy loading will break inverse search. And lazy loading of VimTeX does not really bring any significant benefit, so please, just don't do that.

Finally, I'll add that I'm running Wayland, so I also needed to set vim.g.vimtex_view_method = "zathura_simple"

👍🏻

estrac commented 8 months ago

I just created a pull request in LunarVim to add the vimtex inverse search capability to the starter.lvim file for LaTeX (I believe this is the closest to a wiki for LunarVim LaTeX).