2

There is a great way to make Emacs, Evince and Synctex work together. However it has a minor caveat: when you do backward search, focus is not moved to Emacs (so you have to do that using mouse or Alt+Tab). This is a slight but nonetheless untoward problem.

In Linux (which I use) there is a CLI utility called wmctrl which can be used to move focus between windows. However I don't know how to add it to the script mentioned above, so I decided to ask.

(I believe the main point of this question is using Emacs Lisp so it is less relevant to Ask Ubuntu).

2

Add the following code, taken from https://lists.gnu.org/archive/html/bug-auctex/2013-04/msg00004.html, to your .emacs

(defun raise-client-frame ()
  (let ((wmctrl (executable-find "wmctrl")))
    (if wmctrl
    (start-process "wmctrl" nil wmctrl "-R" (frame-parameter nil 'name)))))
;; This raises the frame when using Evince.
(add-hook 'TeX-source-correlate-mode-hook
      (lambda ()
        (when (TeX-evince-dbus-p)
          (dbus-register-signal
           :session nil "/org/gnome/evince/Window/0"
           "org.gnome.evince.Window" "SyncSource"
           (lambda (file linecol &rest ignored)
         (TeX-source-correlate-sync-source file linecol ignored)
         (raise-client-frame))))))
;; This raises the frame when using all other viewers.
(add-hook 'server-switch-hook 'raise-client-frame)

Current version of AUCTeX supports forward/inverse search with Evince out-of-the-box, there is no more need to use old hacks.

|improve this answer|||||
  • Sorry, didn't work. (I have the latest Ubuntu versions of the three programs installed.) – Reza Apr 10 '14 at 16:48
  • @Reza did you restart Emacs after adding that code? – giordano Apr 10 '14 at 17:09
  • Yes, I did. Does where you put it in .emacs (w.r.t. the synctex scrip) matter? – Reza Apr 11 '14 at 15:47
  • @Reza Ok, you're right, that hook isn't run when Evince is used as viewer (it's run with Okular, the viewer I use). I'll try another way to answer your question, hold on! – giordano Apr 11 '14 at 18:46
  • @Reza See the updated answer, now this should work for all viewers, Evince included. – giordano Apr 11 '14 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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