diff --git a/autoload/vimtex/view.vim b/autoload/vimtex/view.vim index 8b559ae..78c9d58 100644 --- a/autoload/vimtex/view.vim +++ b/autoload/vimtex/view.vim @@ -7,10 +7,6 @@ let s:viewers = [ \ 'general', \ 'mupdf', - \ 'okular', - \ 'qpdfview', - \ 'skim', - \ 'sumatrapdf', \ 'zathura', \ ] for viewer in s:viewers @@ -38,6 +34,8 @@ function! vimtex#view#init_buffer() " {{{1 let viewer = 's:' . g:vimtex_view_method if !exists(viewer) echoerr 'vimtex viewer ' . g:vimtex_view_method . ' does not exist!' + echo "\nPlease see :h g:vimtex_view_method\n\n" + let b:vimtex.viewer = {} return endif execute 'let b:vimtex.viewer = ' . viewer @@ -88,12 +86,14 @@ function! s:general.init() dict " {{{2 " " Set default options " + call vimtex#util#set_default_os_specific('g:vimtex_view_general_viewer', \ { \ 'linux' : 'xdg-open', \ 'mac' : 'open', \ }) - call vimtex#util#set_default('g:vimtex_view_general_options', '') + call vimtex#util#set_default('g:vimtex_view_general_options', '@pdf') + call vimtex#util#set_default('g:vimtex_view_general_options_latexmk', '') if !executable(g:vimtex_view_general_viewer) echoerr 'vimtex viewer is not executable!' @@ -107,10 +107,17 @@ function! s:general.view(file) dict " {{{2 let outfile = a:file !=# '' ? a:file : b:vimtex.out() if s:output_not_readable(outfile) | return | endif + " Parse options + let opts = g:vimtex_view_general_options + let opts = substitute(opts, '@line', line('.'), 'g') + let opts = substitute(opts, '@col', col('.'), 'g') + let opts = substitute(opts, '@tex', + \ vimtex#util#fnameescape(expand('%:p')), 'g') + let opts = substitute(opts, '@pdf', vimtex#util#fnameescape(outfile), 'g') + + " Construct the command let exe = {} - let exe.cmd = g:vimtex_view_general_viewer - let exe.cmd .= ' ' . g:vimtex_view_general_options - let exe.cmd .= ' ' . vimtex#util#fnameescape(outfile) + let exe.cmd = g:vimtex_view_general_viewer . ' ' . opts call vimtex#util#execute(exe) let self.cmd_view = exe.cmd @@ -121,12 +128,9 @@ endfunction " }}}2 function! s:general.latexmk_append_argument() dict " {{{2 - let cmd = vimtex#latexmk#add_option('new_viewer_always', '0') - let cmd .= vimtex#latexmk#add_option('pdf_update_method', '0') - let cmd .= vimtex#latexmk#add_option('pdf_previewer', 'start ' + return vimtex#latexmk#add_option('pdf_previewer', 'start ' \ . g:vimtex_view_general_viewer . ' ' - \ . g:vimtex_view_general_options) - return cmd + \ . g:vimtex_view_general_options_latexmk) endfunction " }}}2 @@ -287,123 +291,6 @@ endfunction " }}}2 -" {{{1 Okular -function! s:okular.init() dict " {{{2 - call vimtex#util#set_default('g:vimtex_view_okular_options', '') - - if !executable('okular') - echoerr 'vimtex viewer Okular is not executable!' - endif -endfunction - -" }}}2 -function! s:okular.view(file) dict " {{{2 - let outfile = a:file !=# '' ? a:file : b:vimtex.out() - if s:output_not_readable(outfile) | return | endif - - let exe = {} - let exe.cmd = 'okular ' . g:vimtex_view_okular_options - let exe.cmd .= ' --unique ' . vimtex#util#fnameescape(outfile) - let exe.cmd .= '\#src:' . line('.') . vimtex#util#fnameescape(expand('%:p')) - call vimtex#util#execute(exe) - let self.cmd_view = exe.cmd - - if has_key(self, 'hook_view') - call self.hook_view() - endif -endfunction - -" }}}2 - -" {{{1 qpdfview -function! s:qpdfview.init() dict " {{{2 - call vimtex#util#set_default('g:vimtex_view_qpdfview_options', '') - - if !executable('qpdfview') - echoerr 'vimtex viewer qpdfview is not executable!' - endif -endfunction - -" }}}2 -function! s:qpdfview.view(file) dict " {{{2 - let outfile = a:file !=# '' ? a:file : b:vimtex.out() - if s:output_not_readable(outfile) | return | endif - - let exe = {} - let exe.cmd = 'qpdfview ' . g:vimtex_view_qpdfview_options - let exe.cmd .= ' --unique ' . vimtex#util#fnameescape(outfile) - let exe.cmd .= '\#src:' . vimtex#util#fnameescape(expand('%:p')) - let exe.cmd .= ':' . line('.') - let exe.cmd .= ':' . col('.') - call vimtex#util#execute(exe) - let self.cmd_view = exe.cmd - - if has_key(self, 'hook_view') - call self.hook_view() - endif -endfunction - -" }}}2 - -" {{{1 Skim -function! s:skim.init() dict " {{{2 - call vimtex#util#set_default('g:vimtex_view_skim_options', '') - - if !executable('/Applications/Skim.app/Contents/SharedSupport/displayline') - echoerr 'vimtex viewer Skim is not executable!' - endif -endfunction - -" }}}2 -function! s:skim.view(file) dict " {{{2 - let outfile = a:file !=# '' ? a:file : b:vimtex.out() - if s:output_not_readable(outfile) | return | endif - - let exe = {} - let exe.cmd = '/Applications/Skim.app/Contents/SharedSupport/displayline' - let exe.cmd .= ' ' . g:vimtex_view_skim_options - let exe.cmd .= ' ' . line('.') - let exe.cmd .= ' ' . vimtex#util#fnameescape(outfile) - let exe.cmd .= ' ' . vimtex#util#fnameescape(expand('%:p')) - call vimtex#util#execute(exe) - let self.cmd_view = exe.cmd - - if has_key(self, 'hook_view') - call self.hook_view() - endif -endfunction - -" }}}2 - -" {{{1 SumatraPDF -function! s:sumatrapdf.init() dict " {{{2 - call vimtex#util#set_default('g:vimtex_view_sumatrapdf_options', '') - - if !executable('SumatraPDF') - echoerr 'vimtex viewer SumatraPDF is not executable!' - endif -endfunction - -" }}}2 -function! s:sumatrapdf.view(file) dict " {{{2 - let outfile = a:file !=# '' ? a:file : b:vimtex.out() - if s:output_not_readable(outfile) | return | endif - - let exe = {} - let exe.cmd = 'SumatraPDF ' . g:vimtex_view_sumatrapdf_options - let exe.cmd .= ' -forward-search ' . vimtex#util#fnameescape(expand('%:p')) - let exe.cmd .= ' ' . line('.') - let exe.cmd .= ' ' . vimtex#util#fnameescape(outfile) - call vimtex#util#execute(exe) - let self.cmd_view = exe.cmd - - if has_key(self, 'hook_view') - call self.hook_view() - endif -endfunction - -" }}}2 - " {{{1 Zathura function! s:zathura.init() dict " {{{2 " Only initialize once diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 91d5ad5..1334ce0 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -586,15 +586,78 @@ Options~ Default value: 1 *g:vimtex_view_method* - Set the viewer method. The supported viewers are listed below. Please see - |vimtex-synctex| for explanations of the terms 'forward search' and - 'backward search'. + Set the viewer method. The general viewer |vimtex_viewer_general| defines + a generic interface that allows sufficient customization for most viewer + applications. However, a few applications require some special attention, + and so |vimtex| provides a couple of custom viewers: |vimtex_viewer_mupdf| and + |vimtex_viewer_zathura|. - general~ - This is a basic interface where the viewer can be specified through - |g:vimtex_view_general_viewer|. + Possible values: + 'general' (default) + 'mupdf' + 'zathura' - mupdf~ + *vimtex_viewer_general* + This is a generic interface where the viewer application is specified + through |g:vimtex_view_general_viewer| and the viewer options are given + with |g:vimtex_view_general_options|. After successful compilation with + `latexmk`, the viewer is started with the options provided by + |g:vimtex_view_general_options_latexmk|. The interface allows the + general viewer to support forward search with a lot of different + applications: + + *vimtex_viewer_okular* + https://okular.kde.org/ + Okular is a very feature rich PDF viewer that supports forward + and backward search. Backward search must be set up from the + viewer. > + + let g:vimtex_view_general_viewer = 'okular' + let g:vimtex_view_general_options = '--unique @pdf\#src:@line@tex' + let g:vimtex_view_general_options_latexmk = '--unique' +< + *vimtex_viewer_qpdfview* + https://launchpad.net/qpdfview + qpdfview is a tabbed document viewer. It supports forward search. + Backward search must be set up from the viewer. > + + let g:vimtex_view_general_viewer = 'qpdfview' + let g:vimtex_view_general_options = '--unique @pdf\#src:@tex:@line:@col' + let g:vimtex_view_general_options_latexmk = '--unique' +< + *vimtex_viewer_skim* + http://skim-app.sourceforge.net/ + Skim is a PDF reader and note-taker for OS X. It is designed to help + you read and annotate scientific papers in PDF, but is also great + for viewing any PDF file. > + + let g:vimtex_view_general_viewer + \ = '/Applications/Skim.app/Contents/SharedSupport/displayline' + let g:vimtex_view_general_options = '@line @pdf @tex' +< + *vimtex_viewer_sumatrapdf* + http://www.sumatrapdfreader.org/free-pdf-reader.html + SumatraPDF is a PDF viewer for windows that is powerful, small, + portable and starts up very fast. It supports forward search. + Backward search must be set up from the viewer. > + + let g:vimtex_view_general_viewer = 'SumatraPDF' + let g:vimtex_view_general_options = '-forward-search @tex @line @pdf' + let g:vimtex_view_general_options_latexmk = '-reuse-instance' +< + Note: It is possible to set up inverse search for SumatraPDF through + the command line. This can be utilized to set the correct + |servername| for inverse search: > + + let g:vimtex_view_general_viewer = 'SumatraPDF -reuse-instance ' + \ . '-inverse-search "gvim --servername ' . v:servername + \ . ' --remote-send \"^^' + \ . ':drop \%f^:\%l^:normal\! zzzv^' + \ . ':execute ''drop '' . fnameescape(''\%f'')^' + \ . ':\%l^:normal\! zzzv^' + \ . ':call remote_foreground('''.v:servername.''')^\""' +< + *vimtex_viewer_mupdf* http://www.mupdf.com/ A very minimalistic and quick PDF viewer. Supports forward and backward search. Backward search is available with |VimtexRSearch|, which is @@ -606,38 +669,7 @@ Options~ search will take you to the line in Vim that corresponds to the first line of the current page in MuPDF. - okular~ - https://okular.kde.org/ - A very feature rich PDF viewer. Supports forward search. Backward - search must be set up from the viewer. - - qpdfview~ - https://launchpad.net/qpdfview - A tabbed document viewer. Supports forward search. Backward search - must be set up from the viewer. - - sumatrapdf~ - http://www.sumatrapdfreader.org/free-pdf-reader.html - SumatraPDF is a PDF viewer for windows that is powerful, small, portable - and starts up very fast. It supports forward search. Backward search - must be set up from the viewer. - - Note: It is possible to set up inverse search for SumatraPDF through the - command line. This can be utilized to improve the current - implementation in order to set the correct |servername| for - inverse search. At the moment, this is not implemented. However, - one can achieve the functionality by using the general viewer with - the following setting: > - - let g:vimtex_view_general_viewer = 'SumatraPDF -reuse-instance ' - \ . '-inverse-search "gvim --servername ' . v:servername - \ . ' --remote-send \"^^' - \ . ':drop \%f^:\%l^:normal\! zzzv^' - \ . ':execute ''drop '' . fnameescape(''\%f'')^' - \ . ':\%l^:normal\! zzzv^' - \ . ':call remote_foreground('''.v:servername.''')^\""' -< - zathura~ + *vimtex_viewer_zathura* https://pwmt.org/projects/zathura/ Zathura is like MuPDF a very fast and minimalistic viewer, but it allows more user configuration. Zathura supports forward search and backward @@ -646,21 +678,38 @@ Options~ Note: Forward search requires `xdotool` to work properly, in order to not open a new Zathura instance for invocation of |VimtexView|. - If one chooses a method that is not the default method, then the viewer will - support forward search, see |vimtex-synctex-forward-search|. - - Default value: 'general' - *g:vimtex_view_general_viewer* - Use a general viewer. + Use generic viewer application, see |vimtex_viewer_general|. Default value: Linux: `xdg-open` Mac: `open` -*g:vimtex_view__options* - Set custom options for the given viewer. See |g:vimtex_view_method| for - a list of possible viewers. +*g:vimtex_view_general_options* + Set options for the specified general viewer, see |vimtex_viewer_general|. + The options are parsed to substitute the following keywords: + + `@pdf` Path to pdf file + `@tex` Path to tex file + `@line` Current line number + `@col` Current column number + + Default value: '@pdf' + +*g:vimtex_view_general_options_latexmk* + Set options that are passed on to `latexmk` for the specified general + viewer, see |vimtex_viewer_general|. This allows to send options that + ensures a unique viewer, e.g. with |vimtex_viewer_qpdfview|. + + Default value: '' + +*g:vimtex_view_mupdf_options* + Set options for mupdf (|vimtex_viewer_mupdf|). + + Default value: '' + +*g:vimtex_view_zathura_options* + Set options for zathura (|vimtex_viewer_zathura|). Default value: ''