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