aboutsummaryrefslogtreecommitdiff
path: root/config.org
diff options
context:
space:
mode:
authorBardofSprites <[email protected]>2026-01-20 10:18:44 -0500
committerBardofSprites <[email protected]>2026-01-20 10:18:44 -0500
commitdae7521ccf53e68a370d4051d6909d38d4ac2ad0 (patch)
tree62cdde6a5f33d08dedae29913c2129a0937a298d /config.org
parent8d91ee4fa386943b5952da1055cff3b2ae4540ed (diff)
enhanced LaTeX editing
Diffstat (limited to 'config.org')
-rw-r--r--config.org81
1 files changed, 78 insertions, 3 deletions
diff --git a/config.org b/config.org
index 93e6cdf..de73227 100644
--- a/config.org
+++ b/config.org
@@ -1370,7 +1370,9 @@ For a long time I really struggled with Emacs tab completion. It still only kind
(use-package cdlatex
:ensure t
- )
+ :hook (LaTeX-mode . turn-on-cdlatex)
+ :bind (:map cdlatex-mode-map
+ ("<tab>" . cdlatex-tab)))
;; latex editing niceness
(use-package org-fragtog
@@ -2108,16 +2110,68 @@ Watch [[https://protesilaos.com/codelog/2024-02-08-emacs-window-rules-display-bu
#+begin_src emacs-lisp :tangle bard-emacs-modules/bard-emacs-writing.el :mkdirp yes
(use-package yasnippet
:ensure t
+ :hook ((LaTeX-mode . yas-minor-mode)
+ (post-self-insert . my/yas-try-expanding-auto-snippets))
:config
(setq yas-snippet-dirs '("~/.emacs.d/snippets"))
(yas-global-mode t)
- )
+ (use-package warnings
+ :config
+ (cl-pushnew '(yasnippet backquote-change)
+ warning-suppress-types
+ :test 'equal))
+
+ (setq yas-triggers-in-field t)
+
+ ;; Function that tries to autoexpand YaSnippets
+ ;; The double quoting is NOT a typo!
+ (defun my/yas-try-expanding-auto-snippets ()
+ (when (and (boundp 'yas-minor-mode) yas-minor-mode)
+ (let ((yas-buffer-local-condition ''(require-snippet-condition . auto)))
+ (yas-expand)))))
(use-package yasnippet-capf
:ensure t
:after cape
:config
(add-to-list 'completion-at-point-functions #'yasnippet-capf))
+
+ (use-package cdlatex
+ :hook ((cdlatex-tab . yas-expand)
+ (cdlatex-tab . cdlatex-in-yas-field))
+ :config
+ (use-package yasnippet
+ :bind (:map yas-keymap
+ ("<tab>" . yas-next-field-or-cdlatex)
+ ("TAB" . yas-next-field-or-cdlatex))
+ :config
+ (defun cdlatex-in-yas-field ()
+ ;; Check if we're at the end of the Yas field
+ (when-let* ((_ (overlayp yas--active-field-overlay))
+ (end (overlay-end yas--active-field-overlay)))
+ (if (>= (point) end)
+ ;; Call yas-next-field if cdlatex can't expand here
+ (let ((s (thing-at-point 'sexp)))
+ (unless (and s (assoc (substring-no-properties s)
+ cdlatex-command-alist-comb))
+ (yas-next-field-or-maybe-expand)
+ t))
+ ;; otherwise expand and jump to the correct location
+ (let (cdlatex-tab-hook minp)
+ (setq minp
+ (min (save-excursion (cdlatex-tab)
+ (point))
+ (overlay-end yas--active-field-overlay)))
+ (goto-char minp) t))))
+
+ (defun yas-next-field-or-cdlatex nil
+ (interactive)
+ "Jump to the next Yas field correctly with cdlatex active."
+ (if
+ (or (bound-and-true-p cdlatex-mode)
+ (bound-and-true-p org-cdlatex-mode))
+ (cdlatex-tab)
+ (yas-next-field-or-maybe-expand)))))
#+end_src
*** Denote Note taking
@@ -4340,7 +4394,28 @@ I want to have a custom format for my daily journal file to start what I want to
(org-fragtog-mode t)
(org-cdlatex-mode t)
(electric-pair-local-mode t)
- (bard/cdlatex-add-math-symbols))
+ (bard/cdlatex-add-math-symbols)
+ ;; sending math to calc from latex doc
+ (define-key org-mode-map (kbd "C-S-e") #'latex-math-from-calc))
+
+ ;; latex into calc
+ (defun latex-math-from-calc ()
+ "Evaluate `calc' on the contents of line at point."
+ (interactive)
+ (cond ((region-active-p)
+ (let* ((beg (region-beginning))
+ (end (region-end))
+ (string (buffer-substring-no-properties beg end)))
+ (kill-region beg end)
+ (insert (calc-eval `(,string calc-language latex
+ calc-prefer-frac t
+ calc-angle-mode rad)))))
+ (t (let ((l (thing-at-point 'line)))
+ (end-of-line 1) (kill-line 0)
+ (insert (calc-eval `(,l
+ calc-language latex
+ calc-prefer-frac t
+ calc-angle-mode rad)))))))
#+end_src
*** Provide library