1 ;;; tex-bar.el --- toolbar icons on AUCTeX in GNU emacs and XEmacs
3 ;; Copyright (C) 2004-2008, 2012-2014, 2016 Free Software Foundation, Inc.
5 ;; This program is free software; you can redistribute it and/or
6 ;; modify it under the terms of the GNU General Public License as
7 ;; published by the Free Software Foundation; either version 3 of
8 ;; the License, or (at your option) any later version.
10 ;; This program is distributed in the hope that it will be
11 ;; useful, but WITHOUT ANY WARRANTY; without even the implied
12 ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 ;; PURPOSE. See the GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public
16 ;; License along with this program; if not, write to the Free
17 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 ;; Author: Miguel V. S. Frasson <frasson@math.leidenuniv.nl>
21 ;; Keywords: tool-bar, tex, latex
26 ;; This package also needs `toolbar-x.el', and `latex.el' for the
29 ;;; Use of this preliminary version:
31 ;; - Add `LaTeX-install-toolbar' to `LaTeX-mode-hook'.
33 ;; Special requirements for the use of experimental symbol-toolbar:
35 ;; - Customize `TeX-bar-LaTeX-buttons', adding the label
36 ;; `LaTeX-symbols-experimental' at the end.
38 ;; - You should have a folder called "symb-pics" with the pics of the
39 ;; symbols (xpm format is a good one), and the *parent* of this
40 ;; folder should be in `load-path'.
42 ;; Did you read carefully this item? I will say again: the folder
43 ;; "symb-pics" should *not* be in `load-path', but its *parent*.
45 ;; - each image file is named after the command that it represents in
46 ;; the following rules: the base name is the name of the command
47 ;; without the escape character "\", like \delta -> "delta.xpm";
48 ;; however, since in some OS filenames are case insensitive, all
49 ;; occurences of capital letter should be replaced by the letter
50 ;; plus a dash: \Rightarrow -> "R-ightarrow.xpm" --- actually, for
51 ;; the correct name, apply `TeX-bar-img-filename' to "Rightarrow"
52 ;; (TeX-bar-img-filename "Rightarrow")
54 ;; The function `TeX-bar-img-filename' also treats special commands
55 ;; like `\{', `\|', etc.
57 ;; You can get the symbol images on (temporary solution)
58 ;; http://www.math.leidenuniv.nl/~frasson/symb-pics.tar.gz
69 ;; For the symbol toolbar
75 (defun TeX-bar-help-from-command-list (item)
76 "Return the help string of ITEM in `TeX-command-list'.
77 If there is no help, the empty string is returned."
78 (let ((help (nth 1 (memq :help (assoc item TeX-command-list)))))
81 (defgroup TeX-tool-bar nil
82 "Tool bar support in AUCTeX."
85 (defcustom TeX-bar-TeX-buttons
86 '(new-file open-file dired kill-buffer save-buffer cut copy paste undo
87 [separator nil] tex next-error view bibtex spell)
88 "List of buttons available in `tex-mode'.
89 It should be a list in the same format of the BUTTONS parameter
90 in function `toolbarx-install-toolbar', often a symbol that
91 labels a button or Emacs/XEmacs choice of buttons.
93 Type `\\[TeX-bar-TeX-buttons]' for a list of available buttons.
95 Buttons are defined in alists (labels associated to properties
96 that define a button). For a list of variables that hold such
97 alists, see variable `TeX-bar-TeX-all-button-alists'."
98 :type '(list (set :inline t
109 (const search-forward)
111 (const [separator nil])
119 ;; (const latex-symbols-experimental)
120 (repeat (choice (symbol :tag "Label")
121 (vector :args ((symbol :tag "Label in Emacs ")
122 (symbol :tag "Label in XEmacs"))
123 :tag "Emacs/XEmacs choice")
124 (sexp :tag "General element"))))
125 :group 'TeX-tool-bar)
127 (defun TeX-bar-TeX-buttons ()
128 "Display in a buffer a list of buttons for `tex-bar.el'."
130 (let ((assqs-button-alists)
132 (dolist (m-alist TeX-bar-TeX-all-button-alists)
134 (dolist (as (eval m-alist))
135 (setq labels (cons (car as) labels)))
136 (setq assqs-button-alists (cons (cons m-alist (nreverse labels))
137 assqs-button-alists)))
138 (setq assqs-button-alists (nreverse assqs-button-alists))
139 ;; displaying results
140 (with-current-buffer (get-buffer-create "*TeX tool bar buttons*")
142 (insert "Available buttons for TeX mode
143 ================================")
144 (dolist (i assqs-button-alists)
145 (insert (format "\n\n`%s' provides the following buttons:\n " (car i)))
147 (insert (format " %s" j)))
148 (fill-region (point-at-bol) (point-at-eol))))
149 (display-buffer "*TeX tool bar buttons*" t)))
151 (defgroup TeX-tool-bar-button-definitions nil
152 "Collections of button definitions."
153 :group 'TeX-tool-bar)
155 (defcustom TeX-bar-TeX-all-button-alists
156 '(TeX-bar-TeX-button-alist
157 toolbarx-default-toolbar-meaning-alist)
158 "List of variables that hold buttons properties.
159 Each element should be a symbol bound to list in the format of
160 the argument BUTTON-ALIST in function `toolbarx-install-toolbar'."
161 :type '(repeat variable)
162 :group 'TeX-tool-bar-button-definitions)
164 (defcustom TeX-bar-TeX-button-alist
165 '((tex :image (lambda nil (if TeX-PDF-mode "pdftex" "tex"))
167 (TeX-save-document (TeX-master-file))
168 (TeX-command "TeX" 'TeX-master-file -1))
169 :help (lambda (&rest ignored)
170 (TeX-bar-help-from-command-list "TeX")))
171 (pdftex :image "pdftex"
173 (TeX-save-document (TeX-master-file))
174 (TeX-command "PDFTeX" 'TeX-master-file -1))
175 :help (lambda (&rest ignored)
176 (TeX-bar-help-from-command-list "PDFTeX")))
177 (next-error :image "error"
178 :command TeX-next-error
179 :enable (TeX-error-report-has-errors-p)
180 :visible (TeX-error-report-has-errors-p))
181 (view :image (lambda nil (if TeX-PDF-mode "viewpdf" "viewdvi"))
182 :command (TeX-command "View" 'TeX-master-file -1)
183 :help (lambda (&rest ignored)
184 (TeX-bar-help-from-command-list "View")))
186 :command (TeX-command "File" 'TeX-master-file -1)
187 :visible (not TeX-PDF-mode)
188 :help (lambda (&rest ignored)
189 (TeX-bar-help-from-command-list "File")))
190 (bibtex :image "bibtex"
191 :command (TeX-command "BibTeX" 'TeX-master-file -1)
192 :help (lambda (&rest ignored)
193 (TeX-bar-help-from-command-list "BibTeX")))
194 (clean :image "delete"
195 :command (TeX-command "Clean" 'TeX-master-file -1)
196 :help (lambda (&rest ignored)
197 (TeX-bar-help-from-command-list "Clean")))
198 (spell :image "spell"
199 :command (TeX-command "Spell" 'TeX-master-file -1)
200 :help (lambda (&rest ignored)
201 (TeX-bar-help-from-command-list "Spell"))))
202 ;; latex-symbols-experimental?
203 "Alist for button definitions in TeX bar.
204 Value should le a list where each element is of format (KEY .
205 PROPS), where KEY is a symbol that labels the button and PROPS is
206 a list of properties of the button. For a description of the
207 format of PROPS, please see documentation of function
208 `toolbarx-install-toolbar'. This custom variable is in the same
209 format of the argument MEANING-ALIST in the mentioned function."
210 :type '(alist :key-type symbol :value-type sexp)
211 :group 'TeX-tool-bar-button-definitions)
213 ;;; Installation of the tool bar
215 (defun TeX-install-toolbar ()
216 "Install toolbar buttons for TeX mode."
219 (add-to-list 'toolbarx-image-path
220 (expand-file-name "images" TeX-data-directory))
221 (add-hook 'TeX-PDF-mode-hook 'toolbarx-refresh nil t)
222 (toolbarx-install-toolbar TeX-bar-TeX-buttons
224 (dolist (elt TeX-bar-TeX-all-button-alists)
225 (setq append-list (append append-list
229 (defcustom TeX-bar-LaTeX-buttons
230 '(new-file open-file dired kill-buffer save-buffer cut copy paste undo
231 [separator nil] latex next-error view bibtex spell)
232 "List of buttons available in `latex-mode'.
233 It should be a list in the same format of the BUTTONS parameter
234 in function `toolbarx-install-toolbar', often a symbol that
235 labels a button or Emacs/XEmacs choice of buttons.
237 Type `\\[TeX-bar-LaTeX-buttons]' for a list of available buttons.
239 Buttons are defined in alists (labels associated to properties
240 that define a button). For a list of variables that hold such
241 alists, see variable `TeX-bar-LaTeX-all-button-alists'."
242 :type '(list (set :inline t
253 (const search-forward)
255 (const [separator nil])
263 (const latex-symbols-experimental))
264 (repeat (choice (symbol :tag "Label")
265 (vector :args ((symbol :tag "Label in Emacs ")
266 (symbol :tag "Label in XEmacs"))
267 :tag "Emacs/XEmacs choice")
268 (sexp :tag "General element"))))
269 :group 'TeX-tool-bar)
271 (defun TeX-bar-LaTeX-buttons ()
272 "Display in a buffer a list of buttons for `tex-bar.el'."
274 (let ((assqs-button-alists)
276 (dolist (m-alist TeX-bar-LaTeX-all-button-alists)
278 (dolist (as (eval m-alist))
279 (setq labels (cons (car as) labels)))
280 (setq assqs-button-alists (cons (cons m-alist (nreverse labels))
281 assqs-button-alists)))
282 (setq assqs-button-alists (nreverse assqs-button-alists))
283 ;; displaying results
284 (with-current-buffer (get-buffer-create "*TeX tool bar buttons*")
286 (insert "Available buttons for LaTeX mode
287 ================================")
288 (dolist (i assqs-button-alists)
289 (insert (format "\n\n`%s' provides the following buttons:\n " (car i)))
291 (insert (format " %s" j)))
292 (fill-region (point-at-bol) (point-at-eol))))
293 (display-buffer "*TeX tool bar buttons*" t)))
295 (defgroup TeX-tool-bar-button-definitions nil
296 "Collections of button definitions."
297 :group 'TeX-tool-bar)
299 (defcustom TeX-bar-LaTeX-all-button-alists
300 '(TeX-bar-LaTeX-button-alist
301 toolbarx-default-toolbar-meaning-alist)
302 "List of variables that hold buttons properties.
303 Each element should be a symbol bound to list in the format of
304 the argument BUTTON-ALIST in function `toolbarx-install-toolbar'."
305 :type '(repeat variable)
306 :group 'TeX-tool-bar-button-definitions)
308 (defcustom TeX-bar-LaTeX-button-alist
309 '((latex :image (lambda nil (if TeX-PDF-mode "pdftex" "tex"))
311 (TeX-save-document (TeX-master-file))
312 (TeX-command "LaTeX" 'TeX-master-file -1))
313 :help (lambda (&rest ignored)
314 (TeX-bar-help-from-command-list "LaTeX")))
315 (pdflatex :image "pdftex"
317 (TeX-save-document (TeX-master-file))
318 (TeX-command "PDFLaTeX" 'TeX-master-file -1))
319 :help (lambda (&rest ignored)
320 (TeX-bar-help-from-command-list "PDFLaTeX")))
321 (next-error :image "error"
322 :command TeX-next-error
323 :enable (TeX-error-report-has-errors-p)
324 :visible (TeX-error-report-has-errors-p))
325 (view :image (lambda nil (if TeX-PDF-mode "viewpdf" "viewdvi"))
326 :command (TeX-command "View" 'TeX-master-file -1)
327 :help (lambda (&rest ignored)
328 (TeX-bar-help-from-command-list "View")))
330 :command (TeX-command "File" 'TeX-master-file -1)
331 :visible (not TeX-PDF-mode)
332 :help (lambda (&rest ignored)
333 (TeX-bar-help-from-command-list "File")))
334 (bibtex :image "bibtex"
335 :command (TeX-command (if LaTeX-using-Biber "Biber" "BibTeX")
337 :help (lambda (&rest ignored)
338 (TeX-bar-help-from-command-list
339 (if LaTeX-using-Biber "Biber" "BibTeX"))))
340 (clean :image "delete"
341 :command (TeX-command "Clean" 'TeX-master-file -1)
342 :help (lambda (&rest ignored)
343 (TeX-bar-help-from-command-list "Clean")))
344 (spell :image "spell"
345 :command (TeX-command "Spell" 'TeX-master-file -1)
346 :help (lambda (&rest ignored)
347 (TeX-bar-help-from-command-list "Spell")))
348 (latex-symbols-experimental . (:alias :eval-group
349 LaTeX-symbols-toolbar-switch-contents
350 LaTeX-symbols-toolbar-contents)))
351 "Alist for button definitions in TeX bar.
352 Value should le a list where each element is of format (KEY .
353 PROPS), where KEY is a symbol that labels the button and PROPS is
354 a list of properties of the button. For a description of the
355 format of PROPS, please see documentation of function
356 `toolbarx-install-toolbar'. This custom variable is in the same
357 format of the argument MEANING-ALIST in the mentioned function."
358 :type '(alist :key-type symbol :value-type sexp)
359 :group 'TeX-tool-bar-button-definitions)
361 ;;; Installation of the tool bar
363 (defun LaTeX-install-toolbar ()
364 "Install toolbar buttons for LaTeX mode."
367 (add-to-list 'toolbarx-image-path
368 (expand-file-name "images" TeX-data-directory))
369 (add-hook 'TeX-PDF-mode-hook 'toolbarx-refresh nil t)
370 ;; Refresh the toolbar after styles update because `LaTeX-using-Biber' value
371 ;; could have been changed. Append the refresh to the hook so it is run after
372 ;; the other styles-related changes.
373 (add-hook 'TeX-update-style-hook 'toolbarx-refresh t t)
374 (toolbarx-install-toolbar TeX-bar-LaTeX-buttons
376 (dolist (elt TeX-bar-LaTeX-all-button-alists)
377 (setq append-list (append append-list
381 ;;; Experimental Symbol Toolbar
384 (defun TeX-bar-img-filename (tex-command)
385 "Return the filename (no extension) for the image button of TEX-COMMAND."
386 (let ((str-list (append tex-command nil))
390 ;; capital letter -> letter + "-"
391 ((and (>= i ?A) (<= i ?Z))
392 (setq str-result (cons ?- (cons i str-result))))
393 ;; lowercase letter -> letter
394 ((and (>= i ?a) (<= i ?z))
395 (setq str-result (cons i str-result)))
396 ;; open curly brackets `{' -> "ocb--"
398 (setq str-result (cons ?o str-result))
399 (setq str-result (cons ?c str-result))
400 (setq str-result (cons ?b str-result))
401 (setq str-result (cons ?- str-result))
402 (setq str-result (cons ?- str-result)))
403 ;; close curly brackets `}' -> "ccb--"
405 (setq str-result (cons ?c str-result))
406 (setq str-result (cons ?c str-result))
407 (setq str-result (cons ?b str-result))
408 (setq str-result (cons ?- str-result))
409 (setq str-result (cons ?- str-result)))
410 ;; vertical bar `|' -> "v--"
412 (setq str-result (cons ?v str-result))
413 (setq str-result (cons ?- str-result))
414 (setq str-result (cons ?- str-result)))
415 ;; slash `/' -> "s--"
417 (setq str-result (cons ?s str-result))
418 (setq str-result (cons ?- str-result))
419 (setq str-result (cons ?- str-result)))))
420 (concat (nreverse str-result))))
422 (let* ((menu-strings-buttons-alist
423 ;; make a alist os strings with the symbol classes and store it in
424 ;; `menu-strings-alist'
425 (let* ((menu-strings-alist-temp))
426 (dolist (item-external (cdr LaTeX-math-menu)
427 (nreverse menu-strings-alist-temp))
428 (when (listp item-external)
429 ;; if first element is vector, I am supposing that all are
431 (if (vectorp (cadr item-external))
432 (let* ((menu-str (car item-external))
434 (dolist (button (cdr item-external))
436 (cons (list (intern (TeX-bar-img-filename
440 (TeX-bar-img-filename
442 :help (aref button 0)
443 :command (aref button 1))
445 (setq menu-buttons (nreverse menu-buttons))
446 (setq menu-strings-alist-temp
447 (cons (cons menu-str (list menu-buttons))
448 menu-strings-alist-temp)))
449 ;; if another list (therefore, up to second level menu)
450 (let ((parent-str (concat (car item-external) " ")))
451 (dolist (item-internal (cdr item-external))
452 (unless (equal (car item-internal) "Special")
453 (let* ((menu-str (concat parent-str
454 (car item-internal)))
456 (dolist (button (cdr item-internal))
458 (cons (list (intern (aref button 0))
461 (TeX-bar-img-filename
463 :help (aref button 0)
464 :command (aref button 1))
466 (setq menu-buttons (nreverse menu-buttons))
467 (setq menu-strings-alist-temp
468 (cons (cons menu-str (list menu-buttons))
469 menu-strings-alist-temp)))))))))))
470 (list-strings (let* ((list-str-temp))
471 (dolist (i menu-strings-buttons-alist
472 (nreverse list-str-temp))
473 (setq list-str-temp (cons (car i)
475 (defvar LaTeX-symbols-toolbar-visible-flag nil
476 "Non-nil means that the LaTeX symbols on toolbar are visible.
478 (defconst LaTeX-symbols-toolbar-switch-contents
479 `(;; the on-off switch button
480 (latex-symbols-switch
481 :image (lambda nil (if LaTeX-symbols-toolbar-visible-flag
485 (setq LaTeX-symbols-toolbar-visible-flag
486 (not LaTeX-symbols-toolbar-visible-flag))
488 ;; help message depends on if symb-toolbar is on or off, and in
489 ;; the name of the current class of symbols
490 :help (lambda (&rest ignore)
492 (if LaTeX-symbols-toolbar-visible-flag "off " "on ")
493 "the toolbar of LaTeX symbols (current class: "
494 (nth (1- LaTeX-symbols-active-menuitem)
495 (quote ,list-strings))
497 ;; the dropdown button, that also switch on the symbols
498 ,(append '(:dropdown-group)
501 LaTeX-symbols-active-menuitem
503 :dropdown-prepend-command
504 (setq LaTeX-symbols-toolbar-visible-flag t)
505 :dropdown-help "Select a class of symbols to be displayed"))))
506 (defconst LaTeX-symbols-toolbar-contents
509 (dolist (i menu-strings-buttons-alist
510 (append (nreverse ltx-symb)
512 LaTeX-symbols-toolbar-visible-flag
513 :toolbar (bottom . top))))
514 (setq count (1+ count))
516 (cons (append (cdr i)
517 `(:insert (eq LaTeX-symbols-active-menuitem
523 ;;; tex-bar.el ends here