From 46e48e23d99ed37247feb4d219bf7d2dc2c48697 Mon Sep 17 00:00:00 2001 From: Lucas Sta Maria Date: Sun, 25 Feb 2024 14:43:30 -0500 Subject: [PATCH] feat(emacs): add `insert-frac` command for faster latex fractions Signed-off-by: Lucas Sta Maria --- .emacs.d/include/latexconfig.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.emacs.d/include/latexconfig.el b/.emacs.d/include/latexconfig.el index e568029..e99885a 100644 --- a/.emacs.d/include/latexconfig.el +++ b/.emacs.d/include/latexconfig.el @@ -25,6 +25,26 @@ (insert "\\(\\)") (backward-char 2))))) +(defun insert-frac () + "Insert a fraction in math mode." + (interactive) + (enter-math) + (backward-char) + (defconst bc (char-after)) + (defconst bcs (char-to-string bc)) + (forward-char) + (cond ((or (string-blank-p bcs) + (memq bc '(?\ ?( ?) ?{ ?} ?[ ?]))) + (LaTeX-math-frac (not (texmathp)))) + (t + (push-mark) + (backward-word) + (defconst content (buffer-substring (point) (mark))) + (delete-region (point) (mark)) + (pop-mark) + (insert "\\frac{" content "}{}") + (backward-char)))) + (defun configure-latex () "Configure my custom LaTex environment." (electric-indent-mode -1) @@ -37,6 +57,7 @@ (keymap-local-set "C-c C-z" #'custom-compile-latex) (keymap-local-set "C-c C-b" #'latex-insert-block) (keymap-local-set "C-c C-h" #'enter-math) + (keymap-local-set "/" #'insert-frac) (keymap-local-set "C-c C-/" (lambda () (interactive)