bersama catatan peribadi & teknikalnya.

VimTeX and Zathura

Compiling and Viewing TeX Docs


geeky stuff
#zathura | #latex | #vimtex | #synctex | #vim | #pdf
Updated on 24 September 2020:-

Synctex-searches work just fine by installing zathura and all the dependencies from the Arch official repository (libmupdf can be skipped) as long as we set the vimtex-clientserver (please refer to the first related configuration file below) which is specifically for vimtex-synctex-inverse-search.

I use [1] vimtex, a vim plugin that provides support for writing and compiling LaTeX documents and [2] zathura as the document viewer.

In the beginning, I was determined to stick to [3] MuPDF as the PDF viewer due to its fast and complete features despite being small and lightweight but I kept encountering unpleasant experiences while compiling documents where it always froze the screen of my laptop when I closed the viewer.

Therefore, I then decided to just use zathura that was built from source as I would like it to have both synctex-forward-search and synctex-backward/inverse-search worked properly.

So basically, in order to have a complete functional zathura that enables full support of synctex, I need the following dependencies (as available on Arch or in the official website of zathura itself) installed prior to compiling it from source:-

  1. gtk3;
  2. glib2;
  3. girara;
  4. xdotool (mandatory for synctex);
  5. libmupdf (as a needed library).
  6. zathura-pdf-mupdf (as its plugin and to be installed after zathura itself); &

I then downloaded the latest version of [4] zathura (currently is 0.4.7), extracted it to ~/build directory, and run make install to install.

Please note that for neovim, neovim-remote is also necessary for synctex function. Once installed, place the below line in init.vim file:-
let g:vimtex_latexmk_progname= '/usr/bin/nvr'

Related configuration files are as follows:-
  1. To be added into your init.vim or .vimrc or .vimrc.local file, depending on whether or not you use any distributions of vim plugins and resources. Do refer to the configuration provided by lervag beforehand. Please ensure that the 'lervag/vimtex' plugin is installed.
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " VIMTEX
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    let &rtp  = '~/.vim/bundle/vimtex,' . &rtp
    let &rtp .= ',~/.vim/bundle/vimtex/after'
    let g:tex_flavor = 'latex'
    
    " Starting to use vimtex and it needs several configurations to work correctly
    let g:vimtex_fold_enabled = 0
    let g:vimtex_indent_enabled = 1
    let g:vimtex_complete_recursive_bib = 0
    let g:vimtex_view_method = 'zathura'
    let g:vimtex_complete_close_braces = 1
    let g:vimtex_quickfix_mode = 2
    let g:vimtex_quickfix_open_on_warning = 1
    call vimtex#imaps#add_map({
      \ 'lhs' : '<m-i>',
      \ 'rhs' : '\item ',
      \ 'leader' : '',
      \ 'wrapper' : 'vimtex#imaps#wrap_environment',
      \ 'context' : ["itemize", "enumerate", "compactitem"],
      \})
    
    " Setting `vimtex-clientserver` is important for inverse-search
    if empty(v:servername) && exists('*remote_startserver')
      call remote_startserver('VIM')
    endif

  2. Alternatively, vimtex-synctex-inverse-search can also be achieved by adding the following configurations:-

    • open .tex file with the below command:-
      vim --servername VIM

    • OR
    • place this line in .zshrc file:-
      alias vim="vim --servername VIM"
    • *(A note for myself): To make it work when opening .tex files from ranger, add this line to the .config/ranger/rifle.conf file:-
      ext tex, has vim = vim --servername VIM "$@"

    Additional Notes

    The additional configuration above is not needed for gvim as it works out of the box.

  3. .latexmkrc.

    Take note of the below line in this .latexmkrc file:

    $pdflatex = 'xelatex -file-line-error -synctex=1 -interaction=nonstopmode -shell-escape %S %O -verbose';

    This line will be responsible to act as the command in compiling a latex document to PDF automatically.


Now, how to do the synctex-forward-search and synctex-backward-search in zathura when compiling .tex documents with latexmk (the default compiler for vimtex)?

  • For synctex-forward-search: Go to vim (if using this editor) where the .tex doc is opened and point to the sentence we would like to see in zathura, and then press \lv.
    The '\' here means "Whatever key defined as a maplocalleader in vim config file".

    Notice that in zathura, it brings us to the page containing the sentence we previously pointed from vim.
  • For synctex-backward/inverse-search: In zathura, press Ctrl + highlight (Left Click and select the word with touchpad/mouse), the cursor will then automatically be pointed to the front line of the .tex file in vim where it contains the word highlighted from zathura.

Watch the video below to see it in action (updated on 24 September 2020, and the editor used is VIM).


Zathura can be customized with a simple config file. Save the config file as zathurarc in ~/.config/zathura directory, like the one I have [here].

Kali terakhir dikemaskini:
Top