如何让AUCTeX使用pdf-tools打开PDF


11

某些TeX / LaTeX编辑器支持嵌入PDF查看器,并且支持向前/向后搜索。

我想为此配置AUCTeX和pdf工具。

我在邮件列表中找到了讨论。

https://lists.gnu.org/archive/html/auctex/2015-02/msg00013.html

给出了在Emacs中使用pdf-tools实现此打开的PDF文件的方法。我遵循了,但是没有用。

这是我的配置:

(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)))
    (save-excursion
      (dolist (buffer (buffer-list))
        (with-current-buffer buffer
          (let ((name (buffer-name))
                (file buffer-file-name))
            (if (and file (string-match "\\.tex$" file))
                (progn
                  (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)))
    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"
  (interactive)
  (setq-local LaTeX-command
              (if (string= LaTeX-command "latex") "latex -shell-escape"
                "latex"))
  (message (concat "shell escape "
                   (if (string= LaTeX-command "latex -shell-escape")
                       "enabled"
                     "disabled"))
           ))
(add-hook 'LaTeX-mode-hook
          '(lambda ()
             (local-set-key (kbd "C-c C-t x") 'TeX-toggle-escape)))

Answers:


13

这是我的设置,使用auctex-11.89pdf-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
           #'TeX-revert-document-buffer)

2
仅注释:TeX-PDF-mode自AUCTeX 11.88起默认为活动状态。
giordano

我尝试了您的方法,当我尝试emacs -q并加载软件包时它可以工作。但是我的配置有问题。有办法找出原因吗?
stardiviner

我唯一想到的是:将配置文件一分为二,逐个注释,尝试将其固定在与我的解决方案冲突的代码上。
Manuel Uberti

1
仅供参考:我找不到TeX-after-TeX-LaTeX-command-finished-hookTeX-after-compilation-finished-functions现在似乎是相关的钩子(或文档字符串这样说)。

@Dan至少对于版本12.1(2017-12-04),我只TeX-after-compilation-finished-hookAUCTeX手册中看到。我认为它不再是TeX-after-TeX-LaTeX-command-finished-hookTeX-after-compilation-finished-functions
亚当·里特(Adam Liter)'18
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.