Add (provide ...) forms.
[org-mode.git] / contrib / oldexp / org-beamer.el
blob21227c539c5f7854ac3b982ac5977c70650bbd37
1 ;;; org-beamer.el --- Beamer-specific LaTeX export for org-mode
2 ;;
3 ;; Copyright (C) 2007-2013 Free Software Foundation, Inc.
4 ;;
5 ;; Author: Carsten Dominik <carsten.dominik AT gmail DOT com>
6 ;; Maintainer: Carsten Dominik <carsten.dominik AT gmail DOT com>
7 ;; Keywords: org, wp, tex
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; This library implement the special treatment needed by using the
27 ;; beamer class during LaTeX export.
29 ;;; Code:
31 (require 'org)
32 (require 'org-exp)
34 (defvar org-export-latex-header)
35 (defvar org-export-latex-options-plist)
36 (defvar org-export-opt-plist)
38 (defgroup org-beamer nil
39 "Options specific for using the beamer class in LaTeX export."
40 :tag "Org Beamer"
41 :group 'org-export-latex)
43 (defcustom org-beamer-use-parts nil
45 :group 'org-beamer
46 :version "24.1"
47 :type 'boolean)
49 (defcustom org-beamer-frame-level 1
50 "The level that should be interpreted as a frame.
51 The levels above this one will be translated into a sectioning structure.
52 Setting this to 2 will allow sections, 3 will allow subsections as well.
53 You can set this to 4 as well, if you at the same time set
54 `org-beamer-use-parts' to make the top levels `\part'."
55 :group 'org-beamer
56 :version "24.1"
57 :type '(choice
58 (const :tag "Frames need a BEAMER_env property" nil)
59 (integer :tag "Specific level makes a frame")))
61 (defcustom org-beamer-frame-default-options ""
62 "Default options string to use for frames, should contains the [brackets].
63 And example for this is \"[allowframebreaks]\"."
64 :group 'org-beamer
65 :version "24.1"
66 :type '(string :tag "[options]"))
68 (defcustom org-beamer-column-view-format
69 "%45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)"
70 "Default column view format that should be used to fill the template."
71 :group 'org-beamer
72 :version "24.1"
73 :type '(choice
74 (const :tag "Do not insert Beamer column view format" nil)
75 (string :tag "Beamer column view format")))
77 (defcustom org-beamer-themes
78 "\\usetheme{default}\\usecolortheme{default}"
79 "Default string to be used for extra heading stuff in beamer presentations.
80 When a beamer template is filled, this will be the default for
81 BEAMER_HEADER_EXTRA, which will be inserted just before \\begin{document}."
82 :group 'org-beamer
83 :version "24.1"
84 :type '(choice
85 (const :tag "Do not insert Beamer themes" nil)
86 (string :tag "Beamer themes")))
88 (defconst org-beamer-column-widths
89 "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.0 :ETC"
90 "The column widths that should be installed as allowed property values.")
92 (defconst org-beamer-transitions
93 "\transblindsvertical \transblindshorizontal \transboxin \transboxout \transdissolve \transduration \transglitter \transsplithorizontalin \transsplithorizontalout \transsplitverticalin \transsplitverticalout \transwipe :ETC"
94 "Transitions available for beamer.
95 These are just a completion help.")
97 (defconst org-beamer-environments-default
98 '(("frame" "f" "dummy- special handling hard coded" "dummy")
99 ("columns" "C" "\\begin{columns}%o %% %h%x" "\\end{columns}")
100 ("column" "c" "\\begin{column}%o{%h\\textwidth}%x" "\\end{column}")
101 ("block" "b" "\\begin{block}%a{%h}%x" "\\end{block}")
102 ("alertblock" "a" "\\begin{alertblock}%a{%h}%x" "\\end{alertblock}")
103 ("verse" "v" "\\begin{verse}%a %% %h%x" "\\end{verse}")
104 ("quotation" "q" "\\begin{quotation}%a %% %h%x" "\\end{quotation}")
105 ("quote" "Q" "\\begin{quote}%a %% %h%x" "\\end{quote}")
106 ("structureenv" "s" "\\begin{structureenv}%a %% %h%x" "\\end{structureenv}")
107 ("theorem" "t" "\\begin{theorem}%a%U%x" "\\end{theorem}")
108 ("definition" "d" "\\begin{definition}%a%U%x" "\\end{definition}")
109 ("example" "e" "\\begin{example}%a%U%x" "\\end{example}")
110 ("exampleblock" "E" "\\begin{exampleblock}%a{%h}%x" "\\end{exampleblock}")
111 ("proof" "p" "\\begin{proof}%a%U%x" "\\end{proof}")
112 ("beamercolorbox" "o" "\\begin{beamercolorbox}%o{%h}%x" "\\end{beamercolorbox}")
113 ("normal" "h" "%h" "") ; Emit the heading as normal text
114 ("note" "n" "\\note%o%a{%h" "}")
115 ("noteNH" "N" "\\note%o%a{" "}") ; note, ignore heading
116 ("ignoreheading" "i" "%%%% %h" ""))
117 "Environments triggered by properties in Beamer export.
118 These are the defaults - for user definitions, see
119 `org-beamer-environments-extra'.
120 \"normal\" is a special fake environment, which emit the heading as
121 normal text. It is needed when an environment should be surrounded
122 by normal text. Since beamer export converts nodes into environments,
123 you need to have a node to end the environment.
124 For example
126 ** a frame
127 some text
128 *** Blocktitle :B_block:
129 inside the block
130 *** After the block :B_normal:
131 continuing here
132 ** next frame")
134 (defcustom org-beamer-environments-extra nil
135 "Environments triggered by tags in Beamer export.
136 Each entry has 4 elements:
138 name Name of the environment
139 key Selection key for `org-beamer-select-environment'
140 open The opening template for the environment, with the following escapes
141 %a the action/overlay specification
142 %A the default action/overlay specification
143 %o the options argument of the template
144 %h the headline text
145 %H if there is headline text, that text in {} braces
146 %U if there is headline text, that text in [] brackets
147 %x the content of the BEAMER_extra property
148 close The closing string of the environment."
150 :group 'org-beamer
151 :version "24.1"
152 :type '(repeat
153 (list
154 (string :tag "Environment")
155 (string :tag "Selection key")
156 (string :tag "Begin")
157 (string :tag "End"))))
159 (defcustom org-beamer-inherited-properties nil
160 "Properties that should be inherited during beamer export."
161 :group 'org-beamer
162 :type '(repeat
163 (string :tag "Property")))
165 (defvar org-beamer-frame-level-now nil)
166 (defvar org-beamer-header-extra nil)
167 (defvar org-beamer-export-is-beamer-p nil)
168 (defvar org-beamer-inside-frame-at-level nil)
169 (defvar org-beamer-columns-open nil)
170 (defvar org-beamer-column-open nil)
172 (defun org-beamer-cleanup-column-width (width)
173 "Make sure the width is not empty, and that it has a unit."
174 (setq width (org-trim (or width "")))
175 (unless (string-match "\\S-" width) (setq width "0.5"))
176 (if (string-match "\\`[.0-9]+\\'" width)
177 (setq width (concat width "\\textwidth")))
178 width)
180 (defun org-beamer-open-column (&optional width opt)
181 (org-beamer-close-column-maybe)
182 (setq org-beamer-column-open t)
183 (setq width (org-beamer-cleanup-column-width width))
184 (insert (format "\\begin{column}%s{%s}\n" (or opt "") width)))
185 (defun org-beamer-close-column-maybe ()
186 (when org-beamer-column-open
187 (setq org-beamer-column-open nil)
188 (insert "\\end{column}\n")))
189 (defun org-beamer-open-columns-maybe (&optional opts)
190 (unless org-beamer-columns-open
191 (setq org-beamer-columns-open t)
192 (insert (format "\\begin{columns}%s\n" (or opts "")))))
193 (defun org-beamer-close-columns-maybe ()
194 (org-beamer-close-column-maybe)
195 (when org-beamer-columns-open
196 (setq org-beamer-columns-open nil)
197 (insert "\\end{columns}\n")))
199 (defun org-beamer-select-environment ()
200 "Select the environment to be used by beamer for this entry.
201 While this uses (for convenience) a tag selection interface, the result
202 of this command will be that the BEAMER_env *property* of the entry is set.
204 In addition to this, the command will also set a tag as a visual aid, but
205 the tag does not have any semantic meaning."
206 (interactive)
207 (let* ((envs (append org-beamer-environments-extra
208 org-beamer-environments-default))
209 (org-tag-alist
210 (append '((:startgroup))
211 (mapcar (lambda (e) (cons (concat "B_" (car e))
212 (string-to-char (nth 1 e))))
213 envs)
214 '((:endgroup))
215 '(("BMCOL" . ?|))))
216 (org-fast-tag-selection-single-key t))
217 (org-set-tags)
218 (let ((tags (or (ignore-errors (org-get-tags-string)) "")))
219 (cond
220 ((equal org-last-tag-selection-key ?|)
221 (if (string-match ":BMCOL:" tags)
222 (org-set-property "BEAMER_col" (read-string "Column width: "))
223 (org-delete-property "BEAMER_col")))
224 ((string-match (concat ":B_\\("
225 (mapconcat 'car envs "\\|")
226 "\\):")
227 tags)
228 (org-entry-put nil "BEAMER_env" (match-string 1 tags)))
229 (t (org-entry-delete nil "BEAMER_env"))))))
231 (defun org-beamer-sectioning (level text)
232 "Return the sectioning entry for the current headline.
233 LEVEL is the reduced level of the headline.
234 TEXT is the text of the headline, everything except the leading stars.
235 The return value is a cons cell. The car is the headline text, usually
236 just TEXT, but possibly modified if options have been extracted from the
237 text. The cdr is the sectioning entry, similar to what is given
238 in org-export-latex-classes."
239 (let* ((frame-level (or org-beamer-frame-level-now org-beamer-frame-level))
240 (default
241 (if org-beamer-use-parts
242 '((1 . ("\\part{%s}" . "\\part*{%s}"))
243 (2 . ("\\section{%s}" . "\\section*{%s}"))
244 (3 . ("\\subsection{%s}" . "\\subsection*{%s}")))
245 '((1 . ("\\section{%s}" . "\\section*{%s}"))
246 (2 . ("\\subsection{%s}" . "\\subsection*{%s}")))))
247 (envs (append org-beamer-environments-extra
248 org-beamer-environments-default))
249 (props (org-get-text-property-any 0 'org-props text))
250 (in "") (out "") org-beamer-option org-beamer-action org-beamer-defaction org-beamer-environment org-beamer-extra
251 columns-option column-option
252 env have-text ass tmp)
253 (if (= frame-level 0) (setq frame-level nil))
254 (when (and org-beamer-inside-frame-at-level
255 (<= level org-beamer-inside-frame-at-level))
256 (setq org-beamer-inside-frame-at-level nil))
257 (when (setq tmp (org-beamer-assoc-not-empty "BEAMER_col" props))
258 (if (and (string-match "\\`[0-9.]+\\'" tmp)
259 (or (= (string-to-number tmp) 1.0)
260 (= (string-to-number tmp) 0.0)))
261 ;; column width 1 means close columns, go back to full width
262 (org-beamer-close-columns-maybe)
263 (when (setq ass (assoc "BEAMER_envargs" props))
264 (let (case-fold-search)
265 (while (string-match "C\\(\\[[^][]*\\]\\|<[^<>]*>\\)" (cdr ass))
266 (setq columns-option (match-string 1 (cdr ass)))
267 (setcdr ass (replace-match "" t t (cdr ass))))
268 (while (string-match "c\\(\\[[^][]*\\]\\|<[^<>]*>\\)" (cdr ass))
269 (setq column-option (match-string 1 (cdr ass)))
270 (setcdr ass (replace-match "" t t (cdr ass))))))
271 (org-beamer-open-columns-maybe columns-option)
272 (org-beamer-open-column tmp column-option)))
273 (cond
274 ((or (equal (cdr (assoc "BEAMER_env" props)) "frame")
275 (and frame-level (= level frame-level)))
276 ;; A frame
277 (org-beamer-get-special props)
279 (setq in (org-fill-template
280 "\\begin{frame}%a%A%o%T%S%x"
281 (list (cons "a" (or org-beamer-action ""))
282 (cons "A" (or org-beamer-defaction ""))
283 (cons "o" (or org-beamer-option org-beamer-frame-default-options ""))
284 (cons "x" (if org-beamer-extra (concat "\n" org-beamer-extra) ""))
285 (cons "h" "%s")
286 (cons "T" (if (string-match "\\S-" text)
287 "\n\\frametitle{%s}" ""))
288 (cons "S" (if (string-match "\\\\\\\\" text)
289 "\n\\framesubtitle{%s}" ""))))
290 out (copy-sequence "\\end{frame}"))
291 (org-add-props out
292 '(org-insert-hook org-beamer-close-columns-maybe))
293 (setq org-beamer-inside-frame-at-level level)
294 (cons text (list in out in out)))
295 ((and (setq env (cdr (assoc "BEAMER_env" props)))
296 (setq ass (assoc env envs)))
297 ;; A beamer environment selected by the BEAMER_env property
298 (if (string-match "[ \t]+:[ \t]*$" text)
299 (setq text (replace-match "" t t text)))
300 (if (member env '("note" "noteNH"))
301 ;; There should be no labels in a note, so we remove the targets
302 ;; FIXME???
303 (remove-text-properties 0 (length text) '(target nil) text))
304 (org-beamer-get-special props)
305 (setq text (org-trim text))
306 (setq have-text (string-match "\\S-" text))
307 (setq in (org-fill-template
308 (nth 2 ass)
309 (list (cons "a" (or org-beamer-action ""))
310 (cons "A" (or org-beamer-defaction ""))
311 (cons "o" (or org-beamer-option ""))
312 (cons "x" (if org-beamer-extra (concat "\n" org-beamer-extra) ""))
313 (cons "h" "%s")
314 (cons "H" (if have-text (concat "{" text "}") ""))
315 (cons "U" (if have-text (concat "[" text "]") ""))))
316 out (nth 3 ass))
317 (cond
318 ((equal out "\\end{columns}")
319 (setq org-beamer-columns-open t)
320 (setq out (org-add-props (copy-sequence out)
321 '(org-insert-hook
322 (lambda ()
323 (org-beamer-close-column-maybe)
324 (setq org-beamer-columns-open nil))))))
325 ((equal out "\\end{column}")
326 (org-beamer-open-columns-maybe)))
327 (cons text (list in out in out)))
328 ((and (not org-beamer-inside-frame-at-level)
329 (or (not frame-level)
330 (< level frame-level))
331 (assoc level default))
332 ;; Normal sectioning
333 (cons text (cdr (assoc level default))))
334 (t nil))))
336 (defvar org-beamer-extra)
337 (defvar org-beamer-option)
338 (defvar org-beamer-action)
339 (defvar org-beamer-defaction)
340 (defvar org-beamer-environment)
341 (defun org-beamer-get-special (props)
342 "Extract an option, action, and default action string from text.
343 The variables org-beamer-option, org-beamer-action, org-beamer-defaction,
344 org-beamer-extra are all scoped into this function dynamically."
345 (let (tmp)
346 (setq org-beamer-environment (org-beamer-assoc-not-empty "BEAMER_env" props))
347 (setq org-beamer-extra (org-beamer-assoc-not-empty "BEAMER_extra" props))
348 (when org-beamer-extra
349 (setq org-beamer-extra (replace-regexp-in-string "\\\\n" "\n" org-beamer-extra)))
350 (setq tmp (org-beamer-assoc-not-empty "BEAMER_envargs" props))
351 (when tmp
352 (setq tmp (copy-sequence tmp))
353 (if (string-match "\\[<[^][<>]*>\\]" tmp)
354 (setq org-beamer-defaction (match-string 0 tmp)
355 tmp (replace-match "" t t tmp)))
356 (if (string-match "\\[[^][]*\\]" tmp)
357 (setq org-beamer-option (match-string 0 tmp)
358 tmp (replace-match "" t t tmp)))
359 (if (string-match "<[^<>]*>" tmp)
360 (setq org-beamer-action (match-string 0 tmp)
361 tmp (replace-match "" t t tmp))))))
363 (defun org-beamer-assoc-not-empty (elt list)
364 (let ((tmp (cdr (assoc elt list))))
365 (and tmp (string-match "\\S-" tmp) tmp)))
368 (defvar org-beamer-mode-map (make-sparse-keymap)
369 "The keymap for `org-beamer-mode'.")
370 (define-key org-beamer-mode-map "\C-c\C-b" 'org-beamer-select-environment)
372 (define-minor-mode org-beamer-mode
373 "Special support for editing Org-mode files made to export to beamer."
374 nil " Bm" nil)
375 (when (fboundp 'font-lock-add-keywords)
376 (font-lock-add-keywords
377 'org-mode
378 '((":\\(B_[a-z]+\\|BMCOL\\):" 1 'org-beamer-tag prepend))
379 'prepent))
381 (defun org-beamer-place-default-actions-for-lists ()
382 "Find default overlay specifications in items, and move them.
383 The need to be after the begin statement of the environment."
384 (when org-beamer-export-is-beamer-p
385 (let (dovl)
386 (goto-char (point-min))
387 (while (re-search-forward
388 "^[ \t]*\\\\begin{\\(itemize\\|enumerate\\|description\\)}[ \t\n]*\\\\item\\>\\( ?\\(<[^<>\n]*>\\|\\[[^][\n*]\\]\\)\\)?[ \t]*\\S-" nil t)
389 (if (setq dovl (cdr (assoc "BEAMER_dovl"
390 (get-text-property (match-end 0)
391 'org-props))))
392 (save-excursion
393 (goto-char (1+ (match-end 1)))
394 (insert dovl)))))))
396 (defun org-beamer-amend-header ()
397 "Add `org-beamer-header-extra' to the LaTeX header.
398 If the file contains the string BEAMER-HEADER-EXTRA-HERE on a line
399 by itself, it will be replaced with `org-beamer-header-extra'. If not,
400 the value will be inserted right after the documentclass statement."
401 (when (and org-beamer-export-is-beamer-p
402 org-beamer-header-extra)
403 (goto-char (point-min))
404 (cond
405 ((re-search-forward
406 "^[ \t]*\\[?BEAMER-HEADER-EXTRA\\(-HERE\\)?\\]?[ \t]*$" nil t)
407 (replace-match org-beamer-header-extra t t)
408 (or (bolp) (insert "\n")))
409 ((re-search-forward "^[ \t]*\\\\begin{document}" nil t)
410 (beginning-of-line 1)
411 (insert org-beamer-header-extra)
412 (or (bolp) (insert "\n"))))))
414 (defcustom org-beamer-fragile-re "\\\\\\(verb\\|lstinline\\)\\|^[ \t]*\\\\begin{\\(verbatim\\|lstlisting\\|minted\\)}"
415 "If this regexp matches in a frame, the frame is marked as fragile."
416 :group 'org-beamer
417 :version "24.1"
418 :type 'regexp)
420 (defface org-beamer-tag '((t (:box (:line-width 1 :color grey40))))
421 "The special face for beamer tags."
422 :group 'org-beamer)
425 ;; Functions to initialize and post-process
426 ;; These functions will be hooked into various places in the export process
428 (defun org-beamer-initialize-open-trackers ()
429 "Reset variables that track if certain environments are open during export."
430 (setq org-beamer-columns-open nil)
431 (setq org-beamer-column-open nil)
432 (setq org-beamer-inside-frame-at-level nil)
433 (setq org-beamer-export-is-beamer-p nil))
435 (defun org-beamer-after-initial-vars ()
436 "Find special settings for beamer and store them.
437 The effect is that these values will be accessible during export."
438 ;; First verify that we are exporting using the beamer class
439 (setq org-beamer-export-is-beamer-p
440 (string-match "\\\\documentclass\\(\\[[^][]*?\\]\\)?{beamer}"
441 org-export-latex-header))
442 (when org-beamer-export-is-beamer-p
443 ;; Find the frame level
444 (setq org-beamer-frame-level-now
445 (or (and (org-region-active-p)
446 (save-excursion
447 (goto-char (region-beginning))
448 (and (looking-at org-complex-heading-regexp)
449 (org-entry-get nil "BEAMER_FRAME_LEVEL" 'selective))))
450 (save-excursion
451 (save-restriction
452 (widen)
453 (goto-char (point-min))
454 (and (re-search-forward
455 "^#\\+BEAMER_FRAME_LEVEL:[ \t]*\\(.*?\\)[ \t]*$" nil t)
456 (match-string 1))))
457 (plist-get org-export-latex-options-plist :beamer-frame-level)
458 org-beamer-frame-level))
459 ;; Normalize the value so that the functions can trust the value
460 (cond
461 ((not org-beamer-frame-level-now)
462 (setq org-beamer-frame-level-now nil))
463 ((stringp org-beamer-frame-level-now)
464 (setq org-beamer-frame-level-now
465 (string-to-number org-beamer-frame-level-now))))
466 ;; Find the header additions, most likely theme commands
467 (setq org-beamer-header-extra
468 (or (and (org-region-active-p)
469 (save-excursion
470 (goto-char (region-beginning))
471 (and (looking-at org-complex-heading-regexp)
472 (org-entry-get nil "BEAMER_HEADER_EXTRA"
473 'selective))))
474 (save-excursion
475 (save-restriction
476 (widen)
477 (let ((txt ""))
478 (goto-char (point-min))
479 (while (re-search-forward
480 "^#\\+BEAMER_HEADER_EXTRA:[ \t]*\\(.*?\\)[ \t]*$"
481 nil t)
482 (setq txt (concat txt "\n" (match-string 1))))
483 (if (> (length txt) 0) (substring txt 1)))))
484 (plist-get org-export-latex-options-plist
485 :beamer-header-extra)))
486 (let ((inhibit-read-only t)
487 (case-fold-search nil)
488 props)
489 (org-unmodified
490 (remove-text-properties (point-min) (point-max) '(org-props nil))
491 (org-map-entries
492 '(progn
493 (setq props (org-entry-properties nil 'standard))
494 (if (and (not (assoc "BEAMER_env" props))
495 (looking-at ".*?:B_\\(note\\(NH\\)?\\):"))
496 (push (cons "BEAMER_env" (match-string 1)) props))
497 (when (org-bound-and-true-p org-beamer-inherited-properties)
498 (mapc (lambda (p)
499 (unless (assoc p props)
500 (let ((v (org-entry-get nil p 'inherit)))
501 (and v (push (cons p v) props)))))
502 org-beamer-inherited-properties))
503 (put-text-property (point-at-bol) (point-at-eol) 'org-props props)))
504 (setq org-export-latex-options-plist
505 (plist-put org-export-latex-options-plist :tags nil))))))
507 (defun org-beamer-auto-fragile-frames ()
508 "Mark any frames containing verbatim environments as fragile.
509 This function will run in the final LaTeX document."
510 (when org-beamer-export-is-beamer-p
511 (let (opts)
512 (goto-char (point-min))
513 ;; Find something that might be fragile
514 (while (re-search-forward org-beamer-fragile-re nil t)
515 (save-excursion
516 ;; Are we inside a frame here?
517 (when (and (re-search-backward "^[ \t]*\\\\\\(begin\\|end\\){frame}\\(<[^>]*>\\)?"
518 nil t)
519 (equal (match-string 1) "begin"))
520 ;; yes, inside a frame, make sure "fragile" is one of the options
521 (goto-char (match-end 0))
522 (if (not (looking-at "\\[.*?\\]"))
523 (insert "[fragile]")
524 (setq opts (substring (match-string 0) 1 -1))
525 (delete-region (match-beginning 0) (match-end 0))
526 (setq opts (org-split-string opts ","))
527 (add-to-list 'opts "fragile")
528 (insert "[" (mapconcat 'identity opts ",") "]"))))))))
530 (defcustom org-beamer-outline-frame-title "Outline"
531 "Default title of a frame containing an outline."
532 :group 'org-beamer
533 :version "24.1"
534 :type '(string :tag "Outline frame title")
537 (defcustom org-beamer-outline-frame-options nil
538 "Outline frame options appended after \\begin{frame}.
539 You might want to put e.g. [allowframebreaks=0.9] here. Remember to
540 include square brackets."
541 :group 'org-beamer
542 :version "24.1"
543 :type '(string :tag "Outline frame options")
546 (defun org-beamer-fix-toc ()
547 "Fix the table of contents by removing the vspace line."
548 (when org-beamer-export-is-beamer-p
549 (save-excursion
550 (goto-char (point-min))
551 (when (re-search-forward "\\(\\\\setcounter{tocdepth.*\n\\\\tableofcontents.*\n\\)\\(\\\\vspace\\*.*\\)"
552 nil t)
553 (replace-match
554 (concat "\\\\begin{frame}" org-beamer-outline-frame-options
555 "\n\\\\frametitle{"
556 org-beamer-outline-frame-title
557 "}\n\\1\\\\end{frame}")
558 t nil)))))
560 (defun org-beamer-property-changed (property value)
561 "Track the BEAMER_env property with tags."
562 (cond
563 ((equal property "BEAMER_env")
564 (save-excursion
565 (org-back-to-heading t)
566 (let ((tags (org-get-tags)))
567 (setq tags (delq nil (mapcar (lambda (x)
568 (if (string-match "^B_" x) nil x))
569 tags)))
570 (org-set-tags-to tags))
571 (when (and value (stringp value) (string-match "\\S-" value))
572 (org-toggle-tag (concat "B_" value) 'on))))
573 ((equal property "BEAMER_col")
574 (org-toggle-tag "BMCOL" (if (and value (string-match "\\S-" value))
575 'on 'off)))))
577 (defun org-beamer-select-beamer-code ()
578 "Take code marked for BEAMER and turn it into marked for LaTeX."
579 (when org-beamer-export-is-beamer-p
580 (goto-char (point-min))
581 (while (re-search-forward
582 "^\\([ \]*#\\+\\(begin_\\|end_\\)?\\)\\(beamer\\)\\>" nil t)
583 (replace-match "\\1latex"))))
585 ;; OK, hook all these functions into appropriate places
586 (add-hook 'org-export-first-hook
587 'org-beamer-initialize-open-trackers)
588 (add-hook 'org-property-changed-functions
589 'org-beamer-property-changed)
590 (add-hook 'org-export-latex-after-initial-vars-hook
591 'org-beamer-after-initial-vars)
592 (add-hook 'org-export-latex-final-hook
593 'org-beamer-place-default-actions-for-lists)
594 (add-hook 'org-export-latex-final-hook
595 'org-beamer-auto-fragile-frames)
596 (add-hook 'org-export-latex-final-hook
597 'org-beamer-fix-toc)
598 (add-hook 'org-export-latex-final-hook
599 'org-beamer-amend-header)
600 (add-hook 'org-export-preprocess-before-selecting-backend-code-hook
601 'org-beamer-select-beamer-code)
603 (defun org-insert-beamer-options-template (&optional kind)
604 "Insert a settings template, to make sure users do this right."
605 (interactive (progn
606 (message "Current [s]ubtree or [g]lobal?")
607 (if (equal (read-char-exclusive) ?g)
608 (list 'global)
609 (list 'subtree))))
610 (if (eq kind 'subtree)
611 (progn
612 (org-back-to-heading t)
613 (org-reveal)
614 (org-entry-put nil "LaTeX_CLASS" "beamer")
615 (org-entry-put nil "LaTeX_CLASS_OPTIONS" "[presentation]")
616 (org-entry-put nil "EXPORT_FILE_NAME" "presentation.pdf")
617 (org-entry-put nil "BEAMER_FRAME_LEVEL" (number-to-string
618 org-beamer-frame-level))
619 (when org-beamer-themes
620 (org-entry-put nil "BEAMER_HEADER_EXTRA" org-beamer-themes))
621 (when org-beamer-column-view-format
622 (org-entry-put nil "COLUMNS" org-beamer-column-view-format))
623 (org-entry-put nil "BEAMER_col_ALL" "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC"))
624 (insert "#+LaTeX_CLASS: beamer\n")
625 (insert "#+LaTeX_CLASS_OPTIONS: [presentation]\n")
626 (insert (format "#+BEAMER_FRAME_LEVEL: %d\n" org-beamer-frame-level) "\n")
627 (when org-beamer-themes
628 (insert "#+BEAMER_HEADER_EXTRA: " org-beamer-themes "\n"))
629 (when org-beamer-column-view-format
630 (insert "#+COLUMNS: " org-beamer-column-view-format "\n"))
631 (insert "#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC\n")))
634 (defun org-beamer-allowed-property-values (property)
635 "Supply allowed values for BEAMER properties."
636 (cond
637 ((and (equal property "BEAMER_env")
638 (not (org-entry-get nil (concat property "_ALL") 'inherit)))
639 ;; If no allowed values for BEAMER_env have been defined,
640 ;; supply all defined environments
641 (mapcar 'car (append org-beamer-environments-extra
642 org-beamer-environments-default)))
643 ((and (equal property "BEAMER_col")
644 (not (org-entry-get nil (concat property "_ALL") 'inherit)))
645 ;; If no allowed values for BEAMER_col have been defined,
646 ;; supply some
647 '("0.1" "0.2" "0.3" "0.4" "0.5" "0.6" "0.7" "0.8" "0.9" "" ":ETC"))
648 (t nil)))
650 (add-hook 'org-property-allowed-value-functions
651 'org-beamer-allowed-property-values)
653 (provide 'org-beamer)
655 ;;; org-beamer.el ends here