[Emacs] Add LaTeX configuration

This commit is contained in:
Lucien Cartier-Tilet 2022-01-04 18:16:58 +01:00
parent 184731f105
commit 73203756e3
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -3730,6 +3730,224 @@ enhances a couple of built-in functions from Emacs, namely:
([remap describe-key] . helpful-key)) ([remap describe-key] . helpful-key))
#+end_src #+end_src
** LaTeX
:PROPERTIES:
:CUSTOM_ID: Packages-Configuration-LaTeX-qfu4g180gbj0
:END:
#+begin_src emacs-lisp :noweb yes
(require 'auctex)
(use-package auctex
:defer t
:straight (:build t)
:hook (tex-mode . lsp-deferred)
:hook (latex-mode . lsp-deferred)
:init
(setq TeX-command-default (if (executable-find "latexmk") "LatexMk" "LaTeX")
TeX-engine (if (executable-find "xetex") 'xetex 'default)
TeX-auto-save t
TeX-parse-self t
TeX-syntactic-comment t
TeX-auto-local ".auctex-auto"
TeX-style-local ".auctex-style"
TeX-source-correlate-mode t
TeX-source-correlate-method 'synctex
TeX-source-correlate-start-server nil
TeX-electric-sub-and-superscript t
TeX-fill-break-at-separators nil
TeX-save-query t)
:config
<<latex-fontification>>
(setq TeX-master t)
(setcar (cdr (assoc "Check" TeX-command-list)) "chktex -v6 -H %s")
(add-hook 'TeX-mode-hook (lambda ()
(setq ispell-parser 'tex
fill-nobreak-predicate (cons #'texmathp fill-nobreak-predicate))))
(add-hook 'TeX-mode-hook #'visual-line-mode)
(add-hook 'TeX-update-style-hook #'rainbow-delimiters-mode)
:general
(phundrak/major-leader-key
:packages 'auctex
:keymaps '(latex-mode-map LaTeX-mode-map)
"v" '(TeX-view :which-key "View")
"c" '(TeX-command-run-all :which-key "Compile")
"m" '(TeX-command-master :which-key "Run a command")))
#+end_src
From Doom Emacs configuration:
#+name: latex-fontification
#+begin_src emacs-lisp :tangle no
(setq font-latex-match-reference-keywords
'(;; BibLaTeX.
("printbibliography" "[{") ("addbibresource" "[{")
;; Standard commands.
("cite" "[{") ("citep" "[{")
("citet" "[{") ("Cite" "[{")
("parencite" "[{") ("Parencite" "[{")
("footcite" "[{") ("footcitetext" "[{")
;; Style-specific commands.
("textcite" "[{") ("Textcite" "[{")
("smartcite" "[{") ("Smartcite" "[{")
("cite*" "[{") ("parencite*" "[{")
("supercite" "[{")
;; Qualified citation lists.
("cites" "[{") ("Cites" "[{")
("parencites" "[{") ("Parencites" "[{")
("footcites" "[{") ("footcitetexts" "[{")
("smartcites" "[{") ("Smartcites" "[{")
("textcites" "[{") ("Textcites" "[{")
("supercites" "[{")
;; Style-independent commands.
("autocite" "[{") ("Autocite" "[{")
("autocite*" "[{") ("Autocite*" "[{")
("autocites" "[{") ("Autocites" "[{")
;; Text commands.
("citeauthor" "[{") ("Citeauthor" "[{")
("citetitle" "[{") ("citetitle*" "[{")
("citeyear" "[{") ("citedate" "[{")
("citeurl" "[{")
;; Special commands.
("fullcite" "[{")
;; Cleveref.
("cref" "{") ("Cref" "{")
("cpageref" "{") ("Cpageref" "{")
("cpagerefrange" "{") ("Cpagerefrange" "{")
("crefrange" "{") ("Crefrange" "{")
("labelcref" "{")))
(setq font-latex-match-textual-keywords
'(;; BibLaTeX brackets.
("parentext" "{") ("brackettext" "{")
("hybridblockquote" "[{")
;; Auxiliary commands.
("textelp" "{") ("textelp*" "{")
("textins" "{") ("textins*" "{")
;; Subcaption.
("subcaption" "[{")))
(setq font-latex-match-variable-keywords
'(;; Amsmath.
("numberwithin" "{")
;; Enumitem.
("setlist" "[{") ("setlist*" "[{")
("newlist" "{") ("renewlist" "{")
("setlistdepth" "{") ("restartlist" "{")
("crefname" "{")))
#+end_src
#+begin_src elisp
(use-package smartparens-latex
:after auctex
:defer t
:straight (:build t)
:config
(let ((modes '(tex-mode plain-tex-mode latex-mode LaTeX-mode)))
;; From DoomEmacs
;; We have to use lower case modes here, because `smartparens-mode' uses
;; the same during configuration.
(dolist (open '("\\left(" "\\left[" "\\left\\{" "\\left|"
"\\bigl(" "\\biggl(" "\\Bigl(" "\\Biggl(" "\\bigl["
"\\biggl[" "\\Bigl[" "\\Biggl[" "\\bigl\\{" "\\biggl\\{"
"\\Bigl\\{" "\\Biggl\\{"
"\\lfloor" "\\lceil" "\\langle"
"\\lVert" "\\lvert" "`"))
(sp-local-pair modes open nil :actions :rem))
(sp-local-pair-modes $``$ nil :unless '(:add sp-in-math-p))))
#+end_src
#+begin_src emacs-lisp
(after! latex
(setq LaTeX-section-hook
'(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))
#+end_src
#+begin_src emacs-lisp
(after! preview
(add-hook 'LaTeX-mode-hook #'LaTeX-preview-setup)
(setq-default preview-scale 1.4
preview-scale-function
(lambda () (* (/ 10.0 (preview-document-pt)) preview-scale)))
(setq preview-auto-cache-preamble nil)
(phundrak/major-leader-key
:packages 'auctex
:keymaps '(latex-mode-map LaTeX-mode-map)
"p" #'preview-at-point
"P" #'preview-clearout-at-point))
#+end_src
#+begin_src emacs-lisp
(use-package cdlatex
:defer t
:after auctex
:straight (:build t)
:hook (LaTeX-mode . cdlatex-mode)
:hook (org-mode . org-cdlatex-mode)
:config
(setq cdlatex-use-dollar-to-ensure-math nil)
:general
(phundrak/major-leader-key
:packages 'cdlatex
:keymaps 'cdlatex-mode-map
"$" nil
"(" nil
"{" nil
"[" nil
"|" nil
"<" nil
"^" nil
"_" nil
[(control return)] nil))
#+end_src
#+begin_src emacs-lisp
(use-package adaptive-wrap
:defer t
:after auctex
:straight (:build t)
:hook (LaTeX-mode . adaptative-wrap-prefix-mode)
:init (setq-default adaptative-wrap-extra-indent 0))
#+end_src
#+begin_src emacs-lisp
(use-package auctex-latexmk
:after auctex
:defer t
:straight (:build t)
:init
(setq auctex-latexmk-inherit-TeX-PDF-mode t)
(add-hook 'LaTeX-mode (lambda () (setq TeX-command-default "LatexMk")))
:config
(auctex-latexmk-setup))
#+end_src
#+begin_src emacs-lisp
(use-package company-auctex
:defer t
:after (company auctex)
:straight (:build t)
:config
(company-auctex-init))
#+end_src
#+begin_src emacs-lisp
(use-package company-math
:defer t
:straight (:build t)
:after (company auctex)
:config
(defun my-latex-mode-setup ()
(setq-local company-backends
(append '((company-math-symbols-latex company-latex-commands))
company-backends)))
(add-hook 'TeX-mode-hook #'my-latex-mode-setup))
#+end_src
** Org-mode ** Org-mode
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: Packages-Configuration-Org-modedw35fl6184j0 :CUSTOM_ID: Packages-Configuration-Org-modedw35fl6184j0