VimTeX and Zathura
Compiling and Viewing TeX Docs
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:-
- gtk3;
- glib2;
- girara;
- xdotool (mandatory for
synctex
); - libmupdf (as a needed library).
- 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.
- To be added into your
init.vim
or.vimrc
or.vimrc.local
file, depending on whether or not you use any distributions ofvim plugins and resources
. Do refer to the configuration provided bylervag
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
- open
.tex
file with the below command:-vim --servername VIM
- place this line in
.zshrc
file:-alias vim="vim --servername VIM"
- *(A note for myself): To make it work when opening
.tex
files fromranger
, add this line to the.config/ranger/rifle.conf
file:-ext tex, has vim = vim --servername VIM "$@"
- .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.
Alternatively, vimtex-synctex-inverse-search
can also be achieved by adding the following configurations:-
OR
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
.
Notice that inzathura
, it brings us to the page containing the sentence we previously pointed from vim. - For
synctex-backward/inverse-search
: In zathura, pressCtrl + 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].