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