Skip to content
Jdogzz edited this page Feb 13, 2021 · 4 revisions

Here is a sample config which links EAF with the LaTeX compiler in emacs. When a .tex file is open, the Command>Compile and view (C-c C-a) option will compile the .tex file into a .pdf file and display it using EAF.

(add-to-list 'load-path "~/emacs/emacs-application-framework/")
(require 'eaf)
(eaf-setq eaf-browser-dark-mode "true")
(eaf-setq eaf-terminal-dark-mode "false")
(eaf-setq eaf-mindmap-dark-mode "follow") ; default option
(eaf-setq eaf-pdf-dark-mode "ignore")
(eaf-setq eaf-browser-enable-adblocker "true")
(eaf-bind-key scroll_up "C-n" eaf-pdf-viewer-keybinding)
(eaf-bind-key scroll_down "C-p" eaf-pdf-viewer-keybinding)

;; from TeX-pdf-tools-sync-view
;;;###autoload
(defun TeX-eaf-sync-view()
  (unless (fboundp 'eaf-open)
    (error "EAF is not available!"))
  (let* ((pdf (TeX-active-master (TeX-output-extension)))
         (url (expand-file-name pdf))
         (app-name "pdf-viewer")
         (exists-eaf-buffer)
         (eaf-buffer-window))
    (catch 'found-match-buffer
      (dolist (buffer (buffer-list))
        (set-buffer buffer)
        (when (equal major-mode 'eaf-mode)
          (when (and (string= buffer-url url)
                     (string= buffer-app-name app-name))
            (setq exists-eaf-buffer buffer)
            (setq eaf-buffer-window (get-buffer-window exists-eaf-buffer))
            (throw 'found-match-buffer t)))))
    (if (and exists-eaf-buffer eaf-buffer-window)
        (pop-to-buffer exists-eaf-buffer)
      (eaf-open url app-name "--synctex_on=True"))))

(eval-after-load "tex"
  '(progn
	(add-to-list 'TeX-view-program-list '("eaf" TeX-eaf-sync-view))
(add-to-list 'TeX-view-program-selection '(output-pdf "eaf"))
))
Clone this wiki locally