Some TeX/LaTeX editor has support for embedding PDF viewer, and forward/backward search support.

I want to configure AUCTeX and pdf-tools to this result.

I found a discussion in mailing list.


It give out a method to implement this opening PDF file with pdf-tools in Emacs. I followed that, but it does not work.

Here is my config:

(require 'tex-site)
(require 'latex)

;;; AUCTeX config
(setq TeX-auto-save t
      TeX-parse-self t)

(setq-default TeX-master nil)

;; automatic detection of master file
(defun guess-TeX-master (filename)
  "Guess the master file for FILENAME from currently open .tex files."
  (let ((candidate nil)
        (filename (file-name-nondirectory filename)))
      (dolist (buffer (buffer-list))
        (with-current-buffer buffer
          (let ((name (buffer-name))
                (file buffer-file-name))
            (if (and file (string-match "\\.tex$" file))
                  (goto-char (point-min))
                  (if (re-search-forward (concat "\\\\input{" filename "}") nil t)
                      (setq candidate file))
                  (if (re-search-forward (concat "\\\\include{" (file-name-sans-extension filename) "}") nil t)
                      (setq candidate file))))))))
    (if candidate
        (message "TeX master document: %s" (file-name-nondirectory candidate)))

(add-hook 'LaTeX-mode-hook
          '(lambda ()
             (setq TeX-master (guess-TeX-master (buffer-file-name)))

;; enable RefTeX in AUCTeX (LaTeX-mode)
(setq reftex-plug-into-AUCTeX t)
(add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
(add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode

;; view generated PDF with `pdf-tools'.
(unless (assoc "PDF Tools" TeX-view-program-list-builtin)
  (add-to-list 'TeX-view-program-list-builtin
               '("PDF Tools" TeX-pdf-tools-sync-view)))
(add-to-list 'TeX-view-program-selection
             '(output-pdf "PDF Tools"))

;; LaTeX source code block syntax highlighting.
;; [ minted ]
;; toggle shell escape using [C-c C-t x].
(defun TeX-toggle-escape ()
  "Toggle Shell Escape"
  (setq-local LaTeX-command
              (if (string= LaTeX-command "latex") "latex -shell-escape"
  (message (concat "shell escape "
                   (if (string= LaTeX-command "latex -shell-escape")
(add-hook 'LaTeX-mode-hook
          '(lambda ()
             (local-set-key (kbd "C-c C-t x") 'TeX-toggle-escape)))

1 Answer 1


Here's my setup, using auctex-11.89 and pdf-tools-20151224.1159:

;; Use pdf-tools to open PDF files
(setq TeX-view-program-selection '((output-pdf "PDF Tools"))
      TeX-source-correlate-start-server t)

;; Update PDF buffers after successful LaTeX runs
(add-hook 'TeX-after-compilation-finished-functions
  • 2
    Only a comment: TeX-PDF-mode is active by default since AUCTeX 11.88.
    – giordano
    Commented Jan 12, 2016 at 17:40
  • I tried your method, it can work when I try with emacs -q and load packages. but has problem with my configs. Is there a way to find out why? Commented Jan 13, 2016 at 10:25
  • Only thing I can think of: bisect your config file, commenting out piece by piece, trying to nailing it down to the code that is in conflict with my solution. Commented Jan 13, 2016 at 12:19
  • 1
    FYI: I couldn't find TeX-after-TeX-LaTeX-command-finished-hook. TeX-after-compilation-finished-functions now appears to be the relevant hook (or so the docstring says).
    – Dan
    Commented Jul 27, 2016 at 14:42
  • @Dan At least for version 12.1 (2017-12-04), I only see TeX-after-compilation-finished-hook in the AUCTeX manual. I think it is no longer either TeX-after-TeX-LaTeX-command-finished-hook or TeX-after-compilation-finished-functions.
    – Adam Liter
    Commented Aug 20, 2018 at 2:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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