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

VimTeX: Viewer cannot find Zathura window ID! #2941

Open
DALEE9000 opened this issue Apr 24, 2024 · 1 comment
Open

VimTeX: Viewer cannot find Zathura window ID! #2941

DALEE9000 opened this issue Apr 24, 2024 · 1 comment
Labels

Comments

@DALEE9000
Copy link

DALEE9000 commented Apr 24, 2024

Description

Running Ubuntu 22.04.2. After entering command \lv to open Zathura, I receive an error message saying "VimTeX: Viewer cannot find Zathura window ID!", and Zathura doesn't display the pdf.

I have already checked to ensure that Zathura is synctex-enabled.

$ ldd /usr/bin/zathura | grep libsynctex
        libsynctex.so.2 => /lib/x86_64-linux-gnu/libsynctex.so.2 (0x00007fbca7e6b000)

Moreover, I have indeed ensured that Zathura works from the command line in displaying the desired pdf. If it helps, my version of Zathura is listed below:

$ 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)

Additionally, when entering the cmd_start output (see below) in the command line, I receive the following error:

$ zathura  -x "/usr/local/bin/vim -T dumb --not-a-term -n -c \"VimtexInverseSearch %{line} '%{input}'\"" --synctex-forward 5:14:'/home/cantorian_infinity/test.tex' 'test.pdf'
$ error: Could not connect to session bus: Could not connect: No such file or directory
error: Got no usable data from SyncTeX or D-Bus failed in some way.

Steps to reproduce

vim -u minimal.vim minimal.tex

minimal.tex

\documentclass{minimal}

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

minimal.vim

call plug#begin()
"VimTeX
Plug 'lervag/vimtex'
call plug#end()

let g:vimtex_viewer_method='zathura'


" This will only work if `vim --version` includes `+clientserver`!
" To enable Zathura and Vim to speak to each other
if empty(v:servername) && exists('*remote_startserver')
  call remote_startserver('VIM')
endif

" Get Vim's window ID for switching focus from Zathura to Vim using xdotool.
" Only set this variable once for the current Vim instance.
if !exists("g:vim_window_id")
  let g:vim_window_id = system("xdotool getactivewindow")
endif

function! s:TexFocusVim() abort
  " Give window manager time to recognize focus moved to Zathura;
  " tweak the 200m (200 ms) as needed for your hardware and window manager.
  sleep 200m  

  " Refocus Vim and redraw the screen
  silent execute "!xdotool windowfocus " . expand(g:vim_window_id)
  redraw!
endfunction

augroup vimtex_event_focus
  au!
  au User VimtexEventView call s:TexFocusVim()
augroup END

" So Vim finds Zathura window ID
function! ZathuraHook() abort
  if exists('b:vimtex.viewer.xwin_id') && b:vimtex.viewer.xwin_id <= 0
    silent call system('xdotool windowactivate ' . b:vimtex.viewer.xwin_id . ' --sync')
    silent call system('xdotool windowraise ' . b:vimtex.viewer.xwin_id)
  endif
endfunction

augroup vimrc_vimtex
  autocmd!
  autocmd User VimtexEventView call ZathuraHook()
augroup END

Expected behavior

Zathura to display minimal.pdf

Actual behavior

VimTeX: Viewer cannot find Zathura window ID! error appears

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: Ubuntu 22.04.2 LTS
  Vim version: VIM 9.1 (1-368)
  Has clientserver: true
  Servername: VIM

VimTeX project: test
  base: test.tex
  root: /home/cantorian_infinity
  tex: /home/cantorian_infinity/test.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: process 140322 run
      output: /tmp/v721nFr/1
      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: 140322
  viewer: Zathura
    xwin id: 0
    cmd_start: zathura  -x "/usr/local/bin/vim -T dumb --not-a-term -n -c \"VimtexInverseSearch %{line} '%{input}'\"" --synctex-forward 5:14:'/home/cantorian_infinity/test.tex' 'test.pdf'&
  qf method: LaTeX logfile
@DALEE9000 DALEE9000 added the bug label Apr 24, 2024
@lervag
Copy link
Owner

lervag commented Apr 24, 2024

Running Ubuntu 22.04.2.

Just out of curiosity, I notice you have Vim 9.1 - as far as I know, Ubuntu 22 runs with Vim 8.2. Did you install Vim 9.1 from other repos or manually?

After entering command \lv to open Zathura, I receive an error message saying "VimTeX: Viewer cannot find Zathura window ID!", and Zathura doesn't display the pdf.

That Zathura doesn't even display the pdf is strange.

I have already …

Thanks for useful info.

Additionally, when entering the cmd_start output (see below) in the command line, I receive the following error: …

Great, glad to see I don't need to ask for this! And as you see from the output, there is clearly an important problem here that is not with VimTeX, but with your Zathura + Ubuntu installation. Are you on WSL?

minimal.vim

Is this based on your current config? It seems you are using two hooks that are trying to do somewhat "opposing" things on VimtexEventView. I would simplify it, something like this:

if !exists("g:vim_window_id")
  let g:vim_window_id = system("xdotool getactivewindow")
endif

function! ZathuraHook() abort
  " sleep 100m " not sure if you need sleep...
  if exists('b:vimtex.viewer.xwin_id') && b:vimtex.viewer.xwin_id <= 0
    silent call system('xdotool windowactivate ' . b:vimtex.viewer.xwin_id . ' --sync')
    silent call system('xdotool windowraise ' . b:vimtex.viewer.xwin_id)
  endif

  " sleep 200m " not sure if you need sleep...
  silent execute "!xdotool windowfocus " . expand(g:vim_window_id)
endfunction

augroup vimrc_vimtex
  autocmd!
  autocmd User VimtexEventView call ZathuraHook()
augroup END

Feel free to add the comments back if you want. Also, when the viewer works, you should experiment with the sleep, it may not be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants