Moving to Doom Emacs!

This commit is contained in:
Derek Taylor
2019-12-16 20:21:19 -06:00
parent d9f2f456f1
commit d4b4c33550
683 changed files with 51877 additions and 100 deletions

View File

@@ -0,0 +1,88 @@
;;; lang/latex/+fontification.el -*- lexical-binding: t; -*-
;; Fontification taken from https://tex.stackexchange.com/a/86119/81279
(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" "{")))

View File

@@ -0,0 +1,42 @@
;;; lang/latex/+ref.el -*- lexical-binding: t; -*-
(when (stringp +latex-bibtex-file)
(setq bibtex-completion-bibliography (list (expand-file-name +latex-bibtex-file))
reftex-default-bibliography bibtex-completion-bibliography))
(use-package! reftex
:hook (LaTeX-mode . reftex-mode)
:config
;; set up completion for citations and references
(set-company-backend! 'reftex-mode 'company-reftex-labels 'company-reftex-citations)
;; Get ReTeX working with biblatex
;; http://tex.stackexchange.com/questions/31966/setting-up-reftex-with-biblatex-citation-commands/31992#31992
(setq reftex-cite-format
'((?a . "\\autocite[]{%l}")
(?b . "\\blockcquote[]{%l}{}")
(?c . "\\cite[]{%l}")
(?f . "\\footcite[]{%l}")
(?n . "\\nocite{%l}")
(?p . "\\parencite[]{%l}")
(?s . "\\smartcite[]{%l}")
(?t . "\\textcite[]{%l}"))
reftex-plug-into-AUCTeX t
reftex-toc-split-windows-fraction 0.3)
(map! :map reftex-mode-map
:localleader
";" 'reftex-toc)
(add-hook! 'reftex-toc-mode-hook
(reftex-toc-rescan)
(map! :map 'local
:e "j" #'next-line
:e "k" #'previous-line
:e "q" #'kill-buffer-and-window
:e "ESC" #'kill-buffer-and-window)))
;; set up mode for bib files
(after! bibtex
(setq bibtex-dialect 'biblatex
bibtex-align-at-equal-sign t
bibtex-text-indentation 20)
(define-key bibtex-mode-map (kbd "C-c \\") #'bibtex-fill-entry))

View File

@@ -0,0 +1,56 @@
;;; lang/latex/+viewers.el -*- lexical-binding: t; -*-
;; fall back pdf previewing to latex-preview-pane
(add-to-list 'TeX-view-program-selection '(output-pdf "preview-pane") 'append)
(add-to-list 'TeX-view-program-list '("preview-pane" latex-preview-pane-mode))
(dolist (viewer (reverse +latex-viewers))
(pcase viewer
(`skim
(when-let
(app-path
(and IS-MAC
(file-exists-p! (or "/Applications/Skim.app"
"~/Applications/Skim.app"))))
(add-to-list 'TeX-view-program-selection '(output-pdf "Skim"))
(add-to-list 'TeX-view-program-list
(list "Skim" (format "%s/Contents/SharedSupport/displayline -b -g %%n %%o %%b"
app-path)))))
(`sumatrapdf
(when (and IS-WINDOWS
(executable-find "SumatraPDF"))
(add-to-list 'TeX-view-program-selection '(output-pdf "SumatraPDF"))))
(`okular
(when (executable-find "okular")
;; Configure Okular as viewer. Including a bug fix
;; (https://bugs.kde.org/show_bug.cgi?id=373855)
(add-to-list 'TeX-view-program-list '("Okular" ("okular --unique file:%o" (mode-io-correlate "#src:%n%a"))))
(add-to-list 'TeX-view-program-selection '(output-pdf "Okular"))))
(`zathura
(when (executable-find "zathura")
(add-to-list 'TeX-view-program-selection '(output-pdf "Zathura"))))
(`evince
(when (executable-find "evince")
(add-to-list 'TeX-view-program-selection '(output-pdf "Evince"))))
(`pdf-tools
(when (featurep! :tools pdf)
(add-to-list 'TeX-view-program-selection '(output-pdf "PDF Tools"))
(when IS-MAC
;; PDF Tools isn't in `TeX-view-program-list-builtin' on macs
(add-to-list 'TeX-view-program-list '("PDF Tools" TeX-pdf-tools-sync-view)))
;; Update PDF buffers after successful LaTeX runs
(add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer)))))
(after! latex-preview-pane
(setq latex-preview-pane-multifile-mode 'auctex)
(define-key! doc-view-mode-map
"ESC" #'delete-window
"q" #'delete-window
"k" (λ! (quit-window) (delete-window))))

View File

@@ -0,0 +1,78 @@
#+TITLE: lang/latex
#+DATE: January 16, 2017
#+SINCE: v1.3
#+STARTUP: inlineimages
* Table of Contents :TOC_3:noexport:
- [[#description][Description]]
- [[#module-flags][Module Flags]]
- [[#plugins][Plugins]]
- [[#prerequisites][Prerequisites]]
- [[#features][Features]]
- [[#customization][Customization]]
- [[#specifying-the-location-of-a-bibtex-file--corresponding-pdfs][Specifying the location of a bibtex file & corresponding PDFs]]
- [[#changing-the-pdfs-viewer][Changing the PDFs viewer]]
* Description
Provide a helping hand when working with LaTeX documents.
+ Sane defaults
+ Fontification of many popular commands
+ Pretty indentation of wrapped lines using the ~adaptive-wrap~ package
+ Spell checking with ~flycheck~
+ Change PDF viewer to Okular or ~latex-preview-pane~
+ Bibtex editor
+ Autocompletion using ~company-mode~
+ Ivy or Helm for selecting bibliography
+ Compile your .tex code only once using LatexMk
** Module Flags
+ ~+latexmk~ Use LatexMk instead of LaTeX to compile documents.
** Plugins
+ [[http://www.gnu.org/software/auctex/][auctex]]
+ [[http://elpa.gnu.org/packages/adaptive-wrap.html][adaptive-wrap]]
+ [[https://github.com/jsinglet/latex-preview-pane][latex-preview-pane]]
+ [[https://github.com/tom-tan/auctex-latexmk][auctex-latexmk]]*
+ [[https://github.com/alexeyr/company-auctex][company-auctex]]*
+ [[https://github.com/TheBB/company-reftex][company-reftex]]*
+ [[https://github.com/vspinu/company-math][company-math]]*
+ [[https://github.com/tmalsburg/helm-bibtex][ivy-bibtex]]* or [[https://github.com/tmalsburg/helm-bibtex][helm-bibtex]]*
* TODO Prerequisites
* TODO Features
* Customization
** Specifying the location of a bibtex file & corresponding PDFs
The reftex and bibtex-completion packages have two variables that allow you to
specify where it should find your bibliography file(s) and their corresponding
PDFs:
#+BEGIN_SRC emacs-lisp
(setq reftex-default-bibliography "/your/bib/file.bib")
;; Optionally specifying a location for the corresponding PDFs
(setq bibtex-completion-library-path (list "/your/bib/pdfs"))
#+END_SRC
** Changing the PDFs viewer
This module provides integration for four supported pdf viewers. They are
+ [[https://skim-app.sourceforge.io/][Skim.app]] (MacOS only)
+ Evince
+ Sumatra PDF
+ Zathura
+ Okular
+ pdf-tools (requires =:tools pdf= module)
They are searched for in this order. See ~+latex-viewers~ to change the order,
or remove tools from the search altogether. If you want to exclusively use one
tool, for instance:
#+BEGIN_SRC emacs-lisp
(setq +latex-viewers '(zathura))
#+END_SRC
If none of these tools are found, ~latex-preview-pane~ (uses ~DocView~ in Emacs)
is used as a fallback. You can use this exclusively by setting ~+latex-viewers~
to ~nil~.

View File

@@ -0,0 +1,49 @@
;;; lang/latex/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +latex/LaTeX-indent-item ()
"Provide proper indentation for LaTeX \"itemize\",\"enumerate\", and
\"description\" environments.
\"\\item\" is indented `LaTeX-indent-level' spaces relative to the the beginning
of the environment.
Continuation lines are indented either twice `LaTeX-indent-level', or
`LaTeX-indent-level-item-continuation' if the latter is bound."
(save-match-data
(let* ((offset LaTeX-indent-level)
(contin (or (and (boundp '+latex-indent-level-item-continuation)
+latex-indent-level-item-continuation)
(* 4 offset)))
(re-beg "\\\\begin{")
(re-end "\\\\end{")
(re-env "\\(itemize\\|\\enumerate\\|description\\)")
(indent (save-excursion
(when (looking-at (concat re-beg re-env "}"))
(end-of-line))
(LaTeX-find-matching-begin)
(current-column))))
(cond ((looking-at (concat re-beg re-env "}"))
(or (save-excursion
(beginning-of-line)
(ignore-errors
(LaTeX-find-matching-begin)
(+ (current-column)
(if (looking-at (concat re-beg re-env "}"))
contin
offset))))
indent))
((looking-at (concat re-end re-env "}"))
indent)
((looking-at "\\\\item")
(+ offset indent))
((+ contin indent))))))
;;;###autoload
(defun +latex-symbols-company-backend (command &optional arg &rest _ignored)
"A wrapper backend for `company-mode' that either uses
`company-math-symbols-unicode' or `company-math-symbols-latex'. If
`+latex-enable-unicode-math' is non-nil use the former, otherwise the latter."
(if +latex-enable-unicode-math
(company-math-symbols-unicode command arg)
(company-math-symbols-latex command arg)))

View File

@@ -0,0 +1,153 @@
;;; lang/latex/config.el -*- lexical-binding: t; -*-
(defvar +latex-indent-level-item-continuation 4
"Custom indentation level for items in enumeration-type environments")
(defvar +latex-bibtex-file nil
"File AUCTeX (specifically RefTeX) uses to search for citations.")
(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.")
(defvar +latex-viewers '(skim evince sumatrapdf zathura okular pdf-tools)
"A list of enabled latex viewers to use, in this order. If they don't exist,
they will be ignored. Recognized viewers are skim, evince, sumatrapdf, zathura,
okular and pdf-tools.
If no viewers are found, `latex-preview-pane' is used.")
;;
(defvar +latex--company-backends nil)
;;
;; Packages
(add-to-list 'auto-mode-alist '("\\.tex\\'" . LaTeX-mode))
(setq TeX-parse-self t ; parse on load
TeX-auto-save t ; parse on save
;; use hidden dirs for auctex files
TeX-auto-local ".auctex-auto"
TeX-style-local ".auctex-style"
TeX-source-correlate-mode t
TeX-source-correlate-method 'synctex
;; 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)
(after! tex
;; fontify common latex commands
(load! "+fontification")
;; select viewer
(load! "+viewers")
;; do not prompt for master
(setq-default TeX-master t)
;; set-up chktex
(setcar (cdr (assoc "Check" TeX-command-list)) "chktex -v6 -H %s")
;; tell emacs how to parse tex files
(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)
;; Enable rainbow mode after applying styles to the buffer
(add-hook 'TeX-update-style-hook #'rainbow-delimiters-mode)
;; display output of latex commands in popup
(set-popup-rule! " output\\*$" :size 15)
(after! smartparens-latex
(let ((modes '(tex-mode plain-tex-mode latex-mode LaTeX-mode)))
;; All these excess pairs dramatically slow down typing in latex buffers,
;; so we remove them. Let snippets do their job.
(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))
;; And tweak these so that users can decide whether they want use latex
;; quotes or not, via `+latex-enable-plain-double-quotes'
(sp-local-pair modes "``" nil :unless '(:add sp-in-math-p)))))
(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)
(when +latex--company-backends
(set-company-backend! 'latex-mode +latex--company-backends))
;; 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
(dolist (env '("itemize" "enumerate" "description"))
(add-to-list 'LaTeX-indent-environment-list `(,env +latex/LaTeX-indent-item)))
;; Fix #1849: allow fill-paragraph in itemize/enumerate
(defadvice! +latex--re-indent-itemize-and-enumerate-a (orig-fn &rest args)
:around #'LaTeX-fill-region-as-para-do
(let ((LaTeX-indent-environment-list
(append LaTeX-indent-environment-list
'(("itemize" +latex/LaTeX-indent-item)
("enumerate" +latex/LaTeX-indent-item)))))
(apply orig-fn args)))
(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))))
(use-package! preview
:hook (LaTeX-mode . LaTeX-preview-setup)
:config
(setq-default preview-scale 1.4
preview-scale-function
(lambda () (* (/ 10.0 (preview-document-pt)) preview-scale))))
;; Nicely indent lines that have wrapped when visual line mode is activated
(use-package! adaptive-wrap
:hook (LaTeX-mode . adaptive-wrap-prefix-mode)
:init (setq-default adaptive-wrap-extra-indent 0))
(use-package! auctex-latexmk
: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))
(use-package! company-auctex
:when (featurep! :completion company)
:defer t
:init
(add-to-list '+latex--company-backends #'company-auctex-environments nil #'eq)
(add-to-list '+latex--company-backends #'company-auctex-macros nil #'eq))
(use-package! company-math
:when (featurep! :completion company)
:defer t
:init
(add-to-list '+latex--company-backends #'+latex-symbols-company-backend nil #'eq))
;; bibtex + reftex
(load! "+ref")

View File

@@ -0,0 +1,23 @@
;; -*- no-byte-compile: t; -*-
;;; lang/latex/packages.el
(package! auctex)
(package! adaptive-wrap)
(package! latex-preview-pane)
;; Optional module features:
(when (featurep! +latexmk)
(package! auctex-latexmk))
;; Features according to other user selected options
(when (featurep! :completion company)
(package! company-auctex)
(package! company-reftex)
(package! company-math))
(when (featurep! :completion ivy)
(package! ivy-bibtex))
(when (featurep! :completion helm)
(package! helm-bibtex))