Skip to content

Zathura backward search: bug with multi-file projects #2127

@psvenk

Description

@psvenk

Problem

The SyncTeX support for Zathura is excellent out of the box, but I noticed that the backward search command line is hard-coded to use --remote-expr to call vimtex#view#reverse_goto:

let l:cmd .= ' -x "' . g:vimtex_compiler_progname
\ . ' --servername ' . v:servername
\ . ' --remote-expr '
\ . '\"vimtex#view#reverse_goto(%{line}, ''%{input}'')\""'

This function works well in single-file projects, but I noticed a few problems when switching files in multi-file projects. Specifically, consider the case that a project has files a.tex and b.tex, my Vim currently has a.tex open, and I perform a reverse search from a place in the PDF that corresponds to b.tex line 50.

  • If a.tex has unsaved changes, then VimTeX focuses a.tex line 50. This seems to be because the silent edit fails here:
    " Open file if necessary
    if !bufexists(l:file)
    if filereadable(l:file)
    execute 'silent edit' l:file
  • If a.tex does not have unsaved changes, then b.tex takes over the buffer where I was editing a.tex. While this may be desirable behavior for other users, I would prefer that b.tex open in a new tab page.

Suggested solutions/workarounds

I suppose that the first bullet point is a bug and should be fixed globally, but that the second bullet point hinges on subjective preferences. So, I propose that the first part be fixed e.g. by splitting the window, which is what Vim's --remote argument does. To address the tab page issue, I think it would be a good idea to make the behavior configurable.

Alternatively, the use of --remote-expr (as opposed to --remote or --remote-tab) could be made configurable. The stopgap solution that I am using right now is changing the hard-coded --remote-expr to use --remote-tab, and this seems to work fine.

My stopgap solution
diff --git a/autoload/vimtex/view/zathura.vim b/autoload/vimtex/view/zathura.vim
index 95235783..ec17b141 100644
--- a/autoload/vimtex/view/zathura.vim
+++ b/autoload/vimtex/view/zathura.vim
@@ -37,8 +37,7 @@ function! s:zathura.start(outfile) dict abort " {{{1
   if self.has_synctex
     let l:cmd .= ' -x "' . g:vimtex_compiler_progname
           \ . ' --servername ' . v:servername
-          \ . ' --remote-expr '
-          \ .     '\"vimtex#view#reverse_goto(%{line}, ''%{input}'')\""'
+          \ . ' --remote-tab +\%{line} \%{input}\"'
     if g:vimtex_view_forward_search_on_start
       let l:cmd .= ' --synctex-forward '
             \ .  line('.')
@@ -80,7 +79,7 @@ function! s:zathura.latexmk_append_argument() dict abort " {{{1
     if self.has_synctex
       let zathura .= ' -x \"' . g:vimtex_compiler_progname
           \ . ' --servername ' . v:servername
-          \ . ' --remote +\%{line} \%{input}\" \%S'
+          \ . ' --remote-tab +\%{line} \%{input}\" \%S'
     endif
 
     let cmd  = vimtex#compiler#latexmk#wrap_option('new_viewer_always', '0')

I suppose that one could also work around this by using the general viewer and configuring everything manually, but this has obvious downsides.

Miscellany

Additionally, I noticed that --remote and not --remote-expr is used later in the same file, in s:zathura.latexmk_append_argument(). Is there a reason for this? Apologies if this (or anything else in this issue) has already been addressed elsewhere.

let zathura = 'zathura ' . g:vimtex_view_zathura_options
if self.has_synctex
let zathura .= ' -x \"' . g:vimtex_compiler_progname
\ . ' --servername ' . v:servername
\ . ' --remote +\%{line} \%{input}\" \%S'
endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions