;; Time-stamp: <2021-06-30 13h37 EDT (academic)> (defvar latex-template-dir (expand-file-name "~/typeset/latex-templates")) (defun prompt-latex-file-template () "Check if tex file does not exist or the command was called interactively. If neither, prompt to insert from a template populated from the directory *latex-template-dir*" (interactive) (when (and (if (file-exists-p (buffer-file-name)) (called-interactively-p 'interactive) t) (yes-or-no-p "Insert template?")) (let* ((tfiles (directory-files latex-template-dir nil "\\.tex")) (template (completing-read "Select template: " tfiles nil t))) (when template (goto-char (point-min)) (insert-file-contents (concat latex-template-dir "/" template)) (search-forward "begin{document}") (forward-line) (save-buffer))))) (use-package cdm-mode :load-path "~/.emacs.d/scripts/") (use-package unfill :ensure t) (use-package latex :ensure auctex :bind (:map LaTeX-mode-map ("'" . better-TeX-insert-single-quote) ("TAB" . LaTeX-indent-line) ("M-q" . unfill-paragraph) ("M-SPC" . (lambda () (interactive) (insert ?\\))) ; Never used just-one-space ("C-c C-d" . TeX-view)) :hook (LaTeX-mode . (lambda () (latex-setup-visual-aesthetics) (latex-setup-text-environment) (latex-setup-special-minor-modes) (latex-setup-completions) (prompt-latex-file-template))) :init (defun latex-setup-visual-aesthetics () (interactive) (auto-fill-mode -1) (visual-line-mode) (display-line-numbers-mode)) (defun latex-setup-text-environment () (interactive) (electric-pair-local-mode -1) (spell-fu-mode) (siege-mode 1)) (defun latex-setup-special-minor-modes () (interactive) (cdlatex-mode t) (cdm-mode)) (defun latex-setup-completions () (interactive) (require 'reftex) (turn-on-reftex)) (defun better-TeX-insert-single-quote () (interactive) (let ((old-open TeX-open-quote) (old-close TeX-close-quote)) (unwind-protect (progn (setq TeX-open-quote "`" TeX-close-quote "'") (call-interactively 'TeX-insert-quote)) (setq TeX-open-quote old-open TeX-close-quote old-close)))) :config (dolist (entry '(("diagram") ("vdiagram") ("diagram*") ("vsubdiagram") ("vsubdiagrams"))) (push entry LaTeX-indent-environment-list)) (setq TeX-command-list '(("XeLaTeX" "xelatex %t" TeX-run-TeX nil (latex-mode doctex-mode) :help "Run XeLaTeX") ("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %S%(PDFout)%(mode)%' %t" TeX-run-TeX nil (plain-tex-mode ams-tex-mode texinfo-mode) :help "Run plain TeX") ("LaTeX" "%`%l%(mode)%' %T" TeX-run-TeX nil (latex-mode doctex-mode) :help "Run LaTeX") ("BibTeX" "bibtex %s" TeX-run-BibTeX nil (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode context-mode) :help "Run BibTeX") ("View" "%V" TeX-run-discard-or-function t t :help "Run External Viewer") ("View internally" "(find-file \"%o\")" TeX-run-function nil t :help "Run Viewer") ("Spell" "(TeX-ispell-document \"\")" TeX-run-function nil t :help "Spell-check the document") ("Clean" "TeX-clean" TeX-run-function nil t :help "Delete generated intermediate files") ("Clean All" "(TeX-clean t)" TeX-run-function nil t :help "Delete generated intermediate and output files") ("Other" "" TeX-run-command t t :help "Run an arbitrary command"))) (setq TeX-electric-sub-and-superscript t TeX-electric-math '("$" . "$") TeX-electric-escape nil LaTeX-electric-left-right-brace t) (setq reftex-plug-into-AUCTeX t) (setq-default TeX-master nil) (setq TeX-auto-save t TeX-parse-self t TeX-PDF-mode t TeX-source-correlate-mode 'synctex TeX-view-program-selection '(((output-dvi style-pstricks) "dvips and gv") (output-dvi "xdvi") (output-pdf "Zathura") (output-html "xdg-open"))) (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer)) (use-package cdlatex :ensure t :bind (:map cdlatex-mode-map ("(" . nil) ("{" . nil) ("[" . nil) ("|" . nil) ("<" . nil) ("$" . nil) ("'" . nil) ("TAB" . nil) ;; ("TAB" . cdlatex-tab) ("C-c e" . cdlatex-environment) ("~" . cdlatex-math-modify) ("`" . cdlatex-math-symbol)) :init (setq cdlatex-math-modify-prefix ?~ cdlatex-math-symbol-prefix ?` cdlatex-math-modify-alist '((?a "\\mathbb" nil t nil nil) (?c "\\mathcal" "\\textsc" t nil nil) (?v "\\texttt" "\\texttt" t nil nil) (?k "\\mathfrak" nil t nil nil) (?- "\\overline" nil t nil nil) (?_ "\\underline" nil t nil nil)) cdlatex-math-symbol-alist '((?^ ("\\widehat{?}" "\\hat{?}")) (?' ("^{\\prime}" "\\prime")) (?* ("\\times" "\\otimes" "\\star")) (?+ ("+" "\\oplus")) (?- ("\\dashv" "\\vdash" "\\setminus")) (?. ("\\circ" "\\sq" "\\cdot")) (?0 ("\\emptyset" "\\circ")) (?< ("\\leftarrow" "\\leftharpoonup" "\\xleftarrow")) (?> ("\\to" "\\rightharpoonup" "\\xrightarrow")) (?B ("\\bullet")) (?C ("\\widecheck{?}" "\\check{?}")) (?F ("\\Phi" "\\Varphi")) (?M ("\\begin{bsmallmatrix}?\\end{bsmallmatrix}")) (?P ("\\Prod{?}" "\\Pi" "\\partial")) (?S ("\\Sum{?}" "\\Sigma" "\\arcsin")) (?\"("^{\\prime\\prime}" "\\prime\\prime")) (?a ("\\alpha" "\\cap" "\\sqcap")) (?c ("\\cat{?}" "\\catn{?}")) (?e ("\\varepsilon" "\\epsilon" "\\exp{?}")) (?i ("\\iota" "\\in")) (?j ("{\\id^{h}}_{?}" "{\\id^{v}}_{?}")) (?r ("\\rho" "\\varrho" "\\restrict{?}")) (?u ("\\upsilon" "\\cup" "\\sqcup")) (?y ("\\psi" "\\Psi")) (?{ ("\\subseteq" "\\subsetneq")) (?} ("\\supseteq" "\\supsetneq")) )))