2017-06-08 11:47:56 +02:00
|
|
|
;;; lang/latex/config.el -*- lexical-binding: t; -*-
|
2016-05-08 18:27:28 -04:00
|
|
|
|
2018-06-08 16:10:00 +02:00
|
|
|
(defvar +latex-indent-level-item-continuation 4
|
2018-01-01 20:48:23 +01:00
|
|
|
"Custom indentation level for items in enumeration-type environments")
|
2016-05-08 18:27:28 -04:00
|
|
|
|
2018-07-30 02:38:42 +02:00
|
|
|
(defvar +latex-bibtex-file nil
|
2018-07-18 13:38:02 +02:00
|
|
|
"File AUCTeX (specifically RefTeX) uses to search for citations.")
|
|
|
|
|
2018-07-29 21:57:56 +02:00
|
|
|
(defvar +latex-enable-unicode-math nil
|
|
|
|
"If non-nil, use `company-math-symbols-unicode' backend in LaTeX-mode,
|
|
|
|
enabling unicode symbols in math regions. This requires the unicode-math latex
|
|
|
|
package to be installed.")
|
|
|
|
|
2019-08-27 00:11:52 -04:00
|
|
|
(defvar +latex-viewers '(skim evince sumatrapdf zathura okular pdf-tools)
|
2018-07-30 01:05:56 +02:00
|
|
|
"A list of enabled latex viewers to use, in this order. If they don't exist,
|
2019-09-28 18:28:48 +02:00
|
|
|
they will be ignored. Recognized viewers are skim, evince, sumatrapdf, zathura,
|
|
|
|
okular and pdf-tools.
|
2018-07-30 01:05:56 +02:00
|
|
|
|
|
|
|
If no viewers are found, `latex-preview-pane' is used.")
|
|
|
|
|
2018-07-29 21:57:56 +02:00
|
|
|
;;
|
|
|
|
(defvar +latex--company-backends nil)
|
|
|
|
|
|
|
|
|
2018-07-18 13:38:02 +02:00
|
|
|
;;
|
2018-09-07 19:36:16 -04:00
|
|
|
;; Packages
|
2018-07-18 13:38:02 +02:00
|
|
|
|
2019-09-24 20:47:41 -04:00
|
|
|
(add-to-list 'auto-mode-alist '("\\.tex\\'" . LaTeX-mode))
|
2018-12-06 19:07:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
(after! tex
|
|
|
|
(setq TeX-parse-self t ; parse on load
|
|
|
|
TeX-auto-save t ; parse on save
|
2018-07-18 13:38:02 +02:00
|
|
|
;; use hidden dirs for auctex files
|
2018-01-01 20:48:23 +01:00
|
|
|
TeX-auto-local ".auctex-auto"
|
|
|
|
TeX-style-local ".auctex-style"
|
|
|
|
TeX-source-correlate-mode t
|
|
|
|
TeX-source-correlate-method 'synctex
|
2018-07-18 13:38:02 +02:00
|
|
|
;; don't start the emacs server when correlating sources
|
|
|
|
TeX-source-correlate-start-server nil
|
|
|
|
;; automatically insert braces after sub/superscript in math mode
|
|
|
|
TeX-electric-sub-and-superscript t)
|
2018-07-30 02:38:42 +02:00
|
|
|
;; fontify common latex commands
|
|
|
|
(load! "+fontification")
|
|
|
|
;; select viewer
|
|
|
|
(load! "+viewers")
|
2018-07-18 13:38:02 +02:00
|
|
|
;; prompt for master
|
2018-01-01 20:48:23 +01:00
|
|
|
(setq-default TeX-master nil)
|
2018-07-18 13:38:02 +02:00
|
|
|
;; set-up chktex
|
2018-07-18 14:03:31 +02:00
|
|
|
(setcar (cdr (assoc "Check" TeX-command-list)) "chktex -v6 -H %s")
|
2018-07-18 14:04:23 +02:00
|
|
|
;; tell emacs how to parse tex files
|
2018-07-30 02:38:42 +02:00
|
|
|
(setq-hook! 'TeX-mode-hook ispell-parser 'tex)
|
|
|
|
;; Enable word wrapping
|
|
|
|
(add-hook 'TeX-mode-hook #'visual-line-mode)
|
|
|
|
;; Fold TeX macros
|
|
|
|
(add-hook 'TeX-mode-hook #'TeX-fold-mode)
|
2019-03-04 20:44:35 -05:00
|
|
|
;; Enable rainbow mode after applying styles to the buffer
|
|
|
|
(add-hook 'TeX-mode-hook #'rainbow-delimiters-mode)
|
2018-07-18 13:38:02 +02:00
|
|
|
;; display output of latex commands in popup
|
2018-06-18 02:26:05 +02:00
|
|
|
(set-popup-rule! " output\\*$" :size 15)
|
2018-07-18 13:38:02 +02:00
|
|
|
;; Do not prompt for Master files, this allows auto-insert to add templates to
|
|
|
|
;; .tex files
|
2018-07-30 02:38:42 +02:00
|
|
|
(add-hook! 'TeX-mode-hook
|
|
|
|
;; Necessary because it is added as an anonymous, byte-compiled function
|
|
|
|
(remove-hook 'find-file-hook
|
|
|
|
(cl-find-if #'byte-code-function-p find-file-hook)
|
|
|
|
'local))
|
2019-03-04 20:44:35 -05:00
|
|
|
(add-hook 'latex-mode-local-vars-hook #'flyspell-mode!)
|
2018-08-28 01:27:56 +02:00
|
|
|
(after! smartparens-latex
|
|
|
|
(let ((modes '(tex-mode plain-tex-mode latex-mode LaTeX-mode)))
|
2019-09-11 23:32:46 -04:00
|
|
|
;; All these excess pairs dramatically slow down typing in latex buffers,
|
|
|
|
;; so we remove them. Let snippets do their job.
|
2018-08-28 01:27:56 +02:00
|
|
|
(dolist (open '("\\left(" "\\left[" "\\left\\{" "\\left|"
|
|
|
|
"\\bigl(" "\\biggl(" "\\Bigl(" "\\Biggl(" "\\bigl["
|
|
|
|
"\\biggl[" "\\Bigl[" "\\Biggl[" "\\bigl\\{" "\\biggl\\{"
|
|
|
|
"\\Bigl\\{" "\\Biggl\\{"
|
|
|
|
"\\lfloor" "\\lceil" "\\langle"
|
|
|
|
"\\lVert" "\\lvert" "`"))
|
2018-12-22 04:01:17 -05:00
|
|
|
(sp-local-pair modes open nil :actions :rem))
|
2019-09-11 23:32:46 -04:00
|
|
|
;; And tweak these so that users can decide whether they want use latex
|
|
|
|
;; quotes or not, via `+latex-enable-plain-double-quotes'
|
2018-08-28 01:27:56 +02:00
|
|
|
(sp-local-pair modes "``" nil :unless '(:add sp-in-math-p)))))
|
2018-07-18 13:38:02 +02:00
|
|
|
|
2018-05-29 12:46:13 +02:00
|
|
|
|
2018-07-18 15:31:35 +02:00
|
|
|
(after! latex
|
2018-05-29 12:46:13 +02:00
|
|
|
(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
|
2018-07-18 13:38:02 +02:00
|
|
|
LaTeX-item-indent 0)
|
2018-07-29 21:57:56 +02:00
|
|
|
(when +latex--company-backends
|
|
|
|
(set-company-backend! 'latex-mode +latex--company-backends))
|
2019-10-03 20:47:22 -04:00
|
|
|
|
|
|
|
;; Provide proper indentation for LaTeX "itemize","enumerate", and
|
|
|
|
;; "description" environments. See
|
|
|
|
;; http://emacs.stackexchange.com/questions/3083/how-to-indent-items-in-latex-auctex-itemize-environments
|
2018-05-29 12:46:13 +02:00
|
|
|
(dolist (env '("itemize" "enumerate" "description"))
|
2019-10-03 20:47:22 -04:00
|
|
|
(add-to-list 'LaTeX-indent-environment-list `(,env +latex/LaTeX-indent-item)))
|
|
|
|
;; Fix #1849: allow fill-paragraph in itemize/enumerate
|
|
|
|
(defadvice! +latex--dont-indent-itemize-and-enumerate-a (orig-fn &rest args)
|
|
|
|
:around #'LaTeX-fill-region-as-paragraph
|
|
|
|
(let ((LaTeX-indent-environment-list LaTeX-indent-environment-list))
|
|
|
|
(delq! "itemize" LaTeX-indent-environment-list 'assoc)
|
|
|
|
(delq! "enumerate" LaTeX-indent-environment-list 'assoc)
|
|
|
|
(apply orig-fn args))))
|
2018-05-29 12:46:13 +02:00
|
|
|
|
2018-07-30 02:38:42 +02:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-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
|
|
|
|
2018-07-30 02:38:42 +02:00
|
|
|
|
|
|
|
;; Nicely indent lines that have wrapped when visual line mode is activated
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! adaptive-wrap
|
2018-07-30 02:38:42 +02:00
|
|
|
:hook (LaTeX-mode . adaptive-wrap-prefix-mode)
|
|
|
|
:init (setq-default adaptive-wrap-extra-indent 0))
|
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! auctex-latexmk
|
2018-07-30 02:38:42 +02:00
|
|
|
:when (featurep! +latexmk)
|
|
|
|
:after latex
|
|
|
|
: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))
|
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! company-auctex
|
2018-01-04 14:50:59 -05:00
|
|
|
:when (featurep! :completion company)
|
2018-07-18 16:22:47 +02:00
|
|
|
:defer t
|
|
|
|
:init
|
2018-07-29 21:57:56 +02:00
|
|
|
(add-to-list '+latex--company-backends #'company-auctex-environments nil #'eq)
|
|
|
|
(add-to-list '+latex--company-backends #'company-auctex-macros nil #'eq))
|
2018-07-18 16:22:47 +02:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! company-math
|
2018-07-18 16:22:47 +02:00
|
|
|
:when (featurep! :completion company)
|
|
|
|
:defer t
|
|
|
|
:init
|
2018-07-29 21:57:56 +02:00
|
|
|
(add-to-list '+latex--company-backends #'+latex-symbols-company-backend nil #'eq))
|
2018-05-09 12:31:24 +02:00
|
|
|
|
2018-07-18 12:12:15 +02:00
|
|
|
|
2018-07-30 02:38:42 +02:00
|
|
|
;; bibtex + reftex
|
2018-07-18 12:12:15 +02:00
|
|
|
(load! "+ref")
|