lervag / vimtex

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

Vimtex: Viewer cannot find Zathura window ID #2973

Closed coycatrett closed 3 months ago

coycatrett commented 3 months ago

Description

When I want to view a converted pdf file from latex using zathura, vimtex reports back with "Vimtex: Viewer cannot find Zathura window ID".

Zathura version:

zathura 0.4.9
girara 0.3.7 (runtime: 0.3.7)
(plugin) pdf-poppler (0.3.0) (/usr/lib/x86_64-linux-gnu/zathura/libpdf-poppler.so)

minimal vimtex.lua file:

return {
    'lervag/vimtex',
    lazy = false,
    init = function()
        vim.cmd('filetype plugin indent on') -- Edit
        vim.g.vimtex_view_method = 'zathura'
    end
}

Edit: added vim.cmd('filetype plugin indent on') to init function and now the Zathura window appears after executing :VimtexView. This did not fix the errors below with the lazy reloading nor get rid of the initial error message that the viewer cannot find the zathura window ID.

File tree & Lazy.lua file:

lazy lua

Minimal tex:

\documentclass{article}

\begin{document}
Hello World!
\end{document}

When I run :VimtexView in the minimal tex document, this error message appears:

Vimtex: Viewer cannot find Zathura window ID!

When I reload vimtex with lazy, here is what it reports:

Failed to deactivate plugin vimtex

...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:212: module 'vimtex' not found:
^Ino field package.preload['vimtex']
cache_loader: module vimtex not found
cache_loader_lib: module vimtex not found
^Ino file './vimtex.lua'
^Ino file '/home/runner/work/neovim/neovim/.deps/usr/share/luajit-2.1/vimtex.lua'
^Ino file '/usr/local/share/lua/5.1/vimtex.lua'
^Ino file '/usr/local/share/lua/5.1/vimtex/init.lua'
^Ino file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/vimtex.lua'
^Ino file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/vimtex/init.lua'
^Ino file '/home/ccatrett/.local/share/nvim/lazy-rocks/telescope.nvim/share/lua/5.1/vimtex.lua'
^Ino file '/home/ccatrett/.local/share/nvim/lazy-rocks/telescope.nvim/share/lua/5.1/vimtex/init.lua'
^Ino file './vimtex.so'
^Ino file '/usr/local/lib/lua/5.1/vimtex.so'
^Ino file '/home/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/vimtex.so'
^Ino file '/usr/local/lib/lua/5.1/loadall.so'
^Ino file '/home/ccatrett/.local/share/nvim/lazy-rocks/telescope.nvim/lib/lua/5.1/vimtex.so'

The relevant results after running checkhealth:

==============================================================================
lazy: require("lazy.health").check()

lazy.nvim ~
- {lazy.nvim} version `11.9.0`
- OK {git} `version 2.34.1`
- OK no existing packages found by other package managers
- OK packer_compiled.lua not found

luarocks ~
- checking `luarocks` installation
- OK no plugins require `luarocks`, so you can ignore any warnings below
- OK {luarocks} `/usr/bin/luarocks 3.8.0`
- OK {lua5.1} `Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio`

==============================================================================
nvim: require("nvim.health").check()

Configuration ~
- OK no issues found

Runtime ~
- OK $VIMRUNTIME: /opt/nvim-linux64/share/nvim/runtime

Performance ~
- OK Build type: Release

Remote Plugins ~
- OK Up to date

terminal ~
- key_backspace (kbs) terminfo entry: `key_backspace=\177`
- key_dc (kdch1) terminfo entry: `key_dc=\E[3~`

External Tools ~
- OK ripgrep 13.0.0 (/usr/bin/rg)

==============================================================================
vimtex: health#vimtex#check

VimTeX ~
- OK Vim version should have full support!
- OK Zathura should work properly!
- OK Compiler should work!

Steps to reproduce

  1. cd to a location containing a .tex file, say test.tex
  2. nvim test.tex
  3. :VimtexCompile

Expected behavior

Zathura opens the pdf with no error message from neovim displaying, 'Vimtex: Viewer cannot find Zathura window ID'

Actual behavior

Zathura opens the pdf with an error message from neovim displaying 'Vimtex: Viewer cannot find Zathura window ID'

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: Ubuntu 22.04.4 LTS
  Vim version: NVIM v0.10.0
  Has clientserver: true
  Servername: /run/user/1000//nvim.25398.0

VimTeX project: test
  base: test.tex
  root: /home/ccatrett
  tex: /home/ccatrett/test.tex
  main parser: fallback current file
  document class: 
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
    job: 
      jobid: 7
      output: /tmp/nvim.ccatrett/Fp8QMy/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"' 'test.tex'
      pid: 32026
  viewer: Zathura
    xwin id: 0
    cmd_start: zathura  -x "/opt/nvim-linux64/bin/nvim --headless -c \"VimtexInverseSearch %{line} '%{input}'\"" --synctex-forward 5:3:'/home/ccatrett/test.tex' 'test.pdf'&
  qf method: LaTeX logfile
