abstract
| - Add the following code to your tex.vim file (~/.vim/ftplugin/tex.vim on Unix, or $HOME/vimfiles/ftplugin/tex.vim on Windows). Also add one of the OpenPDF functions listed below, depending on your operating system. "Load PDF to the page containing label function! LoadEvinceByLabel(l) for f in split(glob("*.aux")) let label = system('grep "^.newlabel{' . a:l . '" ' . f) let page = matchstr(label, '.\{}{\zs.*\ze}}') if ! empty(page) call OpenPDF(substitute(f, "aux$", "pdf", ""), page) return endif endfor endfunction "Load PDF to the page containing the nearest previous label to the cursor function! EvinceNearestLabel() let line = search("\\label{", "bnW") if line > 0 let m = matchstr(getline(line), '\\label{\zs[^}]*\ze}') if empty(m) echomsg "No label between here and start of file" else call LoadEvinceByLabel(m) endif endif endfunction The first function looks through the aux files created by compiling the latex file for the label passed in as a parameter. If it finds the label, it loads the page number and then loads the pdf to the given page. If you use the hyperref package, replace the pattern '.\{}{\zs.*\ze}}' in the call to matchstr() in function LoadEvinceByLabel with: 'newlabel{.*}' This is because the hyperref package adds three additional fields after the page number to the label definition line in the .aux files. The second function searches for the nearest label from the current position and calls LoadEvinceByLabel. To use them, add something like: nnoremap e :call EvinceNearestLabel() Now \e will load the pdf viewer to the page containing the nearest label to the current cursor position (assuming the default backslash for the LocalLeader key). This works well on multi-file projects since the aux file is searched to find the pdf name. So you can jump around in Vim using its wonderful tools, then tell the pdf viewer to jump to the same page. If you have set up tags, you can also add: command! -nargs=1 -complete=tag Pdf call LoadEvinceByLabel("") to create command :Pdf so you can use Tab completion on labels to jump to a given location.
|