             LaTeX-section-label)
           LaTeX-fill-break-at-separators nil
           LaTeX-item-indent 0) ; item indentation.
-    :config
+
     (map! :map LaTeX-mode-map "C-j" nil)
+
     ;; Do not prompt for Master files, this allows auto-insert to add templates
     ;; to .tex files
     (add-hook! '(LaTeX-mode TeX-mode)
       (remove-hook 'find-file-hook (car find-file-hook) 'local))
     ;; Adding useful things for latex
-    (add-hook! LaTeX-mode
-      (LaTeX-math-mode)
-      (TeX-source-correlate-mode)
-      (TeX-global-PDF-mode t)
-      (TeX-PDF-mode t)
-      (visual-line-mode +1))
+    (add-hook! 'LaTeX-mode-hook
+      #'(LaTeX-math-mode
+         TeX-source-correlate-mode
+         TeX-global-PDF-mode
+         TeX-PDF-mode
+         visual-line-mode))
     ;; Enable rainbow mode after applying styles to the buffer
     (add-hook 'TeX-update-style-hook #'rainbow-delimiters-mode)
     (when (featurep! :feature spellcheck)

          (?f . "\\footcite[]{%l}")
          (?n . "\\nocite{%l}")
          (?b . "\\blockcquote[]{%l}{}")))
  (map! :map reftex-mode-map
        :localleader :n ";" 'reftex-toc)
  (add-hook! 'reftex-toc-mode-hook

          :e "ESC" #'kill-buffer-and-window
          "C-g"    #'reftex-toc-quit)))


(def-package! bibtex
  :defer t
  :mode ("\\.bib\\'" . bibtex-mode)
  :config
  (setq bibtex-dialect 'biblatex
        bibtex-align-at-equal-sign t
        bibtex-text-indentation 20)
  (unless (string-empty-p +latex-bibtex-file)
    (setq bibtex-completion-bibliography (list (expand-file-name +latex-bibtex-file))))
  (unless (string-empty-p +latex-bibtex-dir)
    (setq bibtex-completion-library-path (list +latex-bibtex-dir)
          bibtex-completion-pdf-field "file"
          bibtex-completion-notes-path (expand-file-name "notes.org" +latex-bibtex-dir)
          bibtex-completion-pdf-open-function
          (lambda (fpath) (async-start-process "open-pdf" "/usr/bin/xdg-open" nil fpath))))
  (map! :map bibtex-mode-map "C-c \\" #'bibtex-fill-entry))


(def-package! auctex-latexmk
  :when (featurep! +latexmk)
  :init
  ;; Pass the -pdf flag when TeX-PDF-mode is active
  (setq auctex-latexmk-inherit-TeX-PDF-mode t)
  ;; Set LatexMk as the default
  (setq-hook! LaTeX-mode TeX-command-default "LatexMk")
  :config
  ;; Add latexmk as a TeX target
  (auctex-latexmk-setup))


(def-package! ivy-bibtex
  :when (featurep! :completion ivy)
  :commands ivy-bibtex
  :config (setq ivy-bibtex-default-action 'ivy-bibtex-insert-key))


(def-package! helm-bibtex
  :when (featurep! :completion helm)
  :commands helm-bibtex)


(def-package! company-auctex
  :when (featurep! :completion company)
