lervag / vimtex

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

VimtexInverseSearch can be run but doesn't do anything #2918

Closed MrRedCrack closed 3 months ago

MrRedCrack commented 3 months ago

Description

Hi, I'm new to nvim, just trying to transition from VSCode to nvim for latex writing.

Based on a fresh kickstart.nvim configuration, I added a vimtex.lua to the plugins folder to load vimtex with its settings:

return {
  {
    'lervag/vimtex',
    lazy = false,
    init = function()
      -- Use init for configuration, don't use the more common "config".
      vim.cmd [[
" This is necessary for VimTeX to load properly. The "indent" is optional.
" Note that most plugin managers will do this automatically.
filetype plugin indent on

" This enables Vim's and neovim's syntax-related features. Without this, some
" VimTeX features will not work (see ":help vimtex-requirements" for more
" info).
syntax enable

" Viewer options: One may configure the viewer either by specifying a built-in
" viewer method:

" Or with a generic interface:

" VimTeX uses latexmk as the default compiler backend. If you use it, which is
" strongly recommended, you probably don't need to configure anything. If you
" want another compiler backend, you can change it as follows. The list of
" supported backends and further explanation is provided in the documentation,
" see ":help vimtex-compiler".
let g:vimtex_compiler_method = 'latexmk'

" Most VimTeX mappings rely on localleader and this can be changed with the
" following line. The default is usually fine and is the symbol "\".
" let maplocalleader = ","
" settings for sumatraPDF
let g:vimtex_quickfix_open_on_warning = 0
let g:vimtex_compiler_latexmk = {
        \ 'aux_dir' : 'latexmk_aux',
        \ 'out_dir' : '',
        \ 'callback' : 1,
        \ 'continuous' : 1,
        \ 'executable' : 'latexmk',
        \ 'hooks' : [],
        \ 'options' : [
        \   '-pdflua',
        \   '-verbose',
        \   '-file-line-error',
        \   '-synctex=1',
        \   '-interaction=nonstopmode',
        \   '-shell-escape',
        \   '-f',
        \   '-cd',
        \ ],
        \}
let g:vimtex_compiler_latexmk_engines = {
        \ '_'                : '-lualatex',
        \ 'pdfdvi'           : '-pdfdvi',
        \ 'pdfps'            : '-pdfps',
        \ 'pdflatex'         : '-pdf',
        \ 'luatex'           : '-lualatex',
        \ 'lualatex'         : '-lualatex',
        \ 'xelatex'          : '-xelatex',
        \ 'context (pdftex)' : '-pdf -pdflatex=texexec',
        \ 'context (luatex)' : '-pdf -pdflatex=context',
        \ 'context (xetex)'  : '-pdf -pdflatex=''texexec --xtx''',
        \}
      ]]
    end,
  },
}

I've successfully compiled an existing latex project and able to forward search just fine even from sub .tex files using SumatraPDF as the viewer, but I cannot perform any inverse search by double clicking the document, after adding the option in Sumatra as instructed: cmd /c start /min "" nvim --headless -c "VimtexInverseSearch %l '%f'" whenever I double click the document a cmd window briefly pops up and disappears.

Then I tried to manually run the VimtexInverseSearch command from powershell, and then from within nvim. Both instantly quits nvim no matter what options i pass to the command. I don't know how to continue troubleshooting from this point.

I've looked this up and found a lot of people fixed the issue by adding the lazy = false option to not lazy load the plugin, but that is not the case for me.

Inverse search has always worked just fine in VSCode, so I don't think it should be a problem with the .tex project, so I haven't tried with a minimal test file.

Steps to reproduce

  1. compile a latex project with <leader>ll
  2. from the SumatraPDF viewer spawned by the compilation, double click a spot in the document
  3. cmd window briefly spawns then disappears, nothing changes

Expected behavior

No response

Actual behavior

