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