2017-06-08 11:47:56 +02:00
|
|
|
;;; lang/latex/config.el -*- lexical-binding: t; -*-
|
2016-05-08 18:27:28 -04:00
|
|
|
|
2018-01-01 20:48:23 +01:00
|
|
|
(defvar +latex-bibtex-file ""
|
|
|
|
"File AUCTeX (specifically RefTeX) uses to search for citations.")
|
|
|
|
|
2018-01-09 14:19:02 +01:00
|
|
|
(defvar +latex-bibtex-dir ""
|
2017-02-19 18:57:16 -05:00
|
|
|
"Where bibtex files are kept.")
|
|
|
|
|
2018-01-01 20:48:23 +01:00
|
|
|
(defvar +latex-indent-level-item-continuation 8
|
|
|
|
"Custom indentation level for items in enumeration-type environments")
|
2016-05-08 18:27:28 -04:00
|
|
|
|
|
|
|
|
2018-03-07 21:21:17 -05:00
|
|
|
;;
|
|
|
|
;; Plugins
|
|
|
|
;;
|
|
|
|
|
2018-05-29 12:46:13 +02:00
|
|
|
(after! tex
|
2018-01-01 20:48:23 +01:00
|
|
|
;; Set some varibles to fontify common LaTeX commands.
|
2018-05-27 12:44:22 +02:00
|
|
|
(load! "+fontification")
|
2018-05-29 12:46:13 +02:00
|
|
|
|
|
|
|
(setq TeX-parse-self t ; Enable parse on load.
|
|
|
|
TeX-save-query nil ; just save, don't ask
|
|
|
|
TeX-auto-save t ; Enable parse on save.
|
2018-01-01 20:48:23 +01:00
|
|
|
;; Use hidden directories for AUCTeX files.
|
|
|
|
TeX-auto-local ".auctex-auto"
|
|
|
|
TeX-style-local ".auctex-style"
|
2018-02-14 07:42:22 -05:00
|
|
|
;; When correlating sources to rendered PDFs, don't start the emacs
|
|
|
|
;; server
|
2017-02-19 18:57:16 -05:00
|
|
|
TeX-source-correlate-start-server nil
|
2018-01-01 20:48:23 +01:00
|
|
|
TeX-source-correlate-mode t
|
|
|
|
TeX-source-correlate-method 'synctex
|
|
|
|
;; Fonts for section, subsection, etc
|
|
|
|
font-latex-fontify-sectioning 1.15)
|
|
|
|
(setq-default TeX-master nil)
|
|
|
|
;; Display the output of the latex commands in a popup.
|
2018-01-06 01:23:22 -05:00
|
|
|
(set! :popup " output\\*$" '((size . 15)))
|
2017-03-08 21:30:16 -05:00
|
|
|
|
2018-01-01 20:48:23 +01:00
|
|
|
;; TeX Font Styling
|
2018-03-07 21:21:17 -05:00
|
|
|
;; (def-package! tex-style :defer t)
|
2018-01-01 20:48:23 +01:00
|
|
|
|
|
|
|
;; TeX Folding
|
2018-05-29 12:46:13 +02:00
|
|
|
(add-hook 'TeX-mode-hook #'TeX-fold-mode))
|
|
|
|
|
|
|
|
|
|
|
|
(after! latex
|
|
|
|
(setq LaTeX-section-hook ; Add the toc entry to the sectioning hooks.
|
|
|
|
'(LaTeX-section-heading
|
|
|
|
LaTeX-section-title
|
|
|
|
LaTeX-section-toc
|
|
|
|
LaTeX-section-section
|
|
|
|
LaTeX-section-label)
|
|
|
|
LaTeX-fill-break-at-separators nil
|
|
|
|
LaTeX-item-indent 0) ; item indentation.
|
|
|
|
|
2018-06-05 10:35:02 +02:00
|
|
|
(define-key LaTeX-mode-map "\C-j" nil)
|
2018-05-29 12:46:13 +02:00
|
|
|
|
|
|
|
;; 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-hook
|
|
|
|
#'(LaTeX-math-mode
|
2018-06-02 13:58:04 +02:00
|
|
|
TeX-source-correlate-mode
|
|
|
|
TeX-global-PDF-mode
|
|
|
|
TeX-PDF-mode
|
|
|
|
visual-line-mode))
|
2018-05-29 12:46:13 +02:00
|
|
|
;; Enable rainbow mode after applying styles to the buffer
|
|
|
|
(add-hook 'TeX-update-style-hook #'rainbow-delimiters-mode)
|
|
|
|
(when (featurep! :feature spellcheck)
|
|
|
|
(add-hook 'LaTeX-mode-hook #'flyspell-mode))
|
|
|
|
;; Use chktex to search for errors in a latex file.
|
|
|
|
(setcar (cdr (assoc "Check" TeX-command-list)) "chktex -v6 %s")
|
|
|
|
;; Set a custom item indentation
|
|
|
|
(dolist (env '("itemize" "enumerate" "description"))
|
|
|
|
(map-put LaTeX-indent-environment-list
|
|
|
|
env '(+latex/LaTeX-indent-item)))
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Use Okular if the user says so.
|
|
|
|
(when (featurep! +okular)
|
|
|
|
;; Configure Okular as viewer. Including a bug fix
|
|
|
|
;; (https://bugs.kde.org/show_bug.cgi?id=373855)
|
|
|
|
(map-put TeX-view-program-list
|
|
|
|
"Okular" '(("okular --unique file:%o" (mode-io-correlate "#src:%n%a"))))
|
|
|
|
(map-put TeX-view-program-list 'output-pdf '("Okular")))
|
|
|
|
|
|
|
|
;; Or Skim
|
|
|
|
(when (featurep! +skim)
|
|
|
|
(map-put TeX-view-program-list
|
|
|
|
"Skim" '("/Applications/Skim.app/Contents/SharedSupport/displayline -b -g %n %o %b"))
|
|
|
|
(map-put TeX-view-program-selection 'output-pdf '("Skim")))
|
|
|
|
|
|
|
|
;; Or PDF-tools, but only if the module is also loaded
|
|
|
|
(when (and (featurep! :tools pdf)
|
|
|
|
(featurep! +pdf-tools))
|
|
|
|
(map-put TeX-view-program-list "PDF Tools" '("TeX-pdf-tools-sync-view"))
|
|
|
|
(map-put TeX-view-program-selection 'output-pdf '("PDF Tools"))
|
|
|
|
;; Enable auto reverting the PDF document with PDF Tools
|
|
|
|
(add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer)))
|
|
|
|
|
|
|
|
|
|
|
|
;; The preview package is currently broken with the latest AUCTeX version
|
|
|
|
;; ("11.90.2.2017-07-25) ... and Ghostscript 9.22. It's now fixed in AUCTeX
|
|
|
|
;; master, so we just have to wait.
|
2018-01-01 20:48:23 +01:00
|
|
|
(def-package! preview
|
2018-05-29 12:46:13 +02:00
|
|
|
:hook (LaTeX-mode . LaTeX-preview-setup)
|
|
|
|
:config
|
2018-03-07 21:21:17 -05:00
|
|
|
(setq-default preview-scale 1.4
|
2018-05-09 12:31:24 +02:00
|
|
|
preview-scale-function
|
2018-05-29 12:46:13 +02:00
|
|
|
(lambda () (* (/ 10.0 (preview-document-pt)) preview-scale))))
|
2018-05-09 12:31:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
(def-package! latex-preview-pane
|
|
|
|
:when (featurep! +preview-pane)
|
2018-05-29 12:46:13 +02:00
|
|
|
:hook ((latex-mode LaTeX-mode) . latex-preview-pane-enable)
|
|
|
|
:commands latex-preview-pane-mode
|
2018-05-09 12:31:24 +02:00
|
|
|
:init
|
|
|
|
(setq latex-preview-pane-multifile-mode 'auctex)
|
2018-05-30 00:37:38 +02:00
|
|
|
:config
|
2018-05-09 12:31:24 +02:00
|
|
|
(map-put TeX-view-program-list "preview-pane" '(latex-preview-pane-mode))
|
|
|
|
(map-put TeX-view-program-selection 'output-pdf '("preview-pane"))
|
2018-06-03 15:46:00 +02:00
|
|
|
(define-key! doc-view-mode-map
|
|
|
|
(kbd "ESC") #'delete-window
|
|
|
|
"q" #'delete-window
|
|
|
|
"k" (λ! (quit-window) (delete-window))))
|
2018-05-09 12:31:24 +02:00
|
|
|
|
2017-03-08 21:30:16 -05:00
|
|
|
|
2018-01-01 20:48:23 +01:00
|
|
|
(def-package! reftex
|
2018-05-29 12:46:13 +02:00
|
|
|
:hook ((latex-mode LaTeX-mode) . turn-on-reftex)
|
2017-03-08 21:30:16 -05:00
|
|
|
:init
|
|
|
|
(setq reftex-plug-into-AUCTeX t
|
2018-01-01 20:48:23 +01:00
|
|
|
reftex-toc-split-windows-fraction 0.3)
|
2018-04-11 13:02:58 +02:00
|
|
|
:config
|
2018-03-07 21:21:17 -05:00
|
|
|
;; Get ReTeX working with biblatex
|
|
|
|
;; http://tex.stackexchange.com/questions/31966/setting-up-reftex-with-biblatex-citation-commands/31992#31992
|
2018-01-01 20:48:23 +01:00
|
|
|
(setq reftex-cite-format
|
|
|
|
'((?t . "\\textcite[]{%l}")
|
|
|
|
(?a . "\\autocite[]{%l}")
|
|
|
|
(?c . "\\cite[]{%l}")
|
|
|
|
(?s . "\\smartcite[]{%l}")
|
|
|
|
(?f . "\\footcite[]{%l}")
|
|
|
|
(?n . "\\nocite{%l}")
|
|
|
|
(?b . "\\blockcquote[]{%l}{}")))
|
2018-05-09 12:31:24 +02:00
|
|
|
(unless (string-empty-p +latex-bibtex-file)
|
|
|
|
(setq reftex-default-bibliography (list (expand-file-name +latex-bibtex-file))))
|
2017-03-08 21:30:16 -05:00
|
|
|
(map! :map reftex-mode-map
|
2017-06-19 00:30:41 +02:00
|
|
|
:localleader :n ";" 'reftex-toc)
|
2017-03-09 00:27:50 -05:00
|
|
|
(add-hook! 'reftex-toc-mode-hook
|
|
|
|
(reftex-toc-rescan)
|
2017-07-27 01:00:28 +02:00
|
|
|
(map! :local
|
|
|
|
:e "j" #'next-line
|
|
|
|
:e "k" #'previous-line
|
|
|
|
:e "q" #'kill-buffer-and-window
|
2018-01-01 20:48:23 +01:00
|
|
|
:e "ESC" #'kill-buffer-and-window
|
|
|
|
"C-g" #'reftex-toc-quit)))
|
2017-02-19 18:57:16 -05:00
|
|
|
|
2018-05-09 12:31:24 +02:00
|
|
|
|
2018-01-01 20:48:23 +01:00
|
|
|
(def-package! bibtex
|
2017-12-08 22:33:12 -05:00
|
|
|
:defer t
|
2017-02-19 18:57:16 -05:00
|
|
|
:config
|
|
|
|
(setq bibtex-dialect 'biblatex
|
2016-05-08 18:27:28 -04:00
|
|
|
bibtex-align-at-equal-sign t
|
2018-05-09 12:31:24 +02:00
|
|
|
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))))
|
2018-06-03 15:46:00 +02:00
|
|
|
(define-key bibtex-mode-map (kbd "C-c \\") #'bibtex-fill-entry))
|
2017-02-19 18:57:16 -05:00
|
|
|
|
2018-01-01 20:48:23 +01:00
|
|
|
|
|
|
|
(def-package! auctex-latexmk
|
|
|
|
:when (featurep! +latexmk)
|
2018-05-29 12:46:13 +02:00
|
|
|
:after-call (latex-mode-hook LaTeX-mode-hook)
|
2018-01-01 20:48:23 +01:00
|
|
|
:init
|
|
|
|
;; Pass the -pdf flag when TeX-PDF-mode is active
|
|
|
|
(setq auctex-latexmk-inherit-TeX-PDF-mode t)
|
|
|
|
;; Set LatexMk as the default
|
2018-05-09 12:31:24 +02:00
|
|
|
(setq-hook! LaTeX-mode TeX-command-default "LatexMk")
|
2018-01-01 20:48:23 +01:00
|
|
|
:config
|
|
|
|
;; Add latexmk as a TeX target
|
|
|
|
(auctex-latexmk-setup))
|
2017-06-11 00:59:02 +02:00
|
|
|
|
2018-05-09 12:31:24 +02:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! ivy-bibtex
|
2017-03-19 22:47:50 -04:00
|
|
|
:when (featurep! :completion ivy)
|
2018-01-01 20:48:23 +01:00
|
|
|
:commands ivy-bibtex
|
2018-05-09 12:31:24 +02:00
|
|
|
:config (setq ivy-bibtex-default-action 'ivy-bibtex-insert-key))
|
|
|
|
|
2017-06-11 00:59:02 +02:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! helm-bibtex
|
2017-03-19 22:47:50 -04:00
|
|
|
:when (featurep! :completion helm)
|
2018-05-09 12:31:24 +02:00
|
|
|
:commands helm-bibtex)
|
|
|
|
|
2018-01-04 14:50:59 -05:00
|
|
|
|
|
|
|
(def-package! company-auctex
|
|
|
|
:when (featurep! :completion company)
|
2018-01-01 20:48:23 +01:00
|
|
|
:commands (company-auctex-init)
|
2018-01-04 14:50:59 -05:00
|
|
|
:init
|
|
|
|
;; We can't use the (set! :company-backend ...) because Auctex reports its
|
2018-02-14 07:42:22 -05:00
|
|
|
;; major-mode as `latex-mode', but uses LaTeX-mode-hook for its mode, which is
|
|
|
|
;; not anticipated by :company-backend (and shouldn't have to!)
|
2018-01-04 14:50:59 -05:00
|
|
|
(add-hook! LaTeX-mode
|
|
|
|
(make-variable-buffer-local 'company-backends)
|
|
|
|
(company-auctex-init)))
|
2018-01-01 20:48:23 +01:00
|
|
|
|
2018-05-09 12:31:24 +02:00
|
|
|
|
2018-01-01 20:48:23 +01:00
|
|
|
;; Nicely indent lines that have wrapped when visual line mode is activated
|
|
|
|
(def-package! adaptive-wrap
|
2018-05-29 12:46:13 +02:00
|
|
|
:hook (LaTeX-mode . adaptive-wrap-prefix-mode)
|
|
|
|
:init (setq-default adaptive-wrap-extra-indent 0))
|