0

I am trying to set pdf-tools as my default pdf viewer when using AUCTeX. I found some guidance elsewhere on StackExchange but it doesn't get me to a solution.

As per the thread highlighted, I have the following in init.el.

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

;; Update PDF buffers after successful LaTeX runs
(add-hook 'TeX-after-compilation-finished-functions
           #'TeX-revert-document-buffer)

The .pdf file opens automatically, but in Fundamental mode. I have PDF Tools installed, and if I then enter M-x pdf-view-mode it displays fine.

I also have the following in my init.el, though if I comment it out, it doesn't make a difference.

  (setq TeX-auto-save t)
    (setq TeX-parse-self t)
    (setq-default TeX-master nil)
    (add-hook 'LaTeX-mode-hook 'visual-line-mode)
    (add-hook 'LaTeX-mode-hook 'flyspell-mode)
    (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
    (add-hook 'LaTeX-mode-hook 'turn-on-reftex)
    (setq reftex-plug-into-AUCTeX t)
(setq TeX-PDF-mode t)

Any suggestions greatly appreciated.

EDIT

I tried following @Fran's suggestion, but it still doesn't work. I should have mentioned I am using Emacs 27.2 and AUCTeX 13.1.3. I am using MacOS 12.0.1. For debugging purposes I have the following minimal init.el. The problem persists with the following.

;; Initialize package sources
(require 'package)

(setq package-archives '(("melpa" . "https://melpa.org/packages/")
                         ("org" . "https://orgmode.org/elpa/")
                         ("elpa" . "https://elpa.gnu.org/packages/")))


(package-initialize)
(unless package-archive-contents
 (package-refresh-contents))

;; Initialize use-package on non-Linux platforms
(unless (package-installed-p 'use-package)
   (package-install 'use-package)) 

(require 'use-package)
(setq use-package-always-ensure t)
    
(use-package tex
  :ensure auctex)

(use-package pdf-tools
  :ensure t
  :pin manual
  :config
  (setq pdf-info-epdfinfo-program "/usr/local/bin/epdfinfo"))


 (setq TeX-view-program-selection '((output-pdf "PDF Tools"))
       TeX-source-correlate-start-server t)

 (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer)
Lindsay
  • 23
  • 5
  • 2
    Does this answer your question? [How to use pdf-tools (pdf-view-mode) in emacs?](https://emacs.stackexchange.com/questions/19686/how-to-use-pdf-tools-pdf-view-mode-in-emacs) – Tyler May 26 '22 at 01:35

2 Answers2

0

The following works for me:

(setq TeX-view-program-selection '((output-pdf "PDF Tools"))
      TeX-source-correlate-start-server t)

(add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer)

There should be no need to set TeX-view-program-list.

This with emacs 28.1 and auctex 13.1.13.

Fran Burstall
  • 3,665
  • 10
  • 18
  • Thanks Fran. This doesn't solve my problem, but it did make me think that I didn't provide enough or clear enough info in my initial post. I have edited it accordingly. – Lindsay May 23 '22 at 08:33
0

Touch wood, but I think I have solved my own problem. After some googling and trying many things I found this post. Using that I amended my use-package configuration to include the following line: :mode ("\\.pdf\\'" . pdf-view-mode). The whole configuration command for pdf-tools now is as follows:

(use-package pdf-tools :ensure t :mode ("\.pdf\'" . pdf-view-mode) :pin manual :config (setq pdf-info-epdfinfo-program "/usr/local/bin/epdfinfo"))

I must say I still don't understand fully. I can see that the mode setting is basically telling emacs to open any .pdf file with pdf-view-mode. And I can see that this might be sufficient, and even elegant, but I still can't see why it was necessary.

I want to play with this some more to see if it /really/ works for all cases, but for now I am posting this in case others benefit. I will accept this answer in a couple of days if it works reliably.

Lindsay
  • 23
  • 5