Updating Doom Emacs.

This commit is contained in:
Derek Taylor
2020-06-19 22:43:40 -05:00
parent 0f664d532a
commit a5c86c514a
453 changed files with 13527 additions and 12455 deletions

View File

@@ -1,10 +1,5 @@
;;; 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
@@ -23,6 +18,8 @@
(?t . "\\textcite[]{%l}"))
reftex-plug-into-AUCTeX t
reftex-toc-split-windows-fraction 0.3)
(when (featurep! :editor evil)
(add-hook 'reftex-mode-hook #'evil-normalize-keymaps))
(map! :map reftex-mode-map
:localleader
";" 'reftex-toc)

View File

@@ -53,4 +53,4 @@
(define-key! doc-view-mode-map
"ESC" #'delete-window
"q" #'delete-window
"k" (λ! (quit-window) (delete-window))))
"k" (cmd! (quit-window) (delete-window))))

View File

@@ -8,10 +8,15 @@
- [[#module-flags][Module Flags]]
- [[#plugins][Plugins]]
- [[#prerequisites][Prerequisites]]
- [[#ubuntu][Ubuntu]]
- [[#arch-linux][Arch Linux]]
- [[#macos][macOS]]
- [[#nixos][NixOS]]
- [[#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]]
- [[#using-cdlatexs-snippets-despite-having-yasnippet][Using cdlatex's snippets despite having yasnippet]]
* Description
Provide a helping hand when working with LaTeX documents.
@@ -23,11 +28,15 @@ Provide a helping hand when working with LaTeX documents.
+ 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.
+ =+latexmk= Use LatexMk instead of LaTeX to compile documents.
+ =+cdlatex= Enable [[https://github.com/cdominik/cdlatex][cdlatex]] for fast math insertion.
+ =+lsp= Start LSP automatically in `tex-mode-hook`. This requires the =:tools
lsp= module. Supported servers are `digestif` and `TexLab`.
+ =+fold= Use TeX-fold (from auctex) to fold LaTeX macros to unicode, and make
folding hook-based and less manual.
** Plugins
+ [[http://www.gnu.org/software/auctex/][auctex]]
@@ -37,22 +46,51 @@ Provide a helping hand when working with LaTeX documents.
+ [[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]]*
+ [[https://github.com/cdominik/cdlatex][cdlatex]] (=+cdlatex=)
* TODO Prerequisites
* Prerequisites
You will need ghostscript and a latex compiler. All this is provided by
the =texlive= bundle, available through many OS package managers.
Ghostscript <= 9.27 is [[https://www.gnu.org/software/auctex/manual/preview-latex/No-images-are-displayed-with-gs-9_002e27-and-earlier.html][reported buggy]] and doesn't work with auctex's math
previews. (You can check you ghostscript version with ~gs --version~.) Most
package managers already have newer versions, but if not you might have to build
gs from source.
** Ubuntu
#+BEGIN_SRC sh
apt-get install texlive
#+END_SRC
** Arch Linux
#+BEGIN_SRC sh
pacman -S texlive
#+END_SRC
** TODO macOS
#+BEGIN_SRC sh
brew cask install basictex
# If the above doesn't work, then
brew cask install mactex # WARNING: large 4gb download!
#+END_SRC
#+begin_quote
This has not been verified.
#+end_quote
** NixOS
#+BEGIN_SRC nix
environment.systemPackages = [ pkgs.texlive.combined.scheme-medium ];
#+END_SRC
* 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:
Reftex has a variable that allow you to
specify where it should find your bibliography file(s):
#+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
@@ -76,3 +114,17 @@ tool, for instance:
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~.
** Using cdlatex's snippets despite having yasnippet
cdlatex has a snippet insertion capability which is disabled in favor of
yasnippet when using ~:editor snippets~. If you still wanna use it, simply rebind
the ~TAB~ key for cdlatex, which takes care of snippet-related stuff:
#+BEGIN_SRC emacs-lisp
(map! :map cdlatex-mode-map
:i "TAB" #'cdlatex-tab)
#+END_SRC
This would favor yasnippet's expansion and cursor movement over cdlatex's
expansion and movement, but that shouldn't matter if you're not using yasnippet
in latex buffers.

View File

@@ -39,6 +39,18 @@ Continuation lines are indented either twice `LaTeX-indent-level', or
(+ offset indent))
((+ contin indent))))))
;;;###autoload
(defun +latex-fold-last-macro-a (&rest _)
"Advice to auto-fold LaTeX macros after functions that
typically insert macros."
;; A simpler approach would be to just fold the whole line, but if point was
;; inside a macro that would would kick it out. So instead we fold the last
;; macro before point, hoping its the one newly inserted.
(TeX-fold-region (save-excursion
(search-backward "\\" (line-beginning-position) t)
(point))
(1+ (point))))
;;;###autoload
(defun +latex-symbols-company-backend (command &optional arg &rest _ignored)
"A wrapper backend for `company-mode' that either uses

View File

@@ -3,9 +3,6 @@
(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
@@ -39,6 +36,7 @@ If no viewers are found, `latex-preview-pane' is used.")
;; automatically insert braces after sub/superscript in math mode
TeX-electric-sub-and-superscript t)
(after! tex
;; fontify common latex commands
(load! "+fontification")
@@ -48,12 +46,13 @@ If no viewers are found, `latex-preview-pane' is used.")
(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)
(setq-hook! 'TeX-mode-hook
;; tell emacs how to parse tex files
ispell-parser 'tex
;; Don't auto-fill in math blocks
fill-nobreak-predicate (cons #'texmathp fill-nobreak-predicate))
;; 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
@@ -71,7 +70,49 @@ If no viewers are found, `latex-preview-pane' is used.")
(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)))))
(sp-local-pair modes "``" nil :unless '(:add sp-in-math-p))))
;; Hook lsp if enabled
(when (featurep! +lsp)
(add-hook! '(tex-mode-local-vars-hook
latex-mode-local-vars-hook)
#'lsp!)))
(use-package! tex-fold
:when (featurep! +fold)
:hook (TeX-mode . TeX-fold-buffer)
:hook (TeX-mode . TeX-fold-mode)
:config
;; Fold after all auctex macro insertions
(advice-add #'TeX-insert-macro :after #'+latex-fold-last-macro-a)
;; Fold after cdlatex macro insertions
(advice-add #'cdlatex-math-symbol :after #'+latex-fold-last-macro-a)
(advice-add #'cdlatex-math-modify :after #'+latex-fold-last-macro-a)
;; Fold after snippets
(when (featurep! :editor snippets)
(add-hook! 'TeX-fold-mode-hook
(defun +latex-fold-snippet-contents-h ()
(add-hook! 'yas-after-exit-snippet-hook :local
(TeX-fold-region yas-snippet-beg yas-snippet-end)))))
(add-hook! 'mixed-pitch-mode-hook
(defun +latex-fold-set-variable-pitch-h ()
"Fix folded things invariably getting fixed pitch when using mixed-pitch.
Math faces should stay fixed by the mixed-pitch blacklist, this is mostly for
\\section etc."
(when mixed-pitch-mode
;; Adding to this list makes mixed-pitch clean the face remaps after us
(add-to-list 'mixed-pitch-fixed-cookie
(face-remap-add-relative
'TeX-fold-folded-face
:family (face-attribute 'variable-pitch :family)
:height (face-attribute 'variable-pitch :height))))))
(map! :map TeX-fold-mode-map
:localleader
:desc "Fold paragraph" "f" #'TeX-fold-paragraph
:desc "Unfold paragraph" "F" #'TeX-fold-clearout-paragraph
:desc "Unfold buffer" "C-f" #'TeX-fold-clearout-buffer))
(after! latex
@@ -116,6 +157,35 @@ If no viewers are found, `latex-preview-pane' is used.")
(lambda () (* (/ 10.0 (preview-document-pt)) preview-scale))))
(use-package! cdlatex
:when (featurep! +cdlatex)
:hook (LaTeX-mode . cdlatex-mode)
:hook (org-mode . org-cdlatex-mode)
:config
;; Use \( ... \) instead of $ ... $
(setq cdlatex-use-dollar-to-ensure-math nil)
;; Disabling keys that have overlapping functionality with other parts of Doom
(map! :map cdlatex-mode-map
;; smartparens takes care of inserting closing delimiters, and if you
;; don't use smartparens you probably won't want these also.
"$" nil
"(" nil
"{" nil
"[" nil
"|" nil
"<" nil
;; TAB is used for cdlatex's snippets and navigation. But we have
;; yasnippet for that.
(:when (featurep! :editor snippets)
"TAB" nil)
;; AUCTeX takes care of auto-inserting {} on _^ if you want, with
;; `TeX-electric-sub-and-superscript'
"^" nil
"_" nil
;; AUCTeX already provides this with `LaTeX-insert-item'
[(control return)] nil))
;; Nicely indent lines that have wrapped when visual line mode is activated
(use-package! adaptive-wrap
:hook (LaTeX-mode . adaptive-wrap-prefix-mode)
@@ -142,6 +212,7 @@ If no viewers are found, `latex-preview-pane' is used.")
(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

View File

@@ -1,23 +1,21 @@
;; -*- no-byte-compile: t; -*-
;;; lang/latex/packages.el
(package! auctex)
(package! adaptive-wrap)
(package! latex-preview-pane)
(package! auctex :pin "6abf890a485b2ff734d8f87f38393f9b8f6bbbf6")
(package! adaptive-wrap :pin "1810c0ee8d827dd502ddeaae5bd759d4811fcbce")
(package! latex-preview-pane :pin "5297668a89996b50b2b62f99cba01cc544dbed2e")
;; Optional module features:
(when (featurep! +latexmk)
(package! auctex-latexmk))
(package! auctex-latexmk :pin "4d353522650d7685acbf1d38f7dbc504f734bd84"))
(when (featurep! +cdlatex)
(package! cdlatex :pin "480387b39f6ddd9cd2a9511ecee064ad8e1dd324"))
;; 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))
(package! company-auctex :pin "9400a2ec7459dde8cbf1a5d50dfee4e300ed7e18")
(package! company-reftex :pin "275ef708f08d3bf0eb30632148e5c6184eeaacdb")
(package! company-math :pin "a796053590012e6a15c8b527b521ffc15d137bd0"))