lervag / vimtex

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

inverse search not working WSL #2914

Closed 594212 closed 5 months ago

594212 commented 5 months ago

Description

I'm using nvim with wsl Ubuntu and inverse search not working. I already tried that you describe in others issues:

  1. Open ~/textest/main.tex with neovim.
  2. Open a terminal and go to the project root directory with cd.
  3. In neovim: Compile the project \ll . Sioyek opens, I can close it.
  4. In the terminal, run nvim --headless -c "VimtexInverseSearch 10 '~/textest/main.tex'", This should open the specified file at the specified line in neovim

It didn't work, cursor not moving.

plugins/vimtex.lua

return {
    "lervag/vimtex",
    lazy = false,
    init = function()
        -- Use init for configuration, don't use the more common "config".
        vim.g.vimtex_view_general_viewer = 'sioyek'
        vim.g.vimtex_callback_progpath = "C:\\Windows\\system32\\wsl.exe nvim"
    end
}

instruction above, was executed in wsl, so I think, vim.g.vimtex_callback_progpath dosn't matter, if is not working within wsl

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.4 LTS
  Vim version: NVIM v0.9.4
  Has clientserver: true
  Servername: /run/user/1000//nvim.135906.0

VimTeX project: main
  base: main.tex
  root: /home/sul/textest
  tex: /home/sul/textest/main.tex
  main parser: current file verified
  document class: article
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
    job: 
      jobid: 20
      output: /tmp/nvim.sul/myEqie/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"' 'main.tex'
      pid: 137601
  viewer: General
    job: 
      pid: -
      cmd: sioyek '/home/sul/textest/main.pdf'
  qf method: LaTeX logfile
lervag commented 5 months ago

I already tried that you describe in others issues:

  1. Open ~/textest/main.tex with neovim.
  2. Open a terminal and go to the project root directory with cd.
  3. In neovim: Compile the project \ll . Sioyek opens, I can close it.
  4. In the terminal, run nvim --headless -c "VimtexInverseSearch 10 '~/textest/main.tex'", This should open the specified file at the specified line in neovim

It didn't work, cursor not moving.

return {
    "lervag/vimtex",
    lazy = false,
    init = function()
        -- Use init for configuration, don't use the more common "config".
        vim.g.vimtex_view_general_viewer = 'sioyek'
        vim.g.vimtex_callback_progpath = "C:\\Windows\\system32\\wsl.exe nvim"
    end
}

You did not really read the docs well enough. Sioyek has its own configuration, so you should use this:

return {
    "lervag/vimtex",
    lazy = false,
    init = function()
        vim.g.vimtex_view_method = 'sioyek'
        -- vim.g.vimtex_callback_progpath = "C:\\Windows\\system32\\wsl.exe nvim"
        -- I believe you can simplify this to:
        vim.g.vimtex_callback_progpath = "wsl nvim"
    end
}

Please read :help vimtex-view-sioyek, as well as :help vimtex-faq-wsl for more info.

594212 commented 5 months ago

I'm sorry, I already tried that, while was trying figured out what's going I lost vim.g.vimtex_view_method = 'sioyek', first time I'm tried with this. sioyek opens on the correct line, but inverse search not working.

Just so you know, since you mentioned it, I tried again. However, it didn't work.

You did not really read the docs well enough

this line is hurt

also, If it is important, instead of adding sioyek.exe to %PATH I created symbol link to execution

/usr/bin/sioyek -> /mnt/c/Users/sul/AppData/Local/Microsoft/WinGet/Packages/ahrm.sioyek_Microsoft.Winget.Source_8wekyb3d8bbwe/sioyek-release-windows/sioyek.exe

so it is why I don't use vim.g.vimtex_view_sioyek_exe = 'sioyek.exe'

lervag commented 5 months ago

You did not really read the docs well enough

this line is hurt

Sorry, that was not my intent. Using the general viewer (vimtex_view_method = "general") instead of the specific (vimtex_view_method = "sioyek") indicated that you did not know that there is a specific one.

I'm sorry, I already tried that, while was trying figured out what's going I lost vim.g.vimtex_view_method = 'sioyek', first time I'm tried with this. sioyek opens on the correct line, but inverse search not working.

Ok, do I understand correctly that with this, forward search works as expected? Forward search will not work with vimtex_view_general_viewer = "sioyek", so this is an improvement.

Can you do :VimtexInfo again and report the viewer: part after you have opened a tex file and after the viewer has started? I want to see the viewer.job.cmd.

also, If it is important, instead of adding sioyek.exe to %PATH I created symbol link to execution

/usr/bin/sioyek -> /mnt/c/Users/sul/AppData/Local/Microsoft/WinGet/Packages/ahrm.sioyek_Microsoft.Winget.Source_8wekyb3d8bbwe/sioyek-release-windows/sioyek.exe

so it is why I don't use vim.g.vimtex_view_sioyek_exe = 'sioyek.exe'

