0

I'm learning how to use use-package, and I've some troubles to make it work with the Auctex packages (all the other packages are fine). I made my own function configure-viewer that basically adds a PDF viewer to TeX-view-program-selection depending on desktop environment. If I do (add-hook 'LaTeX-mode-hook 'configure-viewer), then it works, however, it's not really "use-package compliant". So I tried lot's of tricks to make it work, with :hooks, on the package tex, auctex... But as I don't really understand what's the link between auctex, tex, tex-site... I don't manage to make it work properly. For now here is what I do, and it works, but it looks ugly (see that I don't even use any hooks).

What is the good way to combine Auctex and use-package?

(defun get-desktop-environment ()
  (interactive)
  (let (
    ;; Create new variable with DE name
    (de_env (or (getenv "XDG_CURRENT_DESKTOP") ""))
    ;; Make sure search is case insensitive
    (case-fold-search t))
    (cond ((eq system-type 'darwin)
       "darwin")
      ((memq system-type '(windows-nt ms-dos cygwin))
       "windows")
      ((string-match ".*kde.*" de_env)
       "kde")
      ((string-match ".*gnome.*" de_env)
       "gnome")
      ((string-match ".*unity.*" de_env)
       "unity")
      ((string-match ".*xfce.*" de_env)
       "xfce")
      ((string-match ".*lxde.*" de_env)
       "lxde")
      ((string-match ".*mate.*" de_env)
       "mate")
      ((string-match ".*cinnamon.*" de_env)
       "cinnamon")
      (t "unknown"))))

(defun get-pdf-viewer ()
  (alist-get (get-desktop-environment)
         '(("kde" . ("Okular"))
           ("gnome" . ("Evince"))
           ("xfce" . ("Evince")))
         '("xdg-open") nil 'equal))

(defun configure-viewer ()
  ;; Update the viewer depending on the graphical desktop
  (setcdr (assq 'output-pdf TeX-view-program-selection) (get-pdf-viewer)))


(use-package tex-site
  :ensure auctex
  :init
  (require 'latex) ;; #### /!\ /!\ /!\ This line is strange no? a require in a usepackage file...
  (configure-viewer) ;; #### /!\ /!\ /!\ This line should be loaded with hooks no?
  (setq TeX-source-correlate-mode t
    TeX-source-correlate-start-server t))

;; Compile with latexmk:
(use-package auctex-latexmk
  :ensure t
  :config
  (auctex-latexmk-setup)
  (setq auctex-latexmk-inherit-TeX-PDF-mode t))


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.