VimTeX and Zathura
Compiling and Viewing TeX Docs
Synctex-searches work just fine by installing
zathura
and all the dependencies from 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 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.
neovim
, neovim-remote
is also necessary for synctex
function. Once installed, place the below line in init.vim
file:-VimL
let g:vimtex_latexmk_progname= '/usr/bin/nvr'
To be added into your
init.vim
or.vimrc
or.vimrc.local
file, depending on whether or not you use any distributions ofvim plugins
andresources
. Do refer to the configuration provided bylervag
beforehand. Please ensure that the ‘lervag/vimtex
’ plugin is installed.VimL
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 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
Alternatively,
vimtex-synctex-inverse-search
can also be achieved by adding the following configurations:-open
.tex
file with the below command:-ORbash
vim --servername VIM filename.tex
place this line in
.zshrc
file:-~/.zshrc
alias vim="vim --servername VIM"
*(A note for myself): To make it work when opening
.tex
files fromranger
, add this line to the following file:-~/.config/ranger/rifle.conf
ext tex, has vim = vim --servername VIM "$@"
Additional Notes
The additional configuration above is not needed forgvim
as it works out of the box.
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 amaplocalleader
invim
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, 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.
Tentang Blog & Penulis
Linux
& perisian sumber terbuka, Virtual Machine
, serta Typesetting system
.Full Stack Development
Analisis Data

Sumber dari Wallpaper Cave.