No response

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: DESKTOP-P4NHS39 (Microsoft Windows 11 Pro)
  Vim version: NVIM v0.9.5
  Has clientserver: true
  Servername: \\.\pipe\nvim.15092.0

VimTeX project: dsd
  base: dsd.tex
  root: C:\Users\happy\Desktop\latex\ltxDSD
  tex: C:\Users\happy\Desktop\latex\ltxDSD/dsd.tex
  main parser: current file verified
  document class: article
  packages: acronym amsbsy amsgen amsmath amsopn amstext appendix array atbegshi-ltx atveryend-ltx auxhook babel biblatex bigintcalc bitset blx-case-expl3 booktabs calc caption caption3 catchfile centernot circuitikz comment datetime2 enumitem epstopdf-base eso-pic etexcmds etoolbox expl3 fancyhdr fancyvrb float fontenc fontspec fontspec-luatex framed fvextra geometry gettitlestring graphics graphicx hycolor hyperref hyphenat ifluatex ifplatform iftex ifthen ifvtex import infwarerr intcalc keyval kvdefinekeys kvoptions kvsetkeys l3keys2e lineno lipsum logreq longtable lscape ltcaption ltxcmds makecell minted nameref newfloat newtxmath newtxtext nicematrix parskip pdfescape pdflscape pdflscape-nometadata pdfpages pdftexcmds pgf pgfcomp-version-0-65 pgfcomp-version-1-18 pgfcore pgffor pgfkeys pgfmath pgfrcs pgfsys refcount rerunfilecheck rotating scalefnt setspace shellesc siunitx stringenc subfiles suffix textcomp tikz titlesec tocloft tracklang translations trig uniquecounter upquote url xcolor xkeyval xparse xpatch xstring
  source files:
    dsd.tex
    subfile/1intro.tex
    subfile/2systemDesign.tex
    subfile/3specs.tex
    subfile/3sourcecode.tex
    subfile/4verification.tex
    subfile/5simulation.tex
    subfile/6discussion.tex
    subfile/7conclusion.tex
    subfile/appendices.tex
  compiler: latexmk
    engine: -lualatex
    options:
      -pdflua
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
      -shell-escape
      -f
      -cd
    aux_dir: latexmk_aux
    callback: 1
    continuous: 1
    executable: latexmk
    job: 
      jobid: 6
      output: C:\Users\happy\AppData\Local\Temp\nvim.0\WT63t3\0
      cmd: set max_print_line=2000 & latexmk -pdflua -verbose -file-line-error -synctex=1 -interaction=nonstopmode -shell-escape -f -cd  -lualatex -emulate-aux-dir -auxdir=latexmk_aux -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'" "dsd.tex"
      pid: 19584
  viewer: General
    job: 
      pid: -
      cmd: SumatraPDF -reuse-instance -forward-search "C:\Users\happy\Desktop\latex\ltxDSD\dsd.tex" 1 "C:\Users\happy\Desktop\latex\ltxDSD/dsd.pdf"
  qf method: LaTeX logfile
lervag commented 3 months ago

Based on a fresh kickstart.nvim configuration, I added a vimtex.lua to the plugins folder to load vimtex with its settings: …

You have clearly just copied the contents from the README. Here's an updated version that should work better:

return {
  {
    'lervag/vimtex',
    lazy = false,
    init = function()
      vim.g.vimtex_quickfix_open_on_warning = false
      vim.g.vimtex_compiler_latexmk = {
               aux_dir = "latexmk_aux",
               options = [
                 "-verbose",
                 "-file-line-error",
                 "-synctex=1",
                 "-interaction=nonstopmode",
                 "-shell-escape",
               ],
              }
      vim.g.vimtex_compiler_latexmk_engines = { ["_"] = "-lualatex" }
    end,
  },
}

I've successfully compiled an existing latex project and able to forward search just fine even from sub .tex files using SumatraPDF as the viewer, but I cannot perform any inverse search by double clicking the document, after adding the option in Sumatra as instructed: cmd /c start /min "" nvim --headless -c "VimtexInverseSearch %l '%f'" whenever I double click the document a cmd window briefly pops up and disappears.

