From 883a326e87f9b87b5e729ef01f2bcdec7a897cad Mon Sep 17 00:00:00 2001 From: yoavm448 Date: Fri, 7 Feb 2020 12:36:07 +0200 Subject: [PATCH] Add cdlatex support in latex: +cdlatex cdlatex has 4 main functionalities: + Math and environments snippets: I've disabled these in favor of yasnippet when using :editor snippets by just unbinding the TAB in cdlatex's keymap + Auto insertion of closing delimiters: disabled in favor of smartparens + Fast insertion for some macros: `a becomes \alpha. Kept as-is + Fast accent insertion: a'~ becomes \tilde{a}. Kept as-is I also updated the docs, and added a section explaining how to re-enable cdlatex's snippets despite having yasnippet. --- modules/lang/latex/README.org | 19 ++++++++++++++++++- modules/lang/latex/config.el | 24 ++++++++++++++++++++++++ modules/lang/latex/packages.el | 3 +++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/modules/lang/latex/README.org b/modules/lang/latex/README.org index 173744725..0d208c5c7 100644 --- a/modules/lang/latex/README.org +++ b/modules/lang/latex/README.org @@ -12,6 +12,7 @@ - [[#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. @@ -27,7 +28,8 @@ Provide a helping hand when working with LaTeX documents. + 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. ** Plugins + [[http://www.gnu.org/software/auctex/][auctex]] @@ -38,6 +40,7 @@ Provide a helping hand when working with LaTeX documents. + [[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 @@ -76,3 +79,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. diff --git a/modules/lang/latex/config.el b/modules/lang/latex/config.el index 48a2e19c0..8cc779e7a 100644 --- a/modules/lang/latex/config.el +++ b/modules/lang/latex/config.el @@ -119,6 +119,30 @@ If no viewers are found, `latex-preview-pane' is used.") (lambda () (* (/ 10.0 (preview-document-pt)) preview-scale)))) +(use-package! cdlatex + :defer t + :when (featurep! +cdlatex) + :hook (LaTeX-mode . cdlatex-mode) + :config + ;; Disabling keys that have overlapping functionality with other parts of Doom + ;; smartparens takes care of inserting closing delimiters + (define-key cdlatex-mode-map "$" nil) + (define-key cdlatex-mode-map "(" nil) + (define-key cdlatex-mode-map "{" nil) + (define-key cdlatex-mode-map "[" nil) + (define-key cdlatex-mode-map "|" nil) + (define-key cdlatex-mode-map "<" nil) + ;; TAB is used for cdlatex's snippets and navigation. But have yasnippet for that. + (when (featurep! :editor snippets) + (define-key cdlatex-mode-map "\t" nil)) + + ;; AUCTeX takes care of auto-inserting {} on _^ if you want, with `TeX-electric-sub-and-superscript' + (define-key cdlatex-mode-map "^" nil) + (define-key cdlatex-mode-map "_" nil) + ;; AUCTeX already provides this with `LaTeX-insert-item' + (define-key cdlatex-mode-map [(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) diff --git a/modules/lang/latex/packages.el b/modules/lang/latex/packages.el index 608934c61..db8796c1d 100644 --- a/modules/lang/latex/packages.el +++ b/modules/lang/latex/packages.el @@ -10,6 +10,9 @@ (when (featurep! +latexmk) (package! auctex-latexmk :pin "4d35352265")) +(when (featurep! +cdlatex) + (package! cdlatex :pin "b7af5a9884")) + ;; Features according to other user selected options (when (featurep! :completion company)