-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tex-bar.el
512 lines (469 loc) · 21.9 KB
/
tex-bar.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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
;;; tex-bar.el --- toolbar icons on AUCTeX in GNU emacs. -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
;; Author: Miguel V. S. Frasson <[email protected]>
;; Maintainer: [email protected]
;; Keywords: tool-bar, tex, latex
;; This file is part of AUCTeX.
;; AUCTeX 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.
;; AUCTeX 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 <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This package also needs `toolbar-x.el', and `latex.el' for the
;; symbol-toolbar.
;;; Use of this preliminary version:
;; - Add `LaTeX-install-toolbar' to `LaTeX-mode-hook'.
;; Special requirements for the use of experimental symbol-toolbar:
;; - Customize `TeX-bar-LaTeX-buttons', adding the label
;; `LaTeX-symbols-experimental' at the end.
;; - You should have a folder called "symb-pics" with the pics of the
;; symbols (xpm format is a good one), and the *parent* of this
;; folder should be in `load-path'.
;; Did you read carefully this item? I will say again: the folder
;; "symb-pics" should *not* be in `load-path', but its *parent*.
;; - each image file is named after the command that it represents in
;; the following rules: the base name is the name of the command
;; without the escape character "\", like \delta -> "delta.xpm";
;; however, since in some OS filenames are case insensitive, all
;; occurences of capital letter should be replaced by the letter
;; plus a dash: \Rightarrow -> "R-ightarrow.xpm" --- actually, for
;; the correct name, apply `TeX-bar-img-filename' to "Rightarrow"
;; (TeX-bar-img-filename "Rightarrow")
;; --> "R-ightarrow"
;; The function `TeX-bar-img-filename' also treats special commands
;; like `\{', `\|', etc.
;; You can get the symbol images on (temporary solution)
;; http://www.math.leidenuniv.nl/~frasson/symb-pics.tar.gz
;;; Code:
(require 'custom)
(require 'toolbar-x)
(require 'tex)
;; For the symbol toolbar
(require 'latex)
;;; Standard buttons
;; help strings
(defun TeX-bar-help-from-command-list (item)
"Return the help string of ITEM in `TeX-command-list'.
If there is no help, the empty string is returned."
(let ((help (nth 1 (memq :help (assoc item TeX-command-list)))))
(if help help "")))
(defgroup TeX-tool-bar nil
"Tool bar support in AUCTeX."
:group 'AUCTeX)
(defcustom TeX-bar-TeX-buttons
'(new-file open-file dired kill-buffer save-buffer cut copy paste undo
separator tex next-error view bibtex spell)
"List of buttons available in `plain-TeX-mode'.
It should be a list in the same format of the BUTTONS parameter
in function `toolbarx-install-toolbar', often a symbol that
labels a button.
Type `\\[TeX-bar-TeX-buttons]' for a list of available buttons.
Buttons are defined in alists (labels associated to properties
that define a button). For a list of variables that hold such
alists, see variable `TeX-bar-TeX-all-button-alists'."
:type '(list (set :inline t
(const new-file)
(const open-file)
(const dired)
(const kill-buffer)
(const save-buffer)
(const write-file)
(const undo)
(const cut)
(const copy)
(const paste)
(const search-forward)
(const print-buffer)
(const separator)
(const tex)
(const next-error)
(const view)
(const file)
(const bibtex)
(const clean)
(const spell))
;; (const latex-symbols-experimental)
(repeat (choice (symbol :tag "Label")
(sexp :tag "General element"))))
:group 'TeX-tool-bar)
(defgroup TeX-tool-bar-button-definitions nil
"Collections of button definitions."
:group 'TeX-tool-bar)
(defcustom TeX-bar-TeX-all-button-alists
'(TeX-bar-TeX-button-alist
toolbarx-default-toolbar-meaning-alist)
"List of variables that hold buttons properties.
Each element should be a symbol bound to list in the format of
the argument BUTTON-ALIST in function `toolbarx-install-toolbar'."
:type '(repeat variable)
:group 'TeX-tool-bar-button-definitions)
(defcustom TeX-bar-TeX-button-alist
`((tex :image ,(lambda nil (if TeX-PDF-mode "pdftex" "tex"))
:command (progn
(TeX-save-document #'TeX-master-file)
(TeX-command "TeX" #'TeX-master-file -1))
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "TeX")))
(pdftex :image "pdftex"
:command (progn
(TeX-save-document #'TeX-master-file)
(TeX-command "PDFTeX" #'TeX-master-file -1))
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "PDFTeX")))
(next-error :image "error"
:command TeX-next-error
:enable (TeX-error-report-has-errors-p)
:visible (TeX-error-report-has-errors-p))
(view :image ,(lambda nil (if TeX-PDF-mode "viewpdf" "viewdvi"))
:command (TeX-command "View" #'TeX-master-file -1)
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "View")))
(file :image "dvips"
:command (TeX-command "File" #'TeX-master-file -1)
:visible (not TeX-PDF-mode)
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "File")))
(bibtex :image "bibtex"
:command (TeX-command "BibTeX" #'TeX-master-file -1)
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "BibTeX")))
(clean :image "delete"
:command (TeX-command "Clean" #'TeX-master-file -1)
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "Clean")))
(spell :image "spell"
:command (TeX-command "Spell" #'TeX-master-file -1)
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "Spell"))))
;; latex-symbols-experimental?
"Alist for button definitions in TeX bar.
Value should le a list where each element is of format (KEY .
PROPS), where KEY is a symbol that labels the button and PROPS is
a list of properties of the button. For a description of the
format of PROPS, please see documentation of function
`toolbarx-install-toolbar'. This custom variable is in the same
format of the argument MEANING-ALIST in the mentioned function."
:type '(alist :key-type symbol :value-type sexp)
:group 'TeX-tool-bar-button-definitions)
(defun TeX-bar-TeX-buttons ()
"Display in a buffer a list of buttons for `tex-bar.el'."
(interactive)
(let ((assqs-button-alists)
(labels))
(dolist (m-alist TeX-bar-TeX-all-button-alists)
(setq labels nil)
(dolist (as (eval m-alist t))
(setq labels (cons (car as) labels)))
(setq assqs-button-alists (cons (cons m-alist (nreverse labels))
assqs-button-alists)))
(setq assqs-button-alists (nreverse assqs-button-alists))
;; displaying results
(with-current-buffer (get-buffer-create "*TeX tool bar buttons*")
(erase-buffer)
(insert "Available buttons for TeX mode
================================")
(dolist (i assqs-button-alists)
(insert (format "\n\n`%s' provides the following buttons:\n " (car i)))
(dolist (j (cdr i))
(insert (format " %s" j)))
(fill-region (line-beginning-position) (line-end-position))))
(display-buffer "*TeX tool bar buttons*" t)))
;;; Installation of the tool bar
;;;###autoload
(defun TeX-install-toolbar ()
"Install toolbar buttons for TeX mode."
(interactive)
(add-to-list 'toolbarx-image-path
(expand-file-name "images" TeX-data-directory))
(add-hook 'TeX-PDF-mode-hook #'toolbarx-refresh nil t)
(toolbarx-install-toolbar TeX-bar-TeX-buttons
(let ((append-list))
(dolist (elt TeX-bar-TeX-all-button-alists)
(setq append-list (append append-list
(eval elt t))))
append-list)))
(defcustom TeX-bar-LaTeX-buttons
'(new-file open-file dired kill-buffer save-buffer cut copy paste undo
separator latex next-error view bibtex spell)
"List of buttons available in `LaTeX-mode'.
It should be a list in the same format of the BUTTONS parameter
in function `toolbarx-install-toolbar', often a symbol that
labels a button.
Type `\\[TeX-bar-LaTeX-buttons]' for a list of available buttons.
Buttons are defined in alists (labels associated to properties
that define a button). For a list of variables that hold such
alists, see variable `TeX-bar-LaTeX-all-button-alists'."
:type '(list (set :inline t
(const new-file)
(const open-file)
(const dired)
(const kill-buffer)
(const save-buffer)
(const write-file)
(const undo)
(const cut)
(const copy)
(const paste)
(const search-forward)
(const print-buffer)
(const separator)
(const latex)
(const next-error)
(const view)
(const file)
(const bibtex)
(const clean)
(const spell)
(const latex-symbols-experimental))
(repeat (choice (symbol :tag "Label")
(sexp :tag "General element"))))
:group 'TeX-tool-bar)
(defcustom TeX-bar-LaTeX-all-button-alists
'(TeX-bar-LaTeX-button-alist
toolbarx-default-toolbar-meaning-alist)
"List of variables that hold buttons properties.
Each element should be a symbol bound to list in the format of
the argument BUTTON-ALIST in function `toolbarx-install-toolbar'."
:type '(repeat variable)
:group 'TeX-tool-bar-button-definitions)
(defcustom TeX-bar-LaTeX-button-alist
`((latex :image ,(lambda nil (if TeX-PDF-mode "pdftex" "tex"))
:command (progn
(TeX-save-document #'TeX-master-file)
(TeX-command "LaTeX" #'TeX-master-file -1))
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "LaTeX")))
(pdflatex :image "pdftex"
:command (progn
(TeX-save-document #'TeX-master-file)
(TeX-command "PDFLaTeX" #'TeX-master-file -1))
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "PDFLaTeX")))
(next-error :image "error"
:command TeX-next-error
:enable (TeX-error-report-has-errors-p)
:visible (TeX-error-report-has-errors-p))
(view :image ,(lambda nil (if TeX-PDF-mode "viewpdf" "viewdvi"))
:command (TeX-command "View" #'TeX-master-file -1)
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "View")))
(file :image "dvips"
:command (TeX-command "File" #'TeX-master-file -1)
:visible (not TeX-PDF-mode)
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "File")))
(bibtex :image "bibtex"
:command (TeX-command (if LaTeX-using-Biber "Biber" "BibTeX")
#'TeX-master-file -1)
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list
(if LaTeX-using-Biber "Biber" "BibTeX"))))
(clean :image "delete"
:command (TeX-command "Clean" #'TeX-master-file -1)
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "Clean")))
(spell :image "spell"
:command (TeX-command "Spell" #'TeX-master-file -1)
:help ,(lambda (&rest _ignored)
(TeX-bar-help-from-command-list "Spell")))
(latex-symbols-experimental . (:alias :eval-group
LaTeX-symbols-toolbar-switch-contents
LaTeX-symbols-toolbar-contents)))
"Alist for button definitions in TeX bar.
Value should le a list where each element is of format (KEY .
PROPS), where KEY is a symbol that labels the button and PROPS is
a list of properties of the button. For a description of the
format of PROPS, please see documentation of function
`toolbarx-install-toolbar'. This custom variable is in the same
format of the argument MEANING-ALIST in the mentioned function."
:type '(alist :key-type symbol :value-type sexp)
:group 'TeX-tool-bar-button-definitions)
(defun TeX-bar-LaTeX-buttons ()
"Display in a buffer a list of buttons for `tex-bar.el'."
(interactive)
(let ((assqs-button-alists)
(labels))
(dolist (m-alist TeX-bar-LaTeX-all-button-alists)
(setq labels nil)
(dolist (as (eval m-alist t))
(setq labels (cons (car as) labels)))
(setq assqs-button-alists (cons (cons m-alist (nreverse labels))
assqs-button-alists)))
(setq assqs-button-alists (nreverse assqs-button-alists))
;; displaying results
(with-current-buffer (get-buffer-create "*TeX tool bar buttons*")
(erase-buffer)
(insert "Available buttons for LaTeX mode
================================")
(dolist (i assqs-button-alists)
(insert (format "\n\n`%s' provides the following buttons:\n " (car i)))
(dolist (j (cdr i))
(insert (format " %s" j)))
(fill-region (line-beginning-position) (line-end-position))))
(display-buffer "*TeX tool bar buttons*" t)))
;;; Installation of the tool bar
;;;###autoload
(defun LaTeX-install-toolbar ()
"Install toolbar buttons for LaTeX mode."
(interactive)
(add-to-list 'toolbarx-image-path
(expand-file-name "images" TeX-data-directory))
(add-hook 'TeX-PDF-mode-hook #'toolbarx-refresh nil t)
;; Refresh the toolbar after styles update because `LaTeX-using-Biber' value
;; could have been changed. Append the refresh to the hook so it is run after
;; the other styles-related changes.
(add-hook 'TeX-update-style-hook #'toolbarx-refresh t t)
(toolbarx-install-toolbar TeX-bar-LaTeX-buttons
(let ((append-list))
(dolist (elt TeX-bar-LaTeX-all-button-alists)
(setq append-list (append append-list
(eval elt t))))
append-list)))
;;; Experimental Symbol Toolbar
;;; symbol toolbar
(defun TeX-bar-img-filename (tex-command)
"Return the filename (no extension) for the image button of TEX-COMMAND."
(let ((str-list (append tex-command nil))
(str-result))
(dolist (i str-list)
(cond
;; capital letter -> letter + "-"
((and (>= i ?A) (<= i ?Z))
(setq str-result (cons ?- (cons i str-result))))
;; lowercase letter -> letter
((and (>= i ?a) (<= i ?z))
(setq str-result (cons i str-result)))
;; open curly brackets `{' -> "ocb--"
((eq i ?{)
(setq str-result (cons ?o str-result))
(setq str-result (cons ?c str-result))
(setq str-result (cons ?b str-result))
(setq str-result (cons ?- str-result))
(setq str-result (cons ?- str-result)))
;; close curly brackets `}' -> "ccb--"
((eq i ?})
(setq str-result (cons ?c str-result))
(setq str-result (cons ?c str-result))
(setq str-result (cons ?b str-result))
(setq str-result (cons ?- str-result))
(setq str-result (cons ?- str-result)))
;; vertical bar `|' -> "v--"
((eq i ?|)
(setq str-result (cons ?v str-result))
(setq str-result (cons ?- str-result))
(setq str-result (cons ?- str-result)))
;; slash `/' -> "s--"
((eq i ?/)
(setq str-result (cons ?s str-result))
(setq str-result (cons ?- str-result))
(setq str-result (cons ?- str-result)))))
(concat (nreverse str-result))))
(let* ((menu-strings-buttons-alist
;; make a alist os strings with the symbol classes and store it in
;; `menu-strings-alist'
(let* ((menu-strings-alist-temp))
(dolist (item-external (cdr LaTeX-math-menu)
(nreverse menu-strings-alist-temp))
(when (listp item-external)
;; if first element is vector, I am supposing that all are
;; vectors as well
(if (vectorp (cadr item-external))
(let* ((menu-str (car item-external))
(menu-buttons))
(dolist (button (cdr item-external))
(setq menu-buttons
(cons (list (intern (TeX-bar-img-filename
(aref button 0)))
:image
(concat "symb-pics/"
(TeX-bar-img-filename
(aref button 0)))
:help (aref button 0)
:command (aref button 1))
menu-buttons)))
(setq menu-buttons (nreverse menu-buttons))
(setq menu-strings-alist-temp
(cons (cons menu-str (list menu-buttons))
menu-strings-alist-temp)))
;; if another list (therefore, up to second level menu)
(let ((parent-str (concat (car item-external) " ")))
(dolist (item-internal (cdr item-external))
(unless (equal (car item-internal) "Special")
(let* ((menu-str (concat parent-str
(car item-internal)))
(menu-buttons))
(dolist (button (cdr item-internal))
(setq menu-buttons
(cons (list (intern (aref button 0))
:image
(concat "symb-pics/"
(TeX-bar-img-filename
(aref button 0)))
:help (aref button 0)
:command (aref button 1))
menu-buttons)))
(setq menu-buttons (nreverse menu-buttons))
(setq menu-strings-alist-temp
(cons (cons menu-str (list menu-buttons))
menu-strings-alist-temp)))))))))))
(list-strings (let* ((list-str-temp))
(dolist (i menu-strings-buttons-alist)
(setq list-str-temp (cons (car i)
list-str-temp)))
(nreverse list-str-temp))))
;; Will be defined by running LaTeX-install-toolbar.
(defvar LaTeX-symbols-active-menuitem)
(defvar LaTeX-symbols-toolbar-visible-flag nil
"Non-nil means that the LaTeX symbols on toolbar are visible.
Internal variable.")
(defconst LaTeX-symbols-toolbar-switch-contents
`(;; the on-off switch button
(latex-symbols-switch
:image ,(lambda ()
(if LaTeX-symbols-toolbar-visible-flag
"ltx-symb-turn-off"
"ltx-symb-turn-on"))
:command (progn
(setq LaTeX-symbols-toolbar-visible-flag
(not LaTeX-symbols-toolbar-visible-flag))
(toolbarx-refresh))
;; help message depends on if symb-toolbar is on or off, and in
;; the name of the current class of symbols
:help ,(lambda (&rest _ignore)
(concat "Turn "
(if LaTeX-symbols-toolbar-visible-flag "off " "on ")
"the toolbar of LaTeX symbols (current class: "
(nth (1- LaTeX-symbols-active-menuitem)
list-strings)
")")))
;; the dropdown button, that also switch on the symbols
,(append '(:dropdown-group)
list-strings
'(:variable
LaTeX-symbols-active-menuitem
:save offer
:dropdown-prepend-command
(setq LaTeX-symbols-toolbar-visible-flag t)
:dropdown-help "Select a class of symbols to be displayed"))))
(defconst LaTeX-symbols-toolbar-contents
(let* ((ltx-symb)
(count 0))
(dolist (i menu-strings-buttons-alist
(append (nreverse ltx-symb)
'(:insert
LaTeX-symbols-toolbar-visible-flag
:toolbar (bottom . top))))
(setq count (1+ count))
(setq ltx-symb
(cons (append (cdr i)
`(:insert (eq LaTeX-symbols-active-menuitem
,count)))
ltx-symb))))))
(provide 'tex-bar)
;;; tex-bar.el ends here