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