summaryrefslogtreecommitdiff
path: root/emacs/inits/24-latex.el
blob: 98eb70c4784d14a830cd15cb930e5f0137a054f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
;; Time-stamp: <2019-05-27 11:22:10 (tslil@basingstoke)>

(defvar latex-template-dir (expand-file-name "~/academic/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 (ivy-read "Select template: " tfiles)))
      (when template
        (goto-char (point-min))
        (insert-file-contents (concat latex-template-dir "/" template))
        (search-forward "begin{document}")
        (forward-line)
        (save-buffer)))))

;; Why does this not work?
;; (use-package cdm-mode
;;   :functions cdm-mode
;;   :defer t
;;   :load-path "~/.emacs.d/scripts/")
(autoload 'cdm-mode "cdm-mode" nil t)

(use-package company-auctex :ensure t :defer t)

(use-package latex
  :ensure auctex
  :bind (:map LaTeX-mode-map
              ("'" . better-TeX-insert-single-quote)
              ("TAB" . LaTeX-indent-line))
  :hook (LaTeX-mode . (lambda ()
                        (require 'company-auctex)
                        (electric-pair-local-mode -1)
                        (flyspell-mode)
                        (turn-on-auto-fill)
                        (cdlatex-mode t)
                        (company-auctex-init)
                        (siege-mode 1)
                        (cdm-mode)
                        (prompt-latex-file-template)))
  :init
  (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
  (add-to-list 'LaTeX-indent-environment-list
               '("diagram"))
  (add-to-list 'LaTeX-indent-environment-list
               '("diagram*"))


  (add-to-list 'TeX-command-list '("XeLaTeX" "xelatex %t" TeX-run-TeX nil
                                   (latex-mode doctex-mode)
                                   :help "Run XeLaTeX"))

  (setq TeX-electric-sub-and-superscript t
        TeX-electric-math '("$" . "$")
        TeX-electric-escape nil
        LaTeX-electric-left-right-brace t)

  (setq-default TeX-master nil)
  (setq TeX-auto-save t
        TeX-parse-self t
        TeX-PDF-mode t
        TeX-source-correlate-mode nil
        TeX-view-program-selection '( ((output-dvi style-pstricks) "dvips and gv")
                                      (output-dvi "xdvi")
                                      (output-pdf "Zathura")
                                      (output-html "xdg-open"))))


(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)
                                    (?t "\\trm" "\\trm" t nil nil)
                                    (?y "\\ty" "\\ty" t nil nil)
                                    (?v "\\texttt" "\\texttt" t nil nil)
                                    (?u "\\tyu" "\\tyu" t nil nil)
                                    (?k "\\mathfrak" nil t nil nil)
                                    (?` 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"))
                                    (?- ("\\vdash" "\\setminus" "\\triangle"))
                                    (?. ("\\sq" "\\circ" "\\cdot"))
                                    (?0 ("\\emptyset" "\\circ"))
                                    (?\; ("\\col"))
                                    (?< ("\\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"))
                                    (?{ ("\\subseteq" "\\subsetneq"))
                                    (?} ("\\supseteq" "\\supsetneq"))
                                    )))

(use-package doc-view
  :defer t
  :functions doc-view-mode
  :hook (doc-view-mode . auto-revert-mode)
  :config   (setq doc-view-resolution 300
                  doc-view-continuous t))