/
auctex-config.el
371 lines (298 loc) · 12.8 KB
/
auctex-config.el
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
;; configuration for AUCTeX on OS X
;; Maintainer: David Reitter
;; originally authored by Kevin Walzer
;; Keywords: auctex
;; This file is part of Aquamacs Emacs
;; http://www.aquamacs.org/
;; Aquamacs Emacs 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, or (at your option)
;; any later version.
;; Aquamacs Emacs 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 Aquamacs Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;; Copyright (C) 2005, 2008, 2009, Kevin Walzer, David Reitter
;; set the PATH to typical locations for TeX stuff
(mapc (lambda (path)
(setenv "PATH"
(concat (getenv "PATH") ":" path))
(add-to-list 'exec-path path 'append))
(append
; prefer TeXLive installation
'("/usr/texbin")
; in case /usr/texbin is missing
(reverse (sort (file-expand-wildcards
"/usr/local/texlive/20*/bin")
'string<))
; over older teTex.
(reverse (sort (file-expand-wildcards
"/usr/local/teTeX/bin/*-apple-darwin-current")
'string<))))
;; make sure auctex is loaded from the correct place,
;; i.e. the first file in load-path
;; load the right auctex.el (first one in load-path)
;; (locate-library "auctex.el" t)
(load "auctex.el" nil nil t)
;; this is not done by default
;; maybe add a menu option?
;;(load "preview-latex.el" nil t t)
(aquamacs-set-defaults '(
( TeX-parse-self t)
( TeX-master t) ;; set default
( reftex-plug-into-AUCTeX t)
( reftex-save-parse-info t)
( reftex-use-multiple-selection-buffers t)
( bib-highlight-mouse-t nil)
( bib-cite-use-reftex-view-crossref t)))
(autoload 'bib-cite-minor-mode "bib-cite")
(autoload 'turn-on-bib-cite "bib-cite")
; only load if ghostscript is installed
; (aquamacs-latex-find-style-file-paths)
;; (defun aquamacs-latex-find-style-file-paths ()
;; "Find TeXLive distribution path."
;; (let ((latex-executable
;; ;; find out the selected TeXlive distribution
;; ;; or another distribution that has a texmf directory
;; (with-temp-buffer
;; (shell-command "which latex " t)
;; (if (string-match "^no " (buffer-string))
;; (message
;; "No latex binary found.")
;; (buffer-substring (point-min) (max 0 (- (point-max) (if (eq (char-before (point-max)) 10) 1 0))))))))
;; ;; how does one print the search path from tex?
;; (let ((path (file-name-directory (file-truename latex-executable)))
;; (count 0 ))
;; (while (and (file-exists-p path)
;; (not (equal path "/"))
;; (< count 5)
;; (not (or (file-directory-p (concat path "/texmf" ))
;; (file-directory-p (concat path "/share/texmf" )))))
;; (file-truename latex-executable)
;; (setq count (1+ count))
;; (setq path (file-truename (concat path "/.."))))
;; (apply #'nconc
;; (mapcar
;; (lambda (file)
;; (if (and (> (length file) 1) (file-exists-p file))
;; (list file)))
;; (append (list (concat path "/texmf/tex")
;; (concat path "/texmf-dist/tex")
;; (concat path "/share/texmf/tex") ; used in older teTeX
;; (concat path "/share/texmf.os/tex")
;; (concat path "/share/texmf.local/tex")
;; "/usr/local/texlive/texmf-local/tex"
;; "~/Library/texmf/tex/")
;; (split-string (getenv "TEXINPUTS") ":")
;; ))))))
(defvar aq-preview-latex-checked nil)
(defun load-preview-if-ghostscript ()
"Loads preview-latex.el in case Ghostscript is installed.
Only checks once - subsequent calls will not result in any action."
(unless aq-preview-latex-checked
(with-temp-buffer
(shell-command "which pdf2dsc " t)
(if (string-match "^no " (buffer-string))
(message
"No Ghostscript (pdf2dsc) found - preview-latex not activated.")
(load "preview-latex.el" nil t nil)))
(setq aq-preview-latex-checked t)) nil)
;; must be done here do initialize
;; can't be loaded in hook later on.
(load-preview-if-ghostscript)
(autoload 'preview-mode-setup "preview")
(defvar LaTeX-mode-hook nil) ;; make sure it's defined
;; (add-hook 'LaTeX-mode-hook 'load-preview-if-ghostscript)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(add-hook 'LaTeX-mode-hook 'turn-on-bib-cite)
(add-hook 'LaTeX-mode-hook (lambda () (TeX-fold-mode t)))
(add-hook 'TeX-mode-hook 'aquamacs-latex-viewer-support 'append) ;; load reftex first
;; Allow open buffers in latex-mode to be processed identically to new
;; buffers processed according to text-mode-hook (specifically for
;; Flyspell)
(put 'latex-mode 'derived-mode-parent 'text-mode)
;; this is much slower
;; (defun fln (&optional buffer-pos)
;; (unless buffer-pos (setq buffer-pos (point)))
;; (save-excursion
;; (goto-char 0)
;; (let ((count 0))
;; (while (search-forward "\n" buffer-pos t)
;; (if (get-text-property (match-beginning 0) 'hard)
;; (setq count (1+ count))))
;; count)))
(defun aquamacs-latex-crossref (ev)
"Cross-reference in LaTeX"
(interactive "e")
(save-excursion
(mouse-set-point ev)
(condition-case nil
(let ((aquamacs-ring-bell-on-error-flag nil))
(reftex-view-crossref current-prefix-arg))
(error
(TeX-command "Jump to PDF" 'TeX-master-file))
nil )))
(defun aquamacs-skim-running-p ()
(ignore-errors
(> (string-to-number
(with-temp-buffer
(shell-command "ps ax | grep --count -e '[Ss]kim.app'" t)
(buffer-string)))
0)))
(defvar aquamacs-skim-timer nil)
(defvar aquamacs-skim-show-info-message t)
(defcustom aquamacs-always-use-skim nil
"If t, Aquamacs always uses Skim as viewer in AUCTeX.
If nil Aquamacs uses Skim if and only if it has been running."
:group 'Aquamacs
:version "22.1"
:type 'boolean)
(defun aquamacs-check-for-skim ()
"Show help message if Skim.app is running."
(and (equal major-mode 'latex-mode) (boundp 'TeX-PDF-mode) TeX-PDF-mode
(file-readable-p (expand-file-name
(TeX-master-file (TeX-output-extension))
(and buffer-file-name
(file-name-directory buffer-file-name))))
;; check for running
(or aquamacs-always-use-skim (aquamacs-skim-running-p))
(if (not (equal TeX-command-Show "View"))
t ;; customized by user
(set-default 'TeX-command-Show "Jump to PDF"))
;; (if (not (equal (cdr-safe
;; (cdr-safe
;; (assq-string-equal "^pdf$" TeX-output-view-style)))
;; '("open %o")))
;; ;; has not been changed by us or the user
;; t
;; ;; this variable should not be automatically saved by "Save Options"
;; ;; (unless user customizes it explicitly)
;; (setq TeX-output-view-style
;; (cons '("^pdf$" "." "open -a Skim.app %o")
;; TeX-output-view-style)))
(cancel-timer aquamacs-skim-timer)
aquamacs-skim-show-info-message
(message
(substitute-command-keys
(format
"Skim detected. Use \\[aquamacs-latex-crossref]%s to jump to the PDF and back."
(if (eq 'control mac-emulate-three-button-mouse)
" (Shift-Apple-Click)" ""))))))
(defun aquamacs-check-emacsclient-version ()
(let ((emacsclient-min-version "23.0")
emacsclient-version)
(with-temp-buffer
(call-process "emacsclient" nil t nil "-V")
(goto-char (point-min))
(setq emacsclient-version
(and (search-forward-regexp "\\([0-9]+\\.[0-9\\.]+\\)" nil t)
(match-string 1))))
(if (version< emacsclient-version emacsclient-min-version)
(message "Warning - emacsclient version (%s) too low; must be >= %s for Skim support.
Use Tools --> Install Command Line Tools to update."
emacsclient-version emacsclient-min-version))))
(defun aquamacs-latex-viewer-support ()
"Support for Skim as LaTeX viewer if present."
(add-to-list 'TeX-command-list
'("Jump to PDF"
"(aquamacs-call-viewer %n \"%b\")"
TeX-run-function nil t
:help "Jump here in Skim") 'append)
(and (boundp 'reftex-mode-map) reftex-mode-map
(define-key reftex-mode-map [(shift mouse-2)] nil))
(and (boundp 'LaTeX-mode-map) LaTeX-mode-map
(define-key LaTeX-mode-map [(shift mouse-2)]
'aquamacs-latex-crossref))
(unless aquamacs-skim-timer ;; just once per session
(setq aquamacs-skim-timer
(run-with-idle-timer 30 t 'aquamacs-check-for-skim)))
;; warn if emacsclient version is too low to work with Aquamacs"
;; use idle timer to ensure that message can be seen in echo area
(run-with-idle-timer 1 nil 'aquamacs-check-emacsclient-version)
(unless server-process
(server-force-delete)
;; start server to make emacsclient work
(server-start)))
(require 'server)
(if (boundp 'aquamacs-default-toolbarx-meaning-alist) ;; not on TTY
(aquamacs-set-defaults
'((TeX-PDF-mode t)
;; Toolbar business
(TeX-bar-TeX-all-button-alists
(TeX-bar-TeX-button-alist aquamacs-default-toolbarx-meaning-alist))
(TeX-bar-LaTeX-all-button-alists
(TeX-bar-LaTeX-button-alist aquamacs-default-toolbarx-meaning-alist))
(TeX-bar-TeX-buttons
(open-file save-buffer write-file [separator nil] cut copy paste undo
[separator nil] tex next-error view bibtex))
(TeX-bar-LaTeX-buttons
(open-file save-buffer write-file [separator nil] cut copy paste undo
[separator nil] latex next-error view bibtex)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Customize LaTeX parameters
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; the following seem not to be AUCTeX variables ...
;; obsolete?
;; ;; PDF previewer
;; (setq pdf-previewer-program "open")
;; ;; PS previewer
;; (setq ps-previewer-program "open")
;; ;; DVI previewer
;; (setq dvi-previewer-program "open-x11 xdvi")
;; The LaTeX commands
;; this is NOT ONLY THE MENU, but also forms commands that
; AUCTeX relies on. We can't just change the strings here and
; expect that things work - in particular, the default values
; that are set (when reading the command in the input buffer)
; are hard-coded.
;; modify the default command list
;; This is duplicated from AUCTeX, unfortunately
(aquamacs-set-defaults
`(;; (LaTeX-command "latex --file-line-error -synctex=1")
;; Directories containing the sites TeX macro files and style files
;; AucTeX defines its own (TeX-macro-global), which serves the same function
;; (TeX-macro-global ,(aquamacs-latex-find-style-file-paths))
;; for TeX-command-list
;; ("XɘLaTeX" "xelatex \"%(mode)\\input{%t}\""
;; TeX-run-TeX nil (latex-mode context-mode))
; no XDVI on the Mac
; we just use 'open'
; This TeXniscope support requires the option to be specified
; it's unclear whether this should stay that way
(TeX-output-view-style
(("^dvi$" "^xdvi$" "open-x11 %(o?)xdvi %dS %d") ; %(o?) is 'o' if Omega mode
("^dvi$" "^TeXniscope$" "open -a TeXniscope.app %o")
("^pdf$" "." "open %o")
("^html?$" "." "open %o"))
)))
;(setq TeX-command-list
;; (list
;; (list "-" "" nil nil nil)
;; (list "Compile LaTeX to PDF (pdfLaTeX)" "pdflatex '\\nonstopmode\\input{%t}'" 'TeX-run-LaTeX nil t)
;; (list "View PDF" "open %s.pdf" 'TeX-run-command nil t)
;; (list "Compile & View" "pdflatex '\\nonstopmode\\input{%t}';open %s.pdf" 'TeX-run-LaTeX nil t)
;; (list "-" "" nil nil nil)
;; (list "Compile with LaTeX" "%l '\\nonstopmode\\input{%t}'" 'TeX-run-LaTeX nil t)
;; (list "Convert DVI->Postscript..." "dvips %d -o %f " 'TeX-run-command t t )
;; (list "Convert DVI->PDF..." "dvipdf %d %s.pdf" 'TeX-run-command t t)
;; (list "View DVI" "open-x11 xdvi %s.dvi..." 'TeX-run-command t t)
;; (list "View DVI with TeXniscope" "open -a TeXniscope.app %s.dvi..." 'TeX-run-command t t)
;; (list "View" "open %s.ps" 'TeX-run-command nil t)
;; ; this comment cannot be called "view PS"
;; ; because some defaults in Tex-buf assume it's called "View"
;; (list "-" "" nil nil nil)
;; (list "Compile Bibliography (BibTeX)" "bibtex %s" 'TeX-run-BibTeX nil t)
;; (list "Index" "makeindex %s" 'TeX-run-command nil t)
;; (list "Check Syntax" "lacheck %s" 'TeX-run-compile nil t)
;; (list "Spellcheck" "<ignored>" 'TeX-run-ispell-on-document nil t)
;; (list "-" "" nil nil nil)
;; (list "Convert to HTML" "htlatex %t;open %s.html" 'TeX-run-command t t)
;; (list "Makeinfo" "makeinfo %t" 'TeX-run-compile nil t)
;; (list "Makeinfo HTML" "makeinfo --html %t" 'TeX-run-compile nil t)
;; )
;; )
(provide 'auctex-config)