Ok. So, first, I don't use Windows and I may not be able to help you here. But I'll try.

Now, it seems you are using neovim inside Ubuntu in WSL. And that Sioyek is installed on the Windows side of things. It also seems that this works well, except for the inverse search.

Now, I think the first step here is to check that the inverse search method works at all. Can you do this?

The third action should move your cursor in neovim in the first terminal to the specified file at the specified line. Can you test and let me know what happens?

594212 commented 5 months ago

Ok, do I understand correctly that with this, forward search works as expected? Forward search will not work with vimtex_view_general_viewer = "sioyek", so this is an improvement.

Year, when I used vimtex_view_general_viewer = "sioyek" is only opens sioyek but not in correct line, now with vimtex_view_method = "sioyek" it opens correctly on correct line

Can you do :VimtexInfo again and report the viewer: part after you have opened a tex file and after the viewer has started? I want to see the viewer.job.cmd.

viewer: sioyek
job: 
pid: 37876
cmd: sioyek.exe  --inverse-search "wsl nvim --headless -c \"VimtexInverseSearch %2 '%1'\"" --forward-search-file '/home/sul/textest/main.tex' --forward-search-line 15 '/home/sul/textest/main.pdf'
cmd_start: sioyek.exe  --inverse-search "wsl nvim --headless -c \"VimtexInverseSearch %2 '%1'\"" --forward-search-file '/home/sul/textest/main.tex' --forward-search-line 15 '/home/sul/textest/main.pdf'
qf method: LaTeX logfile

Now, I think the first step here is to check that the inverse search method works at all. Can you do this?

  • Open a terminal and cd textest, then nvim main.tex.
  • Start compilation (\ll), then close the viewer if it opens and restart neovim (:q then nvim main.tex).
  • Open a new terminal and cd textest, then:
  • nvim --headless -c "VimtexInverseSearch 10 '/home/sul/textest/main.tex'"

The third action should move your cursor in neovim in the first terminal to the specified file at the specified line. Can you test and let me know what happens?

it is a magic it jumped on correct line!!! also I tried wsl nvim --headless -c "VimtexInverseSearch 10 '/home/sul/textest/main.tex'" and it work.

Maybe I don't use keystroke correctly?

Press f4 to toggle synctex mode (toggle_synctex command). While in this mode, right clicking on any text opens the corresponding tex file in the appropriate location.

but is still not working

lervag commented 5 months ago

The third action should move your cursor in neovim in the first terminal to the specified file at the specified line. Can you test and let me know what happens?

it is a magic it jumped on correct line!!! also I tried wsl nvim --headless -c "VimtexInverseSearch 10 '/home/sul/textest/main.tex'" and it work.

Great, I'm glad to hear it.

Maybe I don't use keystroke correctly?

Press f4 to toggle synctex mode (toggle_synctex command). While in this mode, right clicking on any text opens the corresponding tex file in the appropriate location.

but is still not working

It seems you are doing things correctly. It's hard to say what is wrong here, to be honest. I don't use this system combination and I don't really know how to figure things out if I can't test it myself.

One thing you could try: There's an :execute command in Sioyek that you can use to execute shell commands. Can you perhaps test what happens if you do something like this:

594212 commented 5 months ago

One thing you could try: There's an :execute command in Sioyek that you can use to execute shell commands. >Can you perhaps test what happens if you do something like this:

  • :execute wsl echo "hello world" (does it print anything?)
  • :execute wsl nvim --headless -c "VimtexInverseSearch 10 '/home/sul/textest/main.tex'"

it worked, its jumped on correct line, what can be a problem

lervag commented 5 months ago

That's interesting. Another thing you can try is to start Sioyek yourself to specify the inverse search command. This way, we can check that it actually does something. Do this:

  1. Ensure that your test project is compiled and has the synctex file.
  2. cd textest
  3. sioyek.exe --inverse-search "wsl echo %2 %1 >> /home/sul/textest/test-sync.log" '/home/sul/textest/main.pdf'
  4. Use the synctex mode <f4>, right click in the document, and check if the test-sync.log file is created and received content.

So, here we simply change the inverse search command to output the line number and filename to a file test-sync.log. This is more or less as "basic" as we can go. If this doesn't work, then I really have no idea what's wrong.

Note, if this does not work, then you might have noticed that we really didn't use VimTeX this time - as such, it may be relevant to ask at the Sioyek repo (https://github.com/ahrm/sioyek).

594212 commented 5 months ago

file is created, but /home/sul/textest/test-sync.log

15 homesul  extestmain.tex
7 homesul   extestmain.tex
7 homesul   extestmain.tex
3 homesul   extestmain.tex

it writes wrong path, so apparently it related to sioyek not vimtex. Anyway, thank you, I really appreciate your help!

lervag commented 5 months ago

Huh; actually, it seems that it does output the correct path, except the string interprets the path seperators as escapes such that \t becomes a tab character. You could try to use ... "wsl echo %2 '%1' ....