``` refactor(tex,completion,edit): Reorganize LaTeX configuration

and cleanup

- Require init-tex module in main init.el Change marginalia
- initialization from hook to immediate mode activation Enable
- yasnippet globally in init-edit Remove unused init-snippet.el
- module Simplify init-tex.el by removing redundant
- cdlatex-yasnippet integration Add lexical binding and proper
- package demand configuration for AuCTeX Clean up commented code in
- init-org.el ```
This commit is contained in:
Zelong Kuang
2025-12-14 19:27:57 +11:00
parent 9e7872b4aa
commit 8b88b04c1b
7 changed files with 19 additions and 63 deletions

View File

@@ -88,3 +88,4 @@
(require 'init-coding) (require 'init-coding)
(require 'init-org) (require 'init-org)
(require 'init-tex)

View File

@@ -60,7 +60,8 @@
;; Enrich existing commands with completion annotations ;; Enrich existing commands with completion annotations
(use-package marginalia (use-package marginalia
:hook (after-init . marginalia-mode)) :init
(marginalia-mode))
;; Consulting completing-read ;; Consulting completing-read
(use-package consult (use-package consult

View File

@@ -18,6 +18,7 @@
:hook ((LaTeX-mode . yas-minor-mode) :hook ((LaTeX-mode . yas-minor-mode)
(post-self-insert . my/yas-try-expanding-auto-snippets)) (post-self-insert . my/yas-try-expanding-auto-snippets))
:config :config
(yas-global-mode)
(use-package warnings (use-package warnings
:config :config
(cl-pushnew '(yasnippet backquote-change) (cl-pushnew '(yasnippet backquote-change)

View File

@@ -68,28 +68,14 @@
;; Increase preview width ;; Increase preview width
(plist-put org-latex-preview-appearance-options (plist-put org-latex-preview-appearance-options
:page-width 0.8) :page-width 0.8)
;; ;; Use dvisvgm to generate previews
;; ;; You don't need this, it's the default:
;; (setq org-latex-preview-process-default 'dvisvgm)
;; Turn on `org-latex-preview-mode', it's built into Org and much faster/more
;; featured than org-fragtog. (Remember to turn off/uninstall org-fragtog.)
;; ;; Block C-n, C-p etc from opening up previews when using `org-latex-preview-mode' ;; ;; Block C-n, C-p etc from opening up previews when using `org-latex-preview-mode'
;; (setq org-latex-preview-mode-ignored-commands ;; (setq org-latex-preview-mode-ignored-commands
;; '(next-line previous-line mwheel-scroll ;; '(next-line previous-line mwheel-scroll
;; scroll-up-command scroll-down-command)) ;; scroll-up-command scroll-down-command))
;; ;; Enable consistent equation numbering
(setq org-latex-preview-numbered t) (setq org-latex-preview-numbered t)
;; Bonus: Turn on live previews. This shows you a live preview of a LaTeX
;; fragment and updates the preview in real-time as you edit it.
;; To preview only environments, set it to '(block edit-special) instead
(setq org-latex-preview-mode-display-live t) (setq org-latex-preview-mode-display-live t)
;; More immediate live-previews -- the default delay is 1 second
(setq org-latex-preview-mode-update-delay 0.25)) (setq org-latex-preview-mode-update-delay 0.25))
(use-package org-roam (use-package org-roam

View File

@@ -1,10 +0,0 @@
(use-package! yasnippet
:config
(defun my-yas-try-expanding-auto-snippets ()
(when yas-minor-mode
(let ((yas-buffer-local-condition ''(require-snippet-condition . auto)))
(yas-expand))))
(add-hook 'post-command-hook #'my-yas-try-expanding-auto-snippets)
)
(provide 'init-snippet)

View File

@@ -1,7 +1,13 @@
;; -*- lexical-binding: t; -*-
(use-package latex (use-package latex
:ensure auctex :demand t
:ensure (auctex :pre-build (("./autogen.sh")
("./configure" "--without-texmf-dir" "--with-lispdir=.")
("make")))
:mode (("\\.tex\\'" . LaTeX-mode))
:hook ((LaTeX-mode . prettify-symbols-mode)) :hook ((LaTeX-mode . prettify-symbols-mode))
:bind (:map LaTeX-mode-map :bind (:map LaTeX-mode-map
("C-S-e" . latex-math-from-calc)) ("C-S-e" . latex-math-from-calc))
@@ -29,39 +35,6 @@
:hook (LaTeX-mode . turn-on-cdlatex) :hook (LaTeX-mode . turn-on-cdlatex)
:bind (:map cdlatex-mode-map :bind (:map cdlatex-mode-map
("<tab>" . cdlatex-tab))) ("<tab>" . cdlatex-tab)))
(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 (provide 'init-tex)
(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)))))

View File

@@ -1,10 +1,14 @@
;;; Automatically generated by recentf on Sun Dec 14 11:04:21 2025. ;;; Automatically generated by recentf on Sun Dec 14 19:26:39 2025 -*- mode: emacs-lisp; lexical-binding: t -*-
(setq recentf-list (setq recentf-list
'( '(
"~/.emacs.d/lisp/init-org.el"
"~/.emacs.d/init.el" "~/.emacs.d/init.el"
"~/.emacs.d/lisp/init-snippet.el"
"~/.emacs.d/lisp/init-org.el"
"~/.emacs.d/lisp/init-tex.el"
"~/org/roam/20251212003211-presentation_of_group.org" "~/org/roam/20251212003211-presentation_of_group.org"
"~/build-emacs-for-macos/builds/Emacs.app/Contents/Resources/lisp/loaddefs.el.gz"
"~/.emacs.d/lisp/init-completion.el"
"~/.emacs.d/lisp/init-edit.el" "~/.emacs.d/lisp/init-edit.el"
"~/.emacs.d/early-init.el" "~/.emacs.d/early-init.el"
"~/org/roam/20251117171745-emacs.org" "~/org/roam/20251117171745-emacs.org"