Add :version to org-exp-blocks.el option.
[org-mode/org-kjn.git] / lisp / org-beamer.el
blob041a9154095260c440683d4cfe43cefab0c5b83e
1 ;;; org-beamer.el --- Beamer-specific LaTeX export for org-mode
2 ;;
3 ;; Copyright (C) 2007-2012 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 ("proof" "p" "\\begin{proof}%a%U%x" "\\end{proof}")
111 ("beamercolorbox" "o" "\\begin{beamercolorbox}%o{%h}%x" "\\end{beamercolorbox}")
112 ("normal" "h" "%h" "") ; Emit the heading as normal text
113 ("note" "n" "\\note%o%a{%h" "}")
114 ("noteNH" "N" "\\note%o%a{" "}") ; note, ignore heading
115 ("ignoreheading" "i" "%%%% %h" ""))
116 "Environments triggered by properties in Beamer export.
117 These are the defaults - for user definitions, see
118 `org-beamer-environments-extra'.
119 \"normal\" is a special fake environment, which emit the heading as
120 normal text. It is needed when an environment should be surrounded
121 by normal text. Since beamer export converts nodes into environments,
122 you need to have a node to end the environment.
123 For example
125 ** a frame
126 some text
127 *** Blocktitle :B_block:
128 inside the block
129 *** After the block :B_normal:
130 continuing here
131 ** next frame")
133 (defcustom org-beamer-environments-extra nil
134 "Environments triggered by tags in Beamer export.
135 Each entry has 4 elements:
137 name Name of the environment
138 key Selection key for `org-beamer-select-environment'
139 open The opening template for the environment, with the following escapes
140 %a the action/overlay specification
141 %A the default action/overlay specification
142 %o the options argument of the template
143 %h the headline text
144 %H if there is headline text, that text in {} braces
145 %U if there is headline text, that text in [] brackets
146 %x the content of the BEAMER_extra property
147 close The closing string of the environment."
149 :group 'org-beamer
150 :version "24.1"
151 :type '(repeat
152 (list
153 (string :tag "Environment")
154 (string :tag "Selection key")
155 (string :tag "Begin")
156 (string :tag "End"))))
158 (defvar org-beamer-frame-level-now nil)
159 (defvar org-beamer-header-extra nil)
160 (defvar org-beamer-export-is-beamer-p nil)
161 (defvar org-beamer-inside-frame-at-level nil)
162 (defvar org-beamer-columns-open nil)
163 (defvar org-beamer-column-open nil)
165 (defun org-beamer-cleanup-column-width (width)
166 "Make sure the width is not empty, and that it has a unit."
167 (setq width (org-trim (or width "")))
168 (unless (string-match "\\S-" width) (setq width "0.5"))
169 (if (string-match "\\`[.0-9]+\\'" width)
170 (setq width (concat width "\\textwidth")))
171 width)
173 (defun org-beamer-open-column (&optional width opt)
174 (org-beamer-close-column-maybe)
175 (setq org-beamer-column-open t)
176 (setq width (org-beamer-cleanup-column-width width))
177 (insert (format "\\begin{column}%s{%s}\n" (or opt "") width)))
178 (defun org-beamer-close-column-maybe ()
179 (when org-beamer-column-open
180 (setq org-beamer-column-open nil)
181 (insert "\\end{column}\n")))
182 (defun org-beamer-open-columns-maybe (&optional opts)
183 (unless org-beamer-columns-open
184 (setq org-beamer-columns-open t)
185 (insert (format "\\begin{columns}%s\n" (or opts "")))))
186 (defun org-beamer-close-columns-maybe ()
187 (org-beamer-close-column-maybe)
188 (when org-beamer-columns-open
189 (setq org-beamer-columns-open nil)
190 (insert "\\end{columns}\n")))
192 (defun org-beamer-select-environment ()
193 "Select the environment to be used by beamer for this entry.
194 While this uses (for convenience) a tag selection interface, the result
195 of this command will be that the BEAMER_env *property* of the entry is set.
197 In addition to this, the command will also set a tag as a visual aid, but
198 the tag does not have any semantic meaning."
199 (interactive)
200 (let* ((envs (append org-beamer-environments-extra
201 org-beamer-environments-default))
202 (org-tag-alist
203 (append '((:startgroup))
204 (mapcar (lambda (e) (cons (concat "B_" (car e))
205 (string-to-char (nth 1 e))))
206 envs)
207 '((:endgroup))
208 '(("BMCOL" . ?|))))
209 (org-fast-tag-selection-single-key t))
210 (org-set-tags)
211 (let ((tags (or (ignore-errors (org-get-tags-string)) "")))
212 (cond
213 ((equal org-last-tag-selection-key ?|)
214 (if (string-match ":BMCOL:" tags)
215 (org-set-property "BEAMER_col" (read-string "Column width: "))
216 (org-delete-property "BEAMER_col")))
217 ((string-match (concat ":B_\\("
218 (mapconcat 'car envs "\\|")
219 "\\):")
220 tags)
221 (org-entry-put nil "BEAMER_env" (match-string 1 tags)))
222 (t (org-entry-delete nil "BEAMER_env"))))))
225 (defun org-beamer-sectioning (level text)
226 "Return the sectioning entry for the current headline.
227 LEVEL is the reduced level of the headline.
228 TEXT is the text of the headline, everything except the leading stars.
229 The return value is a cons cell. The car is the headline text, usually
230 just TEXT, but possibly modified if options have been extracted from the
231 text. The cdr is the sectioning entry, similar to what is given
232 in org-export-latex-classes."
233 (let* ((frame-level (or org-beamer-frame-level-now org-beamer-frame-level))
234 (default
235 (if org-beamer-use-parts
236 '((1 . ("\\part{%s}" . "\\part*{%s}"))
237 (2 . ("\\section{%s}" . "\\section*{%s}"))
238 (3 . ("\\subsection{%s}" . "\\subsection*{%s}")))
239 '((1 . ("\\section{%s}" . "\\section*{%s}"))
240 (2 . ("\\subsection{%s}" . "\\subsection*{%s}")))))
241 (envs (append org-beamer-environments-extra
242 org-beamer-environments-default))
243 (props (org-get-text-property-any 0 'org-props text))
244 (in "") (out "") org-beamer-option org-beamer-action org-beamer-defaction org-beamer-environment org-beamer-extra
245 columns-option column-option
246 env have-text ass tmp)
247 (if (= frame-level 0) (setq frame-level nil))
248 (when (and org-beamer-inside-frame-at-level
249 (<= level org-beamer-inside-frame-at-level))
250 (setq org-beamer-inside-frame-at-level nil))
251 (when (setq tmp (org-beamer-assoc-not-empty "BEAMER_col" props))
252 (if (and (string-match "\\`[0-9.]+\\'" tmp)
253 (or (= (string-to-number tmp) 1.0)
254 (= (string-to-number tmp) 0.0)))
255 ;; column width 1 means close columns, go back to full width
256 (org-beamer-close-columns-maybe)
257 (when (setq ass (assoc "BEAMER_envargs" props))
258 (let (case-fold-search)
259 (while (string-match "C\\(\\[[^][]*\\]\\|<[^<>]*>\\)" (cdr ass))
260 (setq columns-option (match-string 1 (cdr ass)))
261 (setcdr ass (replace-match "" t t (cdr ass))))
262 (while (string-match "c\\(\\[[^][]*\\]\\|<[^<>]*>\\)" (cdr ass))
263 (setq column-option (match-string 1 (cdr ass)))
264 (setcdr ass (replace-match "" t t (cdr ass))))))
265 (org-beamer-open-columns-maybe columns-option)
266 (org-beamer-open-column tmp column-option)))
267 (cond
268 ((or (equal (cdr (assoc "BEAMER_env" props)) "frame")
269 (and frame-level (= level frame-level)))
270 ;; A frame
271 (org-beamer-get-special props)
273 (setq in (org-fill-template
274 "\\begin{frame}%a%A%o%T%S%x"
275 (list (cons "a" (or org-beamer-action ""))
276 (cons "A" (or org-beamer-defaction ""))
277 (cons "o" (or org-beamer-option org-beamer-frame-default-options ""))
278 (cons "x" (if org-beamer-extra (concat "\n" org-beamer-extra) ""))
279 (cons "h" "%s")
280 (cons "T" (if (string-match "\\S-" text)
281 "\n\\frametitle{%s}" ""))
282 (cons "S" (if (string-match "\\\\\\\\" text)
283 "\n\\framesubtitle{%s}" ""))))
284 out (copy-sequence "\\end{frame}"))
285 (org-add-props out
286 '(org-insert-hook org-beamer-close-columns-maybe))
287 (setq org-beamer-inside-frame-at-level level)
288 (cons text (list in out in out)))
289 ((and (setq env (cdr (assoc "BEAMER_env" props)))
290 (setq ass (assoc env envs)))
291 ;; A beamer environment selected by the BEAMER_env property
292 (if (string-match "[ \t]+:[ \t]*$" text)
293 (setq text (replace-match "" t t text)))
294 (if (member env '("note" "noteNH"))
295 ;; There should be no labels in a note, so we remove the targets
296 ;; FIXME???
297 (remove-text-properties 0 (length text) '(target nil) text))
298 (org-beamer-get-special props)
299 (setq text (org-trim text))
300 (setq have-text (string-match "\\S-" text))
301 (setq in (org-fill-template
302 (nth 2 ass)
303 (list (cons "a" (or org-beamer-action ""))
304 (cons "A" (or org-beamer-defaction ""))
305 (cons "o" (or org-beamer-option ""))
306 (cons "x" (if org-beamer-extra (concat "\n" org-beamer-extra) ""))
307 (cons "h" "%s")
308 (cons "H" (if have-text (concat "{" text "}") ""))
309 (cons "U" (if have-text (concat "[" text "]") ""))))
310 out (nth 3 ass))
311 (cond
312 ((equal out "\\end{columns}")
313 (setq org-beamer-columns-open t)
314 (setq out (org-add-props (copy-sequence out)
315 '(org-insert-hook
316 (lambda ()
317 (org-beamer-close-column-maybe)
318 (setq org-beamer-columns-open nil))))))
319 ((equal out "\\end{column}")
320 (org-beamer-open-columns-maybe)))
321 (cons text (list in out in out)))
322 ((and (not org-beamer-inside-frame-at-level)
323 (or (not frame-level)
324 (< level frame-level))
325 (assoc level default))
326 ;; Normal sectioning
327 (cons text (cdr (assoc level default))))
328 (t nil))))
330 (defvar org-beamer-extra)
331 (defvar org-beamer-option)
332 (defvar org-beamer-action)
333 (defvar org-beamer-defaction)
334 (defvar org-beamer-environment)
335 (defun org-beamer-get-special (props)
336 "Extract an option, action, and default action string from text.
337 The variables org-beamer-option, org-beamer-action, org-beamer-defaction,
338 org-beamer-extra are all scoped into this function dynamically."
339 (let (tmp)
340 (setq org-beamer-environment (org-beamer-assoc-not-empty "BEAMER_env" props))
341 (setq org-beamer-extra (org-beamer-assoc-not-empty "BEAMER_extra" props))
342 (when org-beamer-extra
343 (setq org-beamer-extra (replace-regexp-in-string "\\\\n" "\n" org-beamer-extra)))
344 (setq tmp (org-beamer-assoc-not-empty "BEAMER_envargs" props))
345 (when tmp
346 (setq tmp (copy-sequence tmp))
347 (if (string-match "\\[<[^][<>]*>\\]" tmp)
348 (setq org-beamer-defaction (match-string 0 tmp)
349 tmp (replace-match "" t t tmp)))
350 (if (string-match "\\[[^][]*\\]" tmp)
351 (setq org-beamer-option (match-string 0 tmp)
352 tmp (replace-match "" t t tmp)))
353 (if (string-match "<[^<>]*>" tmp)
354 (setq org-beamer-action (match-string 0 tmp)
355 tmp (replace-match "" t t tmp))))))
357 (defun org-beamer-assoc-not-empty (elt list)
358 (let ((tmp (cdr (assoc elt list))))
359 (and tmp (string-match "\\S-" tmp) tmp)))
362 (defvar org-beamer-mode-map (make-sparse-keymap)
363 "The keymap for `org-beamer-mode'.")
364 (define-key org-beamer-mode-map "\C-c\C-b" 'org-beamer-select-environment)
366 (define-minor-mode org-beamer-mode
367 "Special support for editing Org-mode files made to export to beamer."
368 nil " Bm" nil)
369 (when (fboundp 'font-lock-add-keywords)
370 (font-lock-add-keywords
371 'org-mode
372 '((":\\(B_[a-z]+\\|BMCOL\\):" 1 'org-beamer-tag prepend))
373 'prepent))
375 (defun org-beamer-place-default-actions-for-lists ()
376 "Find default overlay specifications in items, and move them.
377 The need to be after the begin statement of the environment."
378 (when org-beamer-export-is-beamer-p
379 (let (dovl)
380 (goto-char (point-min))
381 (while (re-search-forward
382 "^[ \t]*\\\\begin{\\(itemize\\|enumerate\\|description\\)}[ \t\n]*\\\\item\\>\\( ?\\(<[^<>\n]*>\\|\\[[^][\n*]\\]\\)\\)?[ \t]*\\S-" nil t)
383 (if (setq dovl (cdr (assoc "BEAMER_dovl"
384 (get-text-property (match-end 0)
385 'org-props))))
386 (save-excursion
387 (goto-char (1+ (match-end 1)))
388 (insert dovl)))))))
390 (defun org-beamer-amend-header ()
391 "Add `org-beamer-header-extra' to the LaTeX header.
392 If the file contains the string BEAMER-HEADER-EXTRA-HERE on a line
393 by itself, it will be replaced with `org-beamer-header-extra'. If not,
394 the value will be inserted right after the documentclass statement."
395 (when (and org-beamer-export-is-beamer-p
396 org-beamer-header-extra)
397 (goto-char (point-min))
398 (cond
399 ((re-search-forward
400 "^[ \t]*\\[?BEAMER-HEADER-EXTRA\\(-HERE\\)?\\]?[ \t]*$" nil t)
401 (replace-match org-beamer-header-extra t t)
402 (or (bolp) (insert "\n")))
403 ((re-search-forward "^[ \t]*\\\\begin{document}" nil t)
404 (beginning-of-line 1)
405 (insert org-beamer-header-extra)
406 (or (bolp) (insert "\n"))))))
408 (defcustom org-beamer-fragile-re "\\\\\\(verb\\|lstinline\\)\\|^[ \t]*\\\\begin{\\(verbatim\\|lstlisting\\|minted\\)}"
409 "If this regexp matches in a frame, the frame is marked as fragile."
410 :group 'org-beamer
411 :version "24.1"
412 :type 'regexp)
414 (defface org-beamer-tag '((t (:box (:line-width 1 :color grey40))))
415 "The special face for beamer tags."
416 :group 'org-beamer)
419 ;; Functions to initialize and post-process
420 ;; These functions will be hooked into various places in the export process
422 (defun org-beamer-initialize-open-trackers ()
423 "Reset variables that track if certain environments are open during export."
424 (setq org-beamer-columns-open nil)
425 (setq org-beamer-column-open nil)
426 (setq org-beamer-inside-frame-at-level nil)
427 (setq org-beamer-export-is-beamer-p nil))
429 (defun org-beamer-after-initial-vars ()
430 "Find special settings for beamer and store them.
431 The effect is that these values will be accessible during export."
432 ;; First verify that we are exporting using the beamer class
433 (setq org-beamer-export-is-beamer-p
434 (string-match "\\\\documentclass\\(\\[[^][]*?\\]\\)?{beamer}"
435 org-export-latex-header))
436 (when org-beamer-export-is-beamer-p
437 ;; Find the frame level
438 (setq org-beamer-frame-level-now
439 (or (and (org-region-active-p)
440 (save-excursion
441 (goto-char (region-beginning))
442 (and (looking-at org-complex-heading-regexp)
443 (org-entry-get nil "BEAMER_FRAME_LEVEL" 'selective))))
444 (save-excursion
445 (save-restriction
446 (widen)
447 (goto-char (point-min))
448 (and (re-search-forward
449 "^#\\+BEAMER_FRAME_LEVEL:[ \t]*\\(.*?\\)[ \t]*$" nil t)
450 (match-string 1))))
451 (plist-get org-export-latex-options-plist :beamer-frame-level)
452 org-beamer-frame-level))
453 ;; Normalize the value so that the functions can trust the value
454 (cond
455 ((not org-beamer-frame-level-now)
456 (setq org-beamer-frame-level-now nil))
457 ((stringp org-beamer-frame-level-now)
458 (setq org-beamer-frame-level-now
459 (string-to-number org-beamer-frame-level-now))))
460 ;; Find the header additions, most likely theme commands
461 (setq org-beamer-header-extra
462 (or (and (org-region-active-p)
463 (save-excursion
464 (goto-char (region-beginning))
465 (and (looking-at org-complex-heading-regexp)
466 (org-entry-get nil "BEAMER_HEADER_EXTRA"
467 'selective))))
468 (save-excursion
469 (save-restriction
470 (widen)
471 (let ((txt ""))
472 (goto-char (point-min))
473 (while (re-search-forward
474 "^#\\+BEAMER_HEADER_EXTRA:[ \t]*\\(.*?\\)[ \t]*$"
475 nil t)
476 (setq txt (concat txt "\n" (match-string 1))))
477 (if (> (length txt) 0) (substring txt 1)))))
478 (plist-get org-export-latex-options-plist
479 :beamer-header-extra)))
480 (let ((inhibit-read-only t)
481 (case-fold-search nil)
482 props)
483 (org-unmodified
484 (remove-text-properties (point-min) (point-max) '(org-props nil))
485 (org-map-entries
486 '(progn
487 (setq props (org-entry-properties nil 'standard))
488 (if (and (not (assoc "BEAMER_env" props))
489 (looking-at ".*?:B_\\(note\\(NH\\)?\\):"))
490 (push (cons "BEAMER_env" (match-string 1)) props))
491 (put-text-property (point-at-bol) (point-at-eol) 'org-props props)))
492 (setq org-export-latex-options-plist
493 (plist-put org-export-latex-options-plist :tags nil))))))
495 (defun org-beamer-auto-fragile-frames ()
496 "Mark any frames containing verbatim environments as fragile.
497 This function will run in the final LaTeX document."
498 (when org-beamer-export-is-beamer-p
499 (let (opts)
500 (goto-char (point-min))
501 ;; Find something that might be fragile
502 (while (re-search-forward org-beamer-fragile-re nil t)
503 (save-excursion
504 ;; Are we inside a frame here?
505 (when (and (re-search-backward "^[ \t]*\\\\\\(begin\\|end\\){frame}"
506 nil t)
507 (equal (match-string 1) "begin"))
508 ;; yes, inside a frame, make sure "fragile" is one of the options
509 (goto-char (match-end 0))
510 (if (not (looking-at "\\[.*?\\]"))
511 (insert "[fragile]")
512 (setq opts (substring (match-string 0) 1 -1))
513 (delete-region (match-beginning 0) (match-end 0))
514 (setq opts (org-split-string opts ","))
515 (add-to-list 'opts "fragile")
516 (insert "[" (mapconcat 'identity opts ",") "]"))))))))
518 (defcustom org-beamer-outline-frame-title "Outline"
519 "Default title of a frame containing an outline."
520 :group 'org-beamer
521 :version "24.1"
522 :type '(string :tag "Outline frame title")
525 (defcustom org-beamer-outline-frame-options nil
526 "Outline frame options appended after \\begin{frame}.
527 You might want to put e.g. [allowframebreaks=0.9] here. Remember to
528 include square brackets."
529 :group 'org-beamer
530 :version "24.1"
531 :type '(string :tag "Outline frame options")
534 (defun org-beamer-fix-toc ()
535 "Fix the table of contents by removing the vspace line."
536 (when org-beamer-export-is-beamer-p
537 (save-excursion
538 (goto-char (point-min))
539 (when (re-search-forward "\\(\\\\setcounter{tocdepth.*\n\\\\tableofcontents.*\n\\)\\(\\\\vspace\\*.*\\)"
540 nil t)
541 (replace-match
542 (concat "\\\\begin{frame}" org-beamer-outline-frame-options
543 "\n\\\\frametitle{"
544 org-beamer-outline-frame-title
545 "}\n\\1\\\\end{frame}")
546 t nil)))))
548 (defun org-beamer-property-changed (property value)
549 "Track the BEAMER_env property with tags."
550 (cond
551 ((equal property "BEAMER_env")
552 (save-excursion
553 (org-back-to-heading t)
554 (let ((tags (org-get-tags)))
555 (setq tags (delq nil (mapcar (lambda (x)
556 (if (string-match "^B_" x) nil x))
557 tags)))
558 (org-set-tags-to tags))
559 (when (and value (stringp value) (string-match "\\S-" value))
560 (org-toggle-tag (concat "B_" value) 'on))))
561 ((equal property "BEAMER_col")
562 (org-toggle-tag "BMCOL" (if (and value (string-match "\\S-" value))
563 'on 'off)))))
565 (defun org-beamer-select-beamer-code ()
566 "Take code marked for BEAMER and turn it into marked for LaTeX."
567 (when org-beamer-export-is-beamer-p
568 (goto-char (point-min))
569 (while (re-search-forward
570 "^\\([ \]*#\\+\\(begin_\\|end_\\)?\\)\\(beamer\\)\\>" nil t)
571 (replace-match "\\1latex"))))
573 ;; OK, hook all these functions into appropriate places
574 (add-hook 'org-export-first-hook
575 'org-beamer-initialize-open-trackers)
576 (add-hook 'org-property-changed-functions
577 'org-beamer-property-changed)
578 (add-hook 'org-export-latex-after-initial-vars-hook
579 'org-beamer-after-initial-vars)
580 (add-hook 'org-export-latex-final-hook
581 'org-beamer-place-default-actions-for-lists)
582 (add-hook 'org-export-latex-final-hook
583 'org-beamer-auto-fragile-frames)
584 (add-hook 'org-export-latex-final-hook
585 'org-beamer-fix-toc)
586 (add-hook 'org-export-latex-final-hook
587 'org-beamer-amend-header)
588 (add-hook 'org-export-preprocess-before-selecting-backend-code-hook
589 'org-beamer-select-beamer-code)
591 (defun org-insert-beamer-options-template (&optional kind)
592 "Insert a settings template, to make sure users do this right."
593 (interactive (progn
594 (message "Current [s]ubtree or [g]lobal?")
595 (if (equal (read-char-exclusive) ?g)
596 (list 'global)
597 (list 'subtree))))
598 (if (eq kind 'subtree)
599 (progn
600 (org-back-to-heading t)
601 (org-reveal)
602 (org-entry-put nil "LaTeX_CLASS" "beamer")
603 (org-entry-put nil "LaTeX_CLASS_OPTIONS" "[presentation]")
604 (org-entry-put nil "EXPORT_FILE_NAME" "presentation.pdf")
605 (org-entry-put nil "BEAMER_FRAME_LEVEL" (number-to-string
606 org-beamer-frame-level))
607 (when org-beamer-themes
608 (org-entry-put nil "BEAMER_HEADER_EXTRA" org-beamer-themes))
609 (when org-beamer-column-view-format
610 (org-entry-put nil "COLUMNS" org-beamer-column-view-format))
611 (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"))
612 (insert "#+LaTeX_CLASS: beamer\n")
613 (insert "#+LaTeX_CLASS_OPTIONS: [presentation]\n")
614 (insert (format "#+BEAMER_FRAME_LEVEL: %d\n" org-beamer-frame-level) "\n")
615 (when org-beamer-themes
616 (insert "#+BEAMER_HEADER_EXTRA: " org-beamer-themes "\n"))
617 (when org-beamer-column-view-format
618 (insert "#+COLUMNS: " org-beamer-column-view-format "\n"))
619 (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")))
622 (defun org-beamer-allowed-property-values (property)
623 "Supply allowed values for BEAMER properties."
624 (cond
625 ((and (equal property "BEAMER_env")
626 (not (org-entry-get nil (concat property "_ALL") 'inherit)))
627 ;; If no allowed values for BEAMER_env have been defined,
628 ;; supply all defined environments
629 (mapcar 'car (append org-beamer-environments-extra
630 org-beamer-environments-default)))
631 ((and (equal property "BEAMER_col")
632 (not (org-entry-get nil (concat property "_ALL") 'inherit)))
633 ;; If no allowed values for BEAMER_col have been defined,
634 ;; supply some
635 '("0.1" "0.2" "0.3" "0.4" "0.5" "0.6" "0.7" "0.8" "0.9" "" ":ETC"))
636 (t nil)))
638 (add-hook 'org-property-allowed-value-functions
639 'org-beamer-allowed-property-values)
641 (provide 'org-beamer)
643 ;;; org-beamer.el ends here