lervag / vimtex

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

Minimal vimtex config example for Linux Wayland with Mupdf (ideally for Neovim) and Latexmk #2995

Closed banana59 closed 1 month ago

banana59 commented 1 month ago

Description

Hello,

this is not a issue perse, rather a request. I can't manage to find a config example for vimtex on Linux using Wayland with Mupdf (for Neovim) using Latexmk. I want to use mupdf since it is also available on windows (or any other pdf viewer available on both OS's). I have read the sections of the documentation regarding Mupdf and couldn't find a valid example using this combination.

Steps to reproduce

My minimal vimtex configuration looks like

vim.g.vimtex_view_method = 'mupdf'

-- Additional vimtex configurations
vim.g.vimtex_compiler_latexmk = {
    build_dir = '.out',
    options = {
        '-shell-escape',
        '-verbose',
        '-file-line-error',
        '-interaction=nonstopmode',
        '-synctex=1'
    }
}

Expected behavior

  1. I couldn't find ways to automatically update Mupdf after the pdf-file change. Can this be automated?
  2. Can the plugin be configured so that it uses the existing window if there is already one window instance open.

Actual behavior

  1. Mupdf have to be manually refreshed using the r key. There is a send_keys option I have already seen, but this seem to happen only once at the beginning if I understand this correct.
  2. Pressing lv opens another instance of the pdf viewer mupdf.

Do you use a latexmkrc file?

No, though I have tried $dvi_update_method=2 and $new_viewer_always=0

VimtexInfo

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

VimTeX project: a
  base: a.tex
  root: /tmp
  tex: /tmp/a.tex
  main parser: current file verified
  document class: article
  packages: inputenc
  compiler: latexmk
    engine: -pdf
    options:
      -shell-escape
      -verbose
      -file-line-error
      -interaction=nonstopmode
      -synctex=1
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: MuPDF
    xwin id: 0
  qf method: LaTeX logfile
lervag commented 1 month ago

this is not a issue perse, rather a request. I can't manage to find a config example for vimtex on Linux using Wayland with Mupdf (for Neovim) using Latexmk. I want to use mupdf since it is also available on windows (or any other pdf viewer available on both OS's). I have read the sections of the documentation regarding Mupdf and couldn't find a valid example using this combination.

I couldn't find ways to automatically update Mupdf after the pdf-file change.

MuPDF on Linux with Xorg works because we use xdotool behind the scenes to make this happen. I believe it is possible to do something similar on Wayland, but I've never used Wayland myself and so I've never investigated thoroughly.

Can this be automated?

So, I think the answer is yes, but I'm not sure. And I'm sorry to say that I'm not interested in spending much time on this until I'm personally using Wayland. But if anyone figures it out I will be happy to accept patches or concrete suggestions.

Can the plugin be configured so that it uses the existing window if there is already one window instance open.

This again relies on xdotool. With xdotool we can check if there is an existing window and avoid opening multiple windows.

As an alternative solution: did you consider testing Zathura? I believe it works on Wayland and it has many of the same benefits as MuPDF (fast, minimal). It should work better with Wayland than MuPDF.

banana59 commented 1 month ago

This seems to work (auto refreshing & one window instance & jumping to the current line). Are there redundant options?

vim.g.vimtex_compiler_method = 'latexmk'
vim.g.vimtex_compiler_latexmk = {
    build_dir = '',
    callback = 1,
    continuous = 1,
    executable = 'latexmk',
    options = {
        '-shell-escape',
        '-verbose',
        '-file-line-error',
        '-interaction=nonstopmode',
        '-synctex=1'
    }
}
vim.g.vimtex_view_method = 'zathura'

vim.g.vimtex_view_general_viewer = 'zathura'
vim.g.vimtex_view_general_options = '--shell-escape -interaction=nonstopmode -synctex=1 -file-line-error'

vim.g.vimtex_view_zathura_options = '-x "nvr --remote-silent +%{line} %{input}" --synctex-forward %l:0:%f'

No ~/.latexmkrc needed

lervag commented 1 month ago

This seems to work (auto refreshing & one window instance & jumping to the current line). Are there redundant options?

Yes, you can simplify to this:

vim.g.vimtex_compiler_latexmk = {
    options = {
        '-shell-escape',
        '-verbose',
        '-file-line-error',
        '-interaction=nonstopmode',
        '-synctex=1'
    }
}
vim.g.vimtex_view_method = 'zathura'

When you set the view method to Zathura you don't need to configure the general view method. And I removed stuff that were already defaults.

You should not really need to specify vim.g.vimtex_view_zathura_options, because it should already be properly specified by VimTeX. If this doesn't work as expected, in particular backward search, then that is most likely because you are lazy loading VimTeX.

banana59 commented 1 month ago

I have updated it according to your advice. I now get the error that zathura window id can't be found, it opens the previewer window though. Error

My current config

On windows with WSL2 I get the same error and the previewer window do not open. In /etc/wsl.conf

[boot]
systemd=true

is set.

lervag commented 1 month ago

I have updated it according to your advice. I now get the error that zathura window id can't be found, it opens the previewer window though.

That's as expected: Zathura will also use xdotool, which won't work. So, now try to use zathura_simple instead. It should work more or less the same, except it won't require xdotool.

![My current config]

It is much easier to help comment on config if you include the actual text content. A screenshot is harder. But ok, a few comments:

Also, I think you might want to remove tex-conceal.vim, because VimTeX already provides the desired conceals.

On windows with WSL2 I get the same error and the previewer window do not open.

If you have issues on Windows with WSL2, please open a new issue - it is really a different beast!

banana59 commented 1 month ago

Thank you. This works great now. I will open another issue, if I can't manage to solve the WSL2 issue with the already preexisting issues.

lervag commented 1 month ago

Thanks, glad to see that things work well now!