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