Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using vim to edit my tex files and I use latex suite as a plugin to compile my tex sources and view them in using Okular pdf viewer.

Setting the following in Okular settings makes inverse search work perfectly

gvim --servername GVIM --remote +%l %f

But having looked on the web and tried different ways to make forward search work within vim with latex suite, forward search is still working only partly for me in vim. I'm only able to do forward search with \ls in the main tex file. If I do \ls inside an include or input file then Okular would complain that it can't find the particular pdf for that include/input file which is true because only the main tex file has a pdf compiled.

I also tried a custom function which I found from an answer to a similar question here on TeXExchange: http://tex.stackexchange.com/a/2947/2031 but the path passed to Okular with this command is just a concatenation of the paths to both the main pdf and tex files.

Below are my current settings in my .vimrc related to this question:

let g:Tex_CompileRule_pdf = 'pdflatex -synctex=1 -src-specials -interaction=nonstopmode $*'
let g:Tex_ViewRule_pdf = 'okular --unique'
function! SyncTexForward()
     let execstr = "silent !okular --unique %:p:r.pdf\#src:".line(".")."%:p &"
     exec execstr
endfunction
nmap <Leader>f :call SyncTexForward()<CR>
share|improve this question

1 Answer 1

up vote 2 down vote accepted

I had exact the same problem. Modifying the function to pass the correct paths did the trick, at least for me. Here is the code:

function! SyncTexForward()
let s:syncfile = fnamemodify(fnameescape(Tex_GetMainFileName()), ":r").".pdf"
let execstr = "silent !okular --unique ".s:syncfile."\\#src:".line(".").expand("%\:p").' &'
exec execstr
endfunction
nnoremap <Leader>f :call SyncTexForward()<CR>
share|improve this answer
    
Many thanks! That worked. Just one thing to note that in order for Tex_GetMainFileName() to work properly one should have a {main tex file name}.latexmain file in the same directory with their main tex file (as described here vim-latex.sourceforge.net/documentation/latex-suite/…) –  ld_pvl Nov 22 '12 at 21:43
    
That's correct. Tex_GetMainFileName() is also used by other plugins. I have Latex-Box installed. The function is defined in the file findmain.vim. So you can copy the function in your own tex.vim and get rid of any plugins if you wish so. –  panos Nov 23 '12 at 6:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.