Files
.emacs.d/lisp/init-tex.el

86 lines
3.0 KiB
EmacsLisp
Raw Normal View History

;; -*- lexical-binding: t; -*-
2025-12-14 09:04:11 +11:00
(use-package latex
:ensure (auctex :pre-build (("./autogen.sh")
2026-03-11 21:08:31 +11:00
("./configure" "--without-texmf-dir" "--with-lispdir=.")
("make")))
:mode (("\\.tex\\'" . LaTeX-mode))
2026-02-20 02:58:42 +11:00
:hook (LaTeX-mode . prettify-symbols-mode)
:hook (LaTeX-mode . visual-line-mode)
:hook (LaTeX-mode . turn-on-reftex)
2025-12-14 09:04:11 +11:00
:bind (:map LaTeX-mode-map
2026-03-14 19:46:30 +11:00
("C-S-e" . latex-math-from-calc)
("C-c x" . TeX-clean))
2026-02-08 20:12:13 +11:00
:custom
2026-03-11 21:08:31 +11:00
(TeX-auto-save t)
2026-02-08 20:12:13 +11:00
(TeX-parse-self t)
(TeX-PDF-mode t)
(TeX-DVI-via-PDFTeX t)
2026-03-11 21:08:31 +11:00
(TeX-clean-confirm nil)
(TeX-save-query nil)
(TeX-source-correlate-mode t)
(TeX-source-correlate-method 'synctex)
(TeX-display-help t)
(TeX-show-compilation nil)
2025-12-14 09:04:11 +11:00
:config
2026-03-11 21:08:31 +11:00
(add-hook 'LaTeX-mode-hook (lambda ()
(setq TeX-command-default "LaTeXMk")))
2025-12-14 09:04:11 +11:00
;; Format math as a Latex string with Calc
2026-02-08 20:12:13 +11:00
(add-hook 'LaTeX-mode-hook #'eglot-ensure)
2025-12-14 09:04:11 +11:00
(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)))
2026-03-11 21:08:31 +11:00
(end-of-line 1) (kill-line 0)
2025-12-14 09:04:11 +11:00
(insert (calc-eval `(,l
calc-language latex
calc-prefer-frac t
2026-02-08 20:12:13 +11:00
calc-angle-mode rad)))))))
2026-03-11 21:08:31 +11:00
;; (setq TeX-view-program-selection '((output-pdf "PDF Tools")))
2026-02-08 20:12:13 +11:00
(add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer)
2026-03-14 11:42:48 +11:00
(setq reftex-plug-into-AUCTeX t)
2026-02-08 20:12:13 +11:00
(with-eval-after-load 'eglot
2026-03-11 21:08:31 +11:00
(add-to-list 'eglot-server-programs '((LaTeX-mode latex-mode) "texlab"))))
2026-02-08 20:12:13 +11:00
2025-12-14 09:04:11 +11:00
(use-package cdlatex
2026-03-11 21:08:31 +11:00
:diminish
2025-12-14 09:04:11 +11:00
:ensure t
:hook (LaTeX-mode . turn-on-cdlatex)
2026-03-11 21:08:31 +11:00
;; :bind (:map cdlatex-mode-map
;; ("<tab>" . cdlatex-tab))
2025-12-22 15:57:17 +11:00
:config
(setq cdlatex-math-symbol-alist '((?f ("\\varphi" "\\phi"))
(?i ("\\iota"))
))
(setq cdlatex-math-modify-alist '((?f "\\mathbb" nil t nil nil)))
2026-03-11 21:08:31 +11:00
(defun tjh/cdlatex-yas-expand ()
"Resolve the conflict between cdlatex and yasnippet. When this
function returns true, the default `cdlatex-tab` will not be
executed. The effect of function is to first try yasnippet
expansion, then cdlatex expansion."
(interactive)
(if (or (bound-and-true-p yas-minor-mode)
(bound-and-true-p yas-global-mode))
(if (yas-expand)
t
nil)
nil))
(add-hook 'cdlatex-tab-hook 'tjh/cdlatex-yas-expand))
2025-12-16 01:58:26 +11:00
(use-package texpresso
:defer nil
:load-path "~/.emacs.d/lisp/packages/")
(provide 'init-tex)