org-gnus.el: Mention also Gmane in org-gnus-prefer-web-links
[org-mode/org-kjn.git] / lisp / org-beamer.el
blob1cd7b4d4c27d38cf5eb4a9e9b098a8ceea9b4951
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 '(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 (when (fboundp 'font-lock-add-keywords)
357 (font-lock-add-keywords
358 'org-mode
359 '((":\\(B_[a-z]+\\|BMCOL\\):" 1 'org-beamer-tag prepend))
360 'prepent))
362 (defun org-beamer-place-default-actions-for-lists ()
363 "Find default overlay specifications in items, and move them.
364 The need to be after the begin statement of the environment."
365 (when org-beamer-export-is-beamer-p
366 (let (dovl)
367 (goto-char (point-min))
368 (while (re-search-forward
369 "^[ \t]*\\\\begin{\\(itemize\\|enumerate\\|desctiption\\)}[ \t\n]*\\\\item\\>\\( ?\\(<[^<>\n]*>\\|\\[[^][\n*]\\]\\)\\)?[ \t]*\\S-" nil t)
370 (if (setq dovl (cdr (assoc "BEAMER_dovl"
371 (get-text-property (match-end 0)
372 'org-props))))
373 (save-excursion
374 (goto-char (1+ (match-end 1)))
375 (insert dovl)))))))
377 (defun org-beamer-amend-header ()
378 "Add `org-beamer-header-extra' to the LaTeX herder.
379 If the file contains the string BEAMER-HEADER-EXTRA-HERE on a line
380 by itself, it will be replaced with `org-beamer-header-extra'. If not,
381 the value will be inserted right after the documentclass statement."
382 (when (and org-beamer-export-is-beamer-p
383 org-beamer-header-extra)
384 (goto-char (point-min))
385 (cond
386 ((re-search-forward "^[ \t]*BEAMER-HEADER-EXTRA-HERE[ \t]*$" nil t)
387 (replace-match org-beamer-header-extra t t)
388 (or (bolp) (insert "\n")))
389 ((re-search-forward "^[ \t]*\\\\documentclass\\>" nil t)
390 (beginning-of-line 2)
391 (insert org-beamer-header-extra)
392 (or (bolp) (insert "\n"))))))
394 (defcustom org-beamer-fragile-re "^[ \t]*\\\\begin{\\(verbatim\\|lstlisting\\)}"
395 "If this regexp matches in a frame, the frame is marked as fragile."
396 :group 'org-beamer
397 :type 'regexp)
399 (defface org-beamer-tag '((t (:box (:line-width 1 :color grey40))))
400 "The special face for beamer tags."
401 :group 'org-beamer)
404 ;; Functions to initialize and post-process
405 ;; These fuctions will be hooked into various places in the export process
407 (defun org-beamer-initialize-open-trackers ()
408 "Reset variables that track if certain environments are open during export."
409 (setq org-beamer-columns-open nil)
410 (setq org-beamer-column-open nil)
411 (setq org-beamer-inside-frame-at-level nil)
412 (setq org-beamer-export-is-beamer-p nil))
414 (defun org-beamer-after-initial-vars ()
415 "Find special setings for beamer and store them.
416 The effect is that these values will be accessible during export."
417 ;; First verify that we are exporting using the beamer class
418 (setq org-beamer-export-is-beamer-p
419 (string-match "\\\\documentclass\\(\\[[^][]*?\\]\\)?{beamer}"
420 org-export-latex-header))
421 (when org-beamer-export-is-beamer-p
422 ;; Find the frame level
423 (setq org-beamer-frame-level-now
424 (or (and (org-region-active-p)
425 (save-excursion
426 (goto-char (region-beginning))
427 (and (looking-at org-complex-heading-regexp)
428 (org-entry-get nil "BEAMER_FRAME_LEVEL" 'selective))))
429 (save-excursion
430 (save-restriction
431 (widen)
432 (goto-char (point-min))
433 (and (re-search-forward
434 "^#\\+BEAMER_FRAME_LEVEL:[ \t]*\\(.*?\\)[ \t]*$" nil t)
435 (match-string 1))))
436 (plist-get org-export-latex-options-plist :beamer-frame-level)
437 org-beamer-frame-level))
438 ;; Normalize the value so that the functions can trust the value
439 (cond
440 ((not org-beamer-frame-level-now)
441 (setq org-beamer-frame-level-now nil))
442 ((stringp org-beamer-frame-level-now)
443 (setq org-beamer-frame-level-now
444 (string-to-number org-beamer-frame-level-now))))
445 ;; Find the header additons, most likely theme commands
446 (setq org-beamer-header-extra
447 (or (and (org-region-active-p)
448 (save-excursion
449 (goto-char (region-beginning))
450 (and (looking-at org-complex-heading-regexp)
451 (org-entry-get nil "BEAMER_HEADER_EXTRA"
452 'selective))))
453 (save-excursion
454 (save-restriction
455 (widen)
456 (let ((txt ""))
457 (goto-char (point-min))
458 (while (re-search-forward
459 "^#\\+BEAMER_HEADER_EXTRA:[ \t]*\\(.*?\\)[ \t]*$"
460 nil t)
461 (setq txt (concat txt "\n" (match-string 1))))
462 (if (> (length txt) 0) (substring txt 1)))))
463 (plist-get org-export-latex-options-plist
464 :beamer-header-extra)))
465 (let ((inhibit-read-only t)
466 (case-fold-search nil)
467 props)
468 (org-unmodified
469 (remove-text-properties (point-min) (point-max) '(org-props nil))
470 (org-map-entries
471 '(progn
472 (setq props (org-entry-properties nil 'standard))
473 (if (and (not (assoc "BEAMER_env" props))
474 (looking-at ".*?:B_\\(note\\(NH\\)?\\):"))
475 (push (cons "BEAMER_env" (match-string 1)) props))
476 (put-text-property (point-at-bol) (point-at-eol) 'org-props props)))
477 (setq org-export-latex-options-plist
478 (plist-put org-export-latex-options-plist :tags nil))))))
480 (defun org-beamer-auto-fragile-frames ()
481 "Mark any frames containing verbatim environments as fragile.
482 This funcion will run in the final LaTeX document."
483 (when org-beamer-export-is-beamer-p
484 (let (opts)
485 (goto-char (point-min))
486 ;; Find something that might be fragile
487 (while (re-search-forward org-beamer-fragile-re nil t)
488 (save-excursion
489 ;; Are we inside a frame here?
490 (when (and (re-search-backward "^[ \t]*\\\\\\(begin\\|end\\){frame}"
491 nil t)
492 (equal (match-string 1) "begin"))
493 ;; yes, inside a frame, make sure "fragile" is one of the options
494 (goto-char (match-end 0))
495 (if (not (looking-at "\\[.*?\\]"))
496 (insert "[fragile]")
497 (setq opts (substring (match-string 0) 1 -1))
498 (delete-region (match-beginning 0) (match-end 0))
499 (setq opts (org-split-string opts ","))
500 (add-to-list 'opts "fragile")
501 (insert "[" (mapconcat 'identity opts ",") "]"))))))))
503 (defcustom org-beamer-outline-frame-title "Outline"
504 "Default title of a frame containing an outline."
505 :group 'org-beamer
506 :type '(string :tag "Outline frame title")
509 (defcustom org-beamer-outline-frame-options nil
510 "Outline frame options appended after \\begin{frame}. You might
511 want to put e.g. [allowframebreaks=0.9] here. Remember to include
512 square brackets."
513 :group 'org-beamer
514 :type '(string :tag "Outline frame options")
517 (defun org-beamer-fix-toc ()
518 "Fix the table of contents by removing the vspace line."
519 (when org-beamer-export-is-beamer-p
520 (save-excursion
521 (goto-char (point-min))
522 (when (re-search-forward "\\(\\\\setcounter{tocdepth.*\n\\\\tableofcontents.*\n\\)\\(\\\\vspace\\*.*\\)"
523 nil t)
524 (replace-match
525 (concat "\\\\begin{frame}" org-beamer-outline-frame-options
526 "\n\\\\frametitle{"
527 org-beamer-outline-frame-title
528 "}\n\\1\\\\end{frame}")
529 t nil)))))
531 (defun org-beamer-property-changed (property value)
532 "Track the BEAMER_env property with tags."
533 (cond
534 ((equal property "BEAMER_env")
535 (save-excursion
536 (org-back-to-heading t)
537 (let ((tags (org-get-tags)))
538 (setq tags (delq nil (mapcar (lambda (x)
539 (if (string-match "^B_" x) nil x))
540 tags)))
541 (org-set-tags-to tags))
542 (when (and value (stringp value) (string-match "\\S-" value))
543 (org-toggle-tag (concat "B_" value) 'on))))
544 ((equal property "BEAMER_col")
545 (org-toggle-tag "BMCOL" (if (and value (string-match "\\S-" value))
546 'on 'off)))))
548 (defun org-beamer-select-beamer-code ()
549 "Take code marked for BEAMER and turn it into marked for LaTeX."
550 (when org-beamer-export-is-beamer-p
551 (goto-char (point-min))
552 (while (re-search-forward
553 "^\\([ \]*#\\+\\(begin_\\|end_\\)?\\)\\(beamer\\)\\>" nil t)
554 (replace-match "\\1latex"))))
556 ;; OK, hook all these functions into appropriate places
557 (add-hook 'org-export-first-hook
558 'org-beamer-initialize-open-trackers)
559 (add-hook 'org-property-changed-functions
560 'org-beamer-property-changed)
561 (add-hook 'org-export-latex-after-initial-vars-hook
562 'org-beamer-after-initial-vars)
563 (add-hook 'org-export-latex-final-hook
564 'org-beamer-place-default-actions-for-lists)
565 (add-hook 'org-export-latex-final-hook
566 'org-beamer-auto-fragile-frames)
567 (add-hook 'org-export-latex-final-hook
568 'org-beamer-fix-toc)
569 (add-hook 'org-export-latex-final-hook
570 'org-beamer-amend-header)
571 (add-hook 'org-export-preprocess-before-selecting-backend-code-hook
572 'org-beamer-select-beamer-code)
574 (defun org-insert-beamer-options-template (kind)
575 "Insert a settings template, to make sure users do this right."
576 (interactive (progn
577 (message "Current [s]ubtree or [g]lobal?")
578 (if (equal (read-char-exclusive) ?g)
579 (list 'global)
580 (list 'subtree))))
581 (if (eq kind 'subtree)
582 (progn
583 (org-back-to-heading t)
584 (org-reveal)
585 (org-entry-put nil "LaTeX_CLASS" "beamer")
586 (org-entry-put nil "LaTeX_CLASS_OPTIONS" "[presentation]")
587 (org-entry-put nil "EXPORT_FILE_NAME" "presentation.pdf")
588 (org-entry-put nil "BEAMER_FRAME_LEVEL" (number-to-string
589 org-beamer-frame-level))
590 (org-entry-put nil "BEAMER_HEADER_EXTRA" org-beamer-themes)
591 (org-entry-put nil "COLUMNS" org-beamer-column-view-format)
592 (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"))
593 (insert "#+LaTeX_CLASS: beamer\n")
594 (insert "#+LaTeX_CLASS_OPTIONS: [presentation]\n")
595 (insert (format "#+BEAMER_FRAME_LEVEL: %d\n" org-beamer-frame-level) "\n")
596 (insert "#+BEAMER_HEADER_EXTRA: " org-beamer-themes "\n")
597 (insert "#+COLUMNS: " org-beamer-column-view-format "\n")
598 (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")))
601 (defun org-beamer-allowed-property-values (property)
602 "Supply allowed values for BEAMER properties."
603 (cond
604 ((and (equal property "BEAMER_env")
605 (not (org-entry-get nil (concat property "_ALL") 'inherit)))
606 ;; If no allowed values for BEAMER_env have been defined,
607 ;; supply all defined environments
608 (mapcar 'car (append org-beamer-environments-extra
609 org-beamer-environments-default)))
610 ((and (equal property "BEAMER_col")
611 (not (org-entry-get nil (concat property "_ALL") 'inherit)))
612 ;; If no allowed values for BEAMER_col have been defined,
613 ;; supply some
614 '("0.1" "0.2" "0.3" "0.4" "0.5" "0.6" "0.7" "0.8" "0.9" "" ":ETC"))
615 (t nil)))
617 (add-hook 'org-property-allowed-value-functions
618 'org-beamer-allowed-property-values)
620 (provide 'org-beamer)
622 ;; arch-tag: 68bac91a-a946-43a3-8173-a9269306f67c
624 ;;; org-beamer.el ends here