Then I tried to manually run the VimtexInverseSearch command from powershell, and then from within nvim. Both instantly quits nvim no matter what options i pass to the command. I don't know how to continue troubleshooting from this point.

That is as expected. The nvim --headless -c ... command is meant to start a new neovim instance which communicates the inverse search to the "real" neovim instance and then quits.

Out of curiosity, how did you try to run the command from powershell? I.e., which command did you run?

I've looked this up and found a lot of people fixed the issue by adding the lazy = false option to not lazy load the plugin, but that is not the case for me.

The point here is simply that you should not lazy load VimTeX. If you do, then you will break the VimtexInverseSearch command.

MrRedCrack commented 3 months ago

Out of curiosity, how did you try to run the command from powershell? I.e., which command did you run?

I left the nvim instance that compiled the latex project running, then from the latex project folder, I opened a new powershell instance and entered this command, where dsd.tex is the main project file nvim --headless -c "VimtexInverseSearch 1 dsd.tex"

The point here is simply that you should not lazy load VimTeX. If you do, then you will break the VimtexInverseSearch command.

yep, I got that. But I'm confused what else has gone wrong as SumatraPDF inverse search is not working still.

You have clearly just copied the contents from the README. Here's an updated version that should work better:

I have pasted the entire thing but not sure what's the issue here: image

lervag commented 3 months ago

Sorry, my mistake: Change [ to { and ] to }.

lervag commented 3 months ago

Out of curiosity, how did you try to run the command from powershell? I.e., which command did you run?

I left the nvim instance that compiled the latex project running, then from the latex project folder, I opened a new powershell instance and entered this command, where dsd.tex is the main project file nvim --headless -c "VimtexInverseSearch 1 dsd.tex"

Ok; and what is the result when you do that? Also, can you try this: nvim --headless -c "VimtexInverseSearch 1 'dsd.tex'" - what is the result now?

MrRedCrack commented 3 months ago

Sorry, my mistake: Change [ to { and ] to }.

works now, thanks for the cleaner code. I'm using this configuration for the test results below:

Ok; and what is the result when you do that? Also, can you try this: nvim --headless -c "VimtexInverseSearch 1 'dsd.tex'" - what is the result now?

It seems to be doing something, but there is error, both with and without the single quotes: image image

So I tried to run the command again but replaced dsd.tex with its full path, then it worked and the cursor jumped to the intended line.

However, when double clicking in Sumatra there is no response in the nvim instance, nor does the cursor move anywhere. Already tried changing the options, no change in result: nvim --headless -c "VimtexInverseSearch %l '%f'" cmd /c start /min "" nvim --headless -c "VimtexInverseSearch %l '%f'" The nvim window sometimes gets brought into focus when I double click in Sumatra, but no change can be found anywhere.

lervag commented 3 months ago

I think you are on to something here. I think it would be useful to temporarily change the inverse view command in SumatraPDF to something that logs the %l and %f to a file. In bash on Linux, this would be echo %l %f >> out.log; but I don't know what to use on CMD/Powershell.

According to ChatGPT, you could try this:

cmd /c echo %l %f >> C:\path\to\your\log\file.txt

But I'm not sure if that will work. The point of this is to check if the %f filename is interpolated correctly.

MrRedCrack commented 3 months ago

But I'm not sure if that will work. The point of this is to check if the %f filename is interpolated correctly.

It works, here is the output: image

It looked normal, so I changed it back to the VimtexInverseSearch command. I don't know why, it magically started working. Tried changing the config back to the old messy one, still no issues. I'm confident I had restarted my computer several times when trying to troubleshoot this. Not sure what changed for it to start working. I will close this issue.

lervag commented 3 months ago

My guess is that you had a slight typo in your original command, but of course, we'll never know. And it doesn't matter; I'm glad to hear it works now!