lervag commented 3 months ago

Do you use Xorg or Wayland?

coycatrett commented 3 months ago

I am unsure what those terms mean. How would I check for the one that I use?

Also, kindly see the edit I made to the initial post

lervag commented 3 months ago

I am unsure what those terms mean. How would I check for the one that I use?

When I want to view a converted pdf file from latex using zathura, vimtex reports back with "Vimtex: Viewer cannot find Zathura window ID".

Wayland and Xorg are two different display server protocols. Wayland is "modern" and expected to be the successor of Xorg. However, since Xorg is very old and very mature and mostly "just works", it's hard to really replace it. Still, Ubuntu and other distros are slowly changing to Wayland as the default.

If you use Wayland, then the "window ID" concept no longer makes sense and the standard Zathura viewer will not work properly. That's why I'm asking which of these you are using.

Edit: added vim.cmd('filetype plugin indent on') to init function and now the Zathura window appears after executing :VimtexView. This did not fix the errors below with the lazy reloading nor get rid of the initial error message that the viewer cannot find the zathura window ID.

That should really not be necessary if you load VimTeX with lazy.nvim.

When I reload vimtex with lazy, here is what it reports: …

What does "reload VimTeX with lazy" mean? Is it :Lazy reload vimtex? If so, then you really should not need to do any reloading. Also, this is an entirely different problem than the original one, so let's keep the issue focused on the Zathura thing.

Steps to reproduce

No response

Expected behavior

No response

Actual behavior

No response

It is really useful if you provide the steps to reproduce and the expected versus actual behaviour. I understand that it can feel pedantic, but the point is to avoid simple misunderstandings and confusions that are hard to catch if we are not explicit.

Something like:

  1. Open terminal
  2. cd somewhere
  3. nvim test.tex
  4. :VimtexCompile
  5. Expect to see pdf opened in zathura, but observe error instead.

VimtexInfo

  viewer: Zathura
    cmd_start: zathura  -x "/opt/nvim-linux64/bin/nvim --headless -c \"VimtexInverseSearch %{line} '%{input}'\"" --synctex-forward 5:3:'/home/ccatrett/test.tex' 'test.pdf'&

What happens if you execute the zathura command manually in a terminal?

zathura -x "/opt/nvim-linux64/bin/nvim --headless -c \"VimtexInverseSearch %{line} '%{input}'\"" --synctex-forward 5:3:'/home/ccatrett/test.tex' 'test.pdf'
coycatrett commented 3 months ago

If you use Wayland, then the "window ID" concept no longer makes sense and the standard Zathura viewer will not work properly. That's why I'm asking which of these you are using.

I tried researching how to check which display server protocol.

Running echo $DISPLAY returns :0 and running echo $WAYLAND_DISPLAY returns wayland-0.

Running ps -e | grep -E 'Xorg|X$' doesn't return anything. I am still unsure of which one I am using, but I think it is wayland based on the wayland display variable.

It is really useful if you provide the steps to reproduce and the expected versus actual behaviour. I understand that it can feel pedantic, but the point is to avoid simple misunderstandings and confusions that are hard to catch if we are not explicit.

I have made updates to the original report for reproduction.

What happens if you execute the zathura command manually in a terminal?

The zathura application opens and correctly displays the test.pdf file.

lervag commented 3 months ago

I tried researching how to check which display server protocol.

Running echo $DISPLAY returns :0 and running echo $WAYLAND_DISPLAY returns wayland-0.

You can check with echo $XDG_SESSION_TYPE, which returns x11 if you are on Xorg or wayland if you're on Wayland.

But since you have the $WAYLAND_DISPLAY variable, I guess you are running Wayland.

…, but I think it is wayland based on the wayland display variable.

Exactly - and the Zathura viewer config does not work well on Wayland. Try to change it to the 'zathura_simple' variant. It should work more or less equally well. See :help vimtex-view-zathura-simple.

let g:vimtex_view_method = 'zathura_simple'

or

vim.g.vimtex_view_method = "zathura_simple"
coycatrett commented 3 months ago

Thank you! That fixed the "cannot find viewer ID" message.

I'll look more into the display protocols. How would I know to think about issues like this in the future?

lervag commented 3 months ago

Thank you! That fixed the "cannot find viewer ID" message.

Glad to hear it!

I'll look more into the display protocols. How would I know to think about issues like this in the future?

It's at least partially explained in the docs. If you read :help vimtex-view-zathura:

Zathura is, like MuPDF, a very fast and minimalistic viewer. Compared to
MuPDF, it allows more user configuration. Zathura has full support for both
forward and inverse search. ZATHURA SHOULD BE STRAIGHTFORWARD TO INSTALL AND
USE ON LINUX WITH XORG. …

...

The main variant uses `xdotool` to help avoid duplicate Zathura instances.
However, in some environments, `xdotool` is not available. Here the simple
variant should work well.

Still, if you are not aware of the concepts of the display manager (Wayland vs Xorg/X11/X window system), then I understand it is hard to catch these things.