[Tex/LaTex] How to set up forward search: from .tex under Emacs to position .pdf under Okular

emacsforward-inverse-searchokularUbuntuviewers

I edit .tex file under Emacs and view them with Okular.

I have already set up the backward search: from .pdf to .tex by pressing Shift+Left click on the .pdf file. The related part of .emacs file is here:

(server-start)
(add-hook 'LaTeX-mode-hook 'TeX-PDF-mode) 

(defun pdf-with-okular ()
 (add-to-list 'TeX-output-view-style
 (quote ("^pdf$" "." "okular %o %(outpage)"))))

(add-hook 'LaTeX-mode-hook 'pdf-with-okular t)
(setq TeX-view-program-list '(("Okular" "okular %o"))) 
(setq TeX-view-program-selection '((output-pdf "Okular") (output-dvi "Okular")))

(custom-set-variables
 '(LaTeX-command "latex -synctex=1")
 '(cua-mode t nil (cua-base))
 '(show-paren-mode t))

However, I do not see how to make "forward" search work. Someone says when we position somewhere in the .tex file, press C-c C-v, we could go to the corresponding location of .pdf file. But here, when I press C-c C-v it opens another okular and we are always on the first page of the .pdf file.

P.S. My whole .emacs.

Best Answer

Try this instead:

okular --unique %o#src:%n%b

This is what I use and works fine. Should definitely not open another window with the --unique command so something else is up if that occurs. A similar solution is in link below but through the menus not in the .emacs file. Should just be able to use the command above with what you already have and should bring you to the line(%n) in the file when you run view or C-c C-v:

http://mathieu.3maisons.org/wordpress/how-to-configure-emacs-and-auctex-to-work-with-a-pdf-viewer