1 ;;; beamer.el --- AUCTeX style for the latex-beamer class
3 ;; Copyright (C) 2003, 2004, 2005,2008 Free Software Foundation
5 ;; Author: Thomas Baumann <thomas.baumann@ch.tum.de>
9 ;; This file is part of AUCTeX.
11 ;; AUCTeX is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; AUCTeX is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with AUCTeX; see the file COPYING. If not, write to the Free
23 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 ;; This file adds support for the latex-beamer class.
32 (defun LaTeX-beamer-after-insert-env (env start end)
33 "Do beamer-specific stuff after the insertion of an environment."
34 ;; Add `fragile' as an optional argument to the frame environment if
35 ;; a verbatim environment is inserted.
36 (when (and (TeX-member env (LaTeX-verbatim-environments) 'string-equal)
39 (string-equal (LaTeX-current-environment) "frame")))
41 (when (re-search-backward "\\\\begin[ \t]*{frame}" nil t)
42 (let ((end-of-begin (match-end 0)))
43 (goto-char end-of-begin)
44 (while (forward-comment 1))
45 (if (eq (char-after) (string-to-char LaTeX-optop))
49 (unless (looking-at (concat "[ \t]*" LaTeX-optcl))
51 (goto-char end-of-begin)
52 (insert "[fragile]")))))))
57 (add-hook 'LaTeX-after-insert-env-hooks 'LaTeX-beamer-after-insert-env nil t)
59 (unless LaTeX-beamer-section-labels-flag
60 (make-local-variable 'LaTeX-section-hook)
61 (setq LaTeX-section-hook
62 '(LaTeX-section-heading
64 LaTeX-section-section)))
67 (append '(("itemize" . LaTeX-item-beamer)
68 ("enumerate" . LaTeX-item-beamer))
71 (LaTeX-paragraph-commands-add-locally "frametitle")
75 '("alt" TeX-arg-beamer-overlay-spec 2)
77 '("beamergotobutton" 1)
78 '("beamerreturnbutton" 1)
79 '("beamerskipbutton" 1)
80 '("frame" TeX-arg-beamer-frametitle)
82 '("hyperlink" TeX-arg-beamer-overlay-spec 2)
83 '("hyperlinkslideprev" TeX-arg-beamer-overlay-spec 1)
84 '("hyperlinkslidenext" TeX-arg-beamer-overlay-spec 1)
85 '("hyperlinkframestart" TeX-arg-beamer-overlay-spec 1)
86 '("hyperlinkframeend" TeX-arg-beamer-overlay-spec 1)
87 '("hyperlinkframestartnext" TeX-arg-beamer-overlay-spec 1)
88 '("hyperlinkframeendprev" TeX-arg-beamer-overlay-spec 1)
89 '("hyperlinkpresentationstart" TeX-arg-beamer-overlay-spec 1)
90 '("hyperlinkpresentationend" TeX-arg-beamer-overlay-spec 1)
91 '("hyperlinkappendixstart" TeX-arg-beamer-overlay-spec 1)
92 '("hyperlinkappendixend" TeX-arg-beamer-overlay-spec 1)
93 '("hyperlinkdocumentstart" TeX-arg-beamer-overlay-spec 1)
94 '("hyperlinkdocumentend" TeX-arg-beamer-overlay-spec 1)
95 '("hypertarget" TeX-arg-beamer-overlay-spec 2)
97 '("invisible" TeX-arg-beamer-overlay-spec 1)
98 '("label" TeX-arg-beamer-overlay-spec 1)
100 '("note" TeX-arg-beamer-note 1)
101 '("only" TeX-arg-beamer-overlay-spec 1)
102 '("onslide" TeX-arg-beamer-overlay-spec)
105 '("structure" TeX-arg-beamer-overlay-spec 1)
106 '("temporal" TeX-arg-beamer-overlay-spec 3)
109 '("uncover" TeX-arg-beamer-overlay-spec 1)
110 '("usetheme" LaTeX-arg-beamer-theme)
111 '("useinnertheme" LaTeX-arg-beamer-inner-theme)
112 '("useoutertheme" LaTeX-arg-beamer-outer-theme)
113 '("usecolortheme" LaTeX-arg-beamer-color-theme)
114 '("usefonttheme" LaTeX-arg-beamer-font-theme)
115 '("usetheme" LaTeX-arg-beamer-theme)
116 '("visible" TeX-arg-beamer-overlay-spec 1))
118 (LaTeX-add-environments
121 '("beamerboxesrounded" 1)
122 '("block" (lambda (env &rest ignore)
123 (LaTeX-insert-environment
124 env (format "{%s}" (read-string "Title: ")))))
127 "columnsonlytextwidth"
129 '("frame" (lambda (env &rest ignore)
130 (let ((title (read-string "(Optional) Title: ")))
131 (LaTeX-insert-environment env)
132 (unless (zerop (length title))
134 (LaTeX-find-matching-begin)
137 (insert (format "\\frametitle{%s}" title))
138 ;; This works because \frametitle is a
139 ;; paragraph command.
141 (LaTeX-fill-paragraph))))))
142 '("onlyenv" (lambda (env &rest ignore)
143 (LaTeX-insert-environment
145 (let ((overlay (read-string "(Optional) Overlay: ")))
146 (unless (zerop (length overlay))
147 (format "<%s>" overlay))))))
148 '("overlayarea" "Area width" "Area height")
149 '("overprint" (lambda (env &rest ignore)
150 (LaTeX-insert-environment
152 (let ((width (read-string "(Optional) Area width: ")))
153 (unless (zerop (length width))
154 (format "[%s]" width))))))
157 (make-local-variable 'LaTeX-indent-environment-list)
158 (add-to-list 'LaTeX-indent-environment-list
159 '("semiverbatim" current-indentation))
160 (make-local-variable 'LaTeX-verbatim-regexp)
161 (setq LaTeX-verbatim-regexp (concat LaTeX-verbatim-regexp "\\|semiverbatim"))
162 (add-to-list 'LaTeX-verbatim-environments-local "semiverbatim")
165 (when (and (featurep 'font-latex)
166 (eq TeX-install-font-lock 'font-latex-setup))
167 (font-latex-add-keywords '(("frametitle" "<[{")) 'slide-title)
168 ;; For syntactic fontification, e.g. verbatim constructs.
169 (font-latex-set-syntactic-keywords)
170 ;; Tell font-lock about the update.
171 (setq font-lock-set-defaults nil)
172 (font-lock-set-defaults))))
174 (defun TeX-arg-beamer-overlay-spec (optional &optional prompt)
175 "Prompt for overlay specification."
176 (let ((overlay (read-string "(Optional) Overlay: ")))
177 (unless (zerop (length overlay))
178 (insert "<" overlay ">"))
179 (indent-according-to-mode)))
181 (defun TeX-arg-beamer-frametitle (optional &optional prompt)
182 "Prompt for the frametitle."
183 (let ((title (read-string "Title: ")))
184 (if (not (zerop (length title)))
185 (insert TeX-grop TeX-esc "frametitle" TeX-grop
186 title TeX-grcl TeX-grcl)
187 (insert TeX-grop TeX-grcl))))
189 (defun LaTeX-item-beamer ()
190 "Insert a new item with an optional overlay argument. You
191 can turn off the prompt for the overlay argument by setting
192 `LaTeX-beamer-item-overlay-flag' to nil. Calling the function
193 with a prefix argument prompts for the overlay specification
195 (if (listp current-prefix-arg)
196 (setq current-prefix-arg (car current-prefix-arg))
198 (TeX-insert-macro "item")
199 (delete-horizontal-space)
200 (if (or current-prefix-arg LaTeX-beamer-item-overlay-flag)
201 (TeX-arg-beamer-overlay-spec 0))
203 (indent-according-to-mode))
205 (defun TeX-arg-beamer-note (optional &optional prompt)
206 "Prompt for overlay specification and optional argument."
207 (let ((overlay (read-string "(Optional) Overlay: "))
208 (options (read-string "(Optional) Options: ")))
209 (unless (zerop (length overlay))
210 (insert "<" overlay ">"))
211 (unless (zerop (length options))
212 (insert "[" options "]"))
213 (indent-according-to-mode)))
215 (defun LaTeX-beamer-search-themes (&optional regexp extensions length)
216 "Search for beamer themes matching REGEXP with EXTENSIONS.
217 The function removes the first LENGTH characters and the
218 extension of the file and returns a list of strings. LENGTH may
219 also be a string. Then the length of the string is used."
220 (let* ((match (or regexp "^beamertheme[A-Z]"))
221 (exts (or extensions '("tex" "sty")))
222 (chars (cond ((integerp length)
225 (string-width length))
226 ;; Try some DWIM magic...
228 (string-match "beamer[A-Za-z0-9]*theme" match))
229 (- (match-end 0) (match-beginning 0)))
230 (t (error "Invalid length: `%s'" length)))))
231 ;; (message "match=`%s' chars=`%s'" match chars)
232 (TeX-delete-duplicate-strings
236 (let ((case-fold-search nil))
237 (and (numberp (string-match match file))
238 (substring file chars))))
239 (TeX-search-files nil exts t t))))))
241 (defun LaTeX-arg-beamer-theme (&rest ignore)
242 "Prompt for beamer theme with completion."
245 (TeX-argument-prompt nil nil "Theme")
247 (cond ((eq LaTeX-beamer-themes 'local)
248 (set (make-local-variable 'LaTeX-beamer-themes)
249 (LaTeX-beamer-search-themes)))
250 ((functionp LaTeX-beamer-themes)
251 (funcall LaTeX-beamer-themes))
252 ((listp LaTeX-beamer-themes)
255 "`LaTeX-beamer-themes' should be a list: `%s'"
256 LaTeX-beamer-themes))))
260 (defun LaTeX-arg-beamer-inner-theme (&rest ignore)
261 "Prompt for beamer inner theme with completion."
264 (TeX-argument-prompt nil nil "Theme")
266 (cond ((eq LaTeX-beamer-inner-themes 'local)
267 (set (make-local-variable 'LaTeX-beamer-inner-themes)
268 (LaTeX-beamer-search-themes "^beamerinnertheme")))
269 ((functionp LaTeX-beamer-inner-themes)
270 (funcall LaTeX-beamer-inner-themes))
271 ((listp LaTeX-beamer-inner-themes)
272 LaTeX-beamer-inner-themes)
274 "`LaTeX-beamer-inner-themes' should be a list: `%s'"
275 LaTeX-beamer-inner-themes))))
279 (defun LaTeX-arg-beamer-outer-theme (&rest ignore)
280 "Prompt for beamer outer theme with completion."
283 (TeX-argument-prompt nil nil "Theme")
285 (cond ((eq LaTeX-beamer-outer-themes 'local)
286 (set (make-local-variable 'LaTeX-beamer-outer-themes)
287 (LaTeX-beamer-search-themes "^beameroutertheme")))
288 ((functionp LaTeX-beamer-outer-themes)
289 (funcall LaTeX-beamer-outer-themes))
290 ((listp LaTeX-beamer-outer-themes)
291 LaTeX-beamer-outer-themes)
293 "`LaTeX-beamer-outer-themes' should be a list: `%s'"
294 LaTeX-beamer-outer-themes))))
298 (defun LaTeX-arg-beamer-color-theme (&rest ignore)
299 "Prompt for beamer color theme with completion."
302 (TeX-argument-prompt nil nil "Theme")
304 (cond ((eq LaTeX-beamer-color-themes 'local)
305 (set (make-local-variable 'LaTeX-beamer-color-themes)
306 (LaTeX-beamer-search-themes "^beamercolortheme")))
307 ((functionp LaTeX-beamer-color-themes)
308 (funcall LaTeX-beamer-color-themes))
309 ((listp LaTeX-beamer-color-themes)
310 LaTeX-beamer-color-themes)
312 "`LaTeX-beamer-color-themes' should be a list: `%s'"
313 LaTeX-beamer-color-themes))))
317 (defun LaTeX-arg-beamer-font-theme (&rest ignore)
318 "Prompt for beamer font theme with completion."
321 (TeX-argument-prompt nil nil "Theme")
323 (cond ((eq LaTeX-beamer-font-themes 'local)
324 (set (make-local-variable 'LaTeX-beamer-font-themes)
325 (LaTeX-beamer-search-themes "^beamerfonttheme")))
326 ((functionp LaTeX-beamer-font-themes)
327 (funcall LaTeX-beamer-font-themes))
328 ((listp LaTeX-beamer-font-themes)
329 LaTeX-beamer-font-themes)
331 "`LaTeX-beamer-font-themes' should be a list: `%s'"
332 LaTeX-beamer-font-themes))))
336 ;;; beamer.el ends here