Skip to content

Instantly share code, notes, and snippets.

@mbenke
Created September 24, 2012 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbenke/3775888 to your computer and use it in GitHub Desktop.
Save mbenke/3775888 to your computer and use it in GitHub Desktop.
Make synctex work with Emacs 23.3.1 and evince 3.4
;; Based on http://tex.stackexchange.com/questions/29813/setup-synctex-with-emacs/49840#49840
;; replacing setf with setq
;; Use Evince as default viewer C-c C-v
(setq TeX-view-program-list '(("Evince" "evince %o"))
TeX-view-program-selection '((output-pdf "Evince")))
;;; Backward search Evince to AUCTeX adapted from http://www.emacswiki.org/emacs/AUCTeX#toc19
(add-hook 'LaTeX-mode-hook 'TeX-source-correlate-mode)
(setq TeX-source-correlate-start-server t); Automatically start server without asking
(defun un-urlify (fname-or-url)
"A trivial function that replaces a prefix of file:/// with just /."
(if (string= (substring fname-or-url 0 8) "file:///")
(substring fname-or-url 7)
fname-or-url))
(defun th-evince-sync (file linecol &rest ignored)
(let* ((fname (un-urlify file))
(buf (find-buffer-visiting fname))
(line (car linecol))
(col (cadr linecol)))
(if (null buf)
(message "[Synctex]: %s is not opened..." fname)
(switch-to-buffer buf)
(goto-line (car linecol))
(unless (= col -1)
(move-to-column col)))))
(defvar *dbus-evince-signal* nil)
(defun enable-evince-sync ()
(require 'dbus)
(when (and
(eq window-system 'x)
(fboundp 'dbus-register-signal))
(unless *dbus-evince-signal*
(setq *dbus-evince-signal* ;; note: original used setf instead of setq here
(dbus-register-signal
:session nil "/org/gnome/evince/Window/0"
"org.gnome.evince.Window" "SyncSource"
'th-evince-sync)))))
(add-hook 'LaTeX-mode-hook 'enable-evince-sync)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment