;;; tex-conf.el --- My configurations of TeX -*- lexical-binding: t; -*- ;; Copyright (C) 2021 李俊緯 ;; Author: 李俊緯 ;; Keywords: tex ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; This is my configuration file for (La)TeX. In particular I use and ;; configure the package AUCTeX here. ;;; Code: (load "auctex.el" nil t t) (load "preview-latex.el" nil t t) (setq TeX-auto-save t) (setq TeX-parse-self t) (setq TeX-view-program-selection '((output-dvi "open") (output-pdf "PDF Tools") (output-html "open"))) ;; I don't want to split the screen. ;;;###autoload (defun durand-TeX-pdf-tools-sync-view-a () "Advice to `TeX-pdf-tools-sync-view', which won't pop buffers." (unless (fboundp 'pdf-tools-install) (error "PDF Tools are not available")) (unless TeX-PDF-mode (error "PDF Tools only work with PDF output")) (add-hook 'pdf-sync-backward-redirect-functions #'TeX-source-correlate-handle-TeX-region) (if (and TeX-source-correlate-mode (fboundp 'pdf-sync-forward-search)) (with-current-buffer (or (when TeX-current-process-region-p (get-file-buffer (TeX-region-file t))) (current-buffer)) (pdf-sync-forward-search)) (let ((pdf (TeX-active-master (TeX-output-extension)))) (switch-to-buffer (or (find-buffer-visiting pdf) (find-file-noselect pdf)))))) (advice-add #'TeX-pdf-tools-sync-view :override #'durand-TeX-pdf-tools-sync-view-a) ;;; Dollars (setq TeX-electric-math (cons "\\(" "\\)")) (define-key LaTeX-mode-map (vector ?\§) #'durand-insert-escape) ;;;###autoload (defun durand-insert-escape () "Insert an escape character." (interactive) (insert "\\")) ;;; Expansions (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode) (define-key LaTeX-math-mode-map (LaTeX-math-abbrev-prefix) t) (set-default 'LaTeX-math-abbrev-prefix "ù") (define-key LaTeX-math-mode-map (LaTeX-math-abbrev-prefix) LaTeX-math-keymap) (cond ((boundp 'LaTeX-math-keymap)) ((defvar LaTeX-math-keymap))) (define-key LaTeX-math-keymap [?$] 'durand-insert-display-equation) (define-key LaTeX-math-keymap [?o] 'durand-insert-o-things) (setq LaTeX-math-list '((?$ durand-insert-display-equation) (?o durand-insert-o-things))) ;;;###autoload (defun durand-insert-display-equation () "Insert display equation symbols." (interactive) (insert "\\[\\]") (goto-char (- (point) 2))) ;;;###autoload (defvar durand-o-things-list nil "A list of things associated with the \"o\" key. Each entry should have the form (key . macro), where the macro part is without the backslash.") (setq durand-o-things-list (list (cons "x" "otimes") (cons "s" "sum") (cons "p" "prod") (cons "+" "oplus") (cons "o" "circ") (list "{" "{" "}"))) ;;;###autoload (defun durand-insert-o-things () "Insert a symbol associated with \"o\" key. The list is in the variable `durand-o-things-list'" (interactive) (let ((thing (minibuffer-with-setup-hook 'durand-headlong-minibuffer-setup-hook (completing-read "Chois une chose associée à \"o\":" (mapcar 'car durand-o-things-list) nil t "^")))) (let ((associated (alist-get thing durand-o-things-list nil nil #'string=))) (cond ((not (consp associated)) ;; length = 1 (insert (format "\\%s" (assoc-default thing durand-o-things-list #'string=)))) ((null (cddr associated)) ;; length = 2 (insert (format "\\left\\%s" (car associated))) (save-excursion (insert (format "\\right\\%s" (cadr associated))))) (t (user-error "Weird associated: %S" associated)))))) ;; Automatic braces (setq TeX-electric-sub-and-superscript t) ;;; If I need to type nested documents frequently, the following will ;;; come in handy. ;; (setq-default TeX-master nil) (provide 'tex-conf) ;;; tex-conf.el ends here