Mac – Emacs Auctex: How to open the pdf in evince at the current cursor position

auctexemacsevincelatex

I use emacs auctex to write latex files. Since the text is pretty long, and I tend to change things in different places, I would like emacs to open the pdf so that the position in the text is shown that the cursor is at in the source file.

I have seen this on a windows machine with MikTex/Texniccenter/Acroreader. Is it possible to do this on Ubuntu in emacs/auctex/evince?

Best Answer

To do this you need add the following lines to your .emacs file so that when you view the pdf using evince it will tell evince the page number:

(setq TeX-view-program-list '(("Evince" "evince --page-index=%(outpage) %o")))
(setq TeX-view-program-selection '((output-pdf "Evince")))

Then once you've opened your tex file in emacs you need to turn on source correlation using the command:

C-c C-t C-s

Or if you don't want to start it manually every time then add the following line to your .emacs:

(add-hook 'LaTeX-mode-hook 'TeX-source-correlate-mode)

Also, if you want to prevent emacs from promting you if you want to start a correlation server then add the following line:

(setq TeX-source-correlate-start-server t)

And that should be it.

Edit: actually, it turns out that you shouldn't use the package pdfsync, so I've removed all reference to it. It isn't needed for this solution (apparently it's now built into all TeX-based engines) and using it actually seems to cause problems (for me it seems to break code using tables).

Edit 2: I was having problems with auto-enabling TeX-source-correlate-mode using .emacs, but now they seem to have gone. Not sure if that's because I updated emacs or because I removed pdfsync. Anyway, that works now :)

Related Question