ox: Fix `org-export-with-backend'
[org-mode.git] / lisp / ox-beamer.el
blobf1dbe8255e03b492056974d0158dbb67245358ed
1 ;;; ox-beamer.el --- Beamer Back-End for Org Export Engine
3 ;; Copyright (C) 2007-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten.dominik AT gmail DOT com>
6 ;; Nicolas Goaziou <n.goaziou AT gmail DOT com>
7 ;; Keywords: org, wp, tex
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; This library implements both a Beamer back-end, derived from the
25 ;; LaTeX one and a minor mode easing structure edition of the
26 ;; document.
28 ;; Depending on the desired output format, three commands are provided
29 ;; for export: `org-beamer-export-as-latex' (temporary buffer),
30 ;; `org-beamer-export-to-latex' ("tex" file) and
31 ;; `org-beamer-export-to-pdf' ("pdf" file).
33 ;; This back-end supports every buffer keyword, attribute and options
34 ;; items (see `org-latex-options-alist') already supported by `latex'
35 ;; back-end. As such, it is suggested to add an entry in
36 ;; `org-latex-classes' variable which is appropriate for Beamer
37 ;; export.
39 ;; On top of this, the `beamer' back-end also introduces the following
40 ;; keywords: "BEAMER_THEME", "BEAMER_COLOR_THEME",
41 ;; "BEAMER_FONT_THEME", "BEAMER_INNER_THEME", "BEAMER_OUTER_THEME" and
42 ;; "BEAMER_HEADER". All but the latter accept options in square
43 ;; brackets.
45 ;; Moreover, headlines now fall into three categories: sectioning
46 ;; elements, frames and blocks.
48 ;; - Headlines become frames when their level is equal to
49 ;; `org-beamer-frame-level' (or "H" value in the OPTIONS line).
50 ;; Though, if a headline in the current tree has a "BEAMER_env"
51 ;; (see below) property set to either "frame" or "fullframe", its
52 ;; level overrides the variable. A "fullframe" is a frame with an
53 ;; empty (ignored) title.
55 ;; - All frames' children become block environments. Special block
56 ;; types can be enforced by setting headline's "BEAMER_env" property
57 ;; to an appropriate value (see `org-beamer-environments-default'
58 ;; for supported value and `org-beamer-environments-extra' for
59 ;; adding more).
61 ;; - As a special case, if the "BEAMER_env" property is set to either
62 ;; "appendix", "note", "noteNH" or "againframe", the headline will
63 ;; become, respectively, an appendix, a note (within frame or
64 ;; between frame, depending on its level), a note with its title
65 ;; ignored or an againframe command. In the latter case,
66 ;; a "BEAMER_ref" property is mandatory in order to refer to the
67 ;; frame being resumed, and contents are ignored.
69 ;; Also, a headline with an "ignoreheading" environment will have
70 ;; its contents only inserted in the output. This special value is
71 ;; useful to have data between frames, or to properly close
72 ;; a "column" environment.
74 ;; Along with "BEAMER_env", headlines also support the "BEAMER_act"
75 ;; and "BEAMER_opt" properties. The former is translated as an
76 ;; overlay/action specification (or a default overlay specification
77 ;; when enclosed within square brackets) whereas the latter specifies
78 ;; options for the current frame ("fragile" option is added
79 ;; automatically, though).
81 ;; Moreover, headlines handle the "BEAMER_col" property. Its value
82 ;; should be a decimal number representing the width of the column as
83 ;; a fraction of the total text width. If the headline has no
84 ;; specific environment, its title will be ignored and its contents
85 ;; will fill the column created. Otherwise, the block will fill the
86 ;; whole column and the title will be preserved. Two contiguous
87 ;; headlines with a non-nil "BEAMER_col" value share the same
88 ;; "columns" LaTeX environment. It will end before the next headline
89 ;; without such a property. This environment is generated
90 ;; automatically. Although, it can also be explicitly created, with
91 ;; a special "columns" value for "BEAMER_env" property (if it needs to
92 ;; be set up with some specific options, for example).
94 ;; Every plain list has support for `:environment', `:overlay' and
95 ;; `:options' attributes (through ATTR_BEAMER affiliated keyword).
96 ;; The first one allows to use a different environment, the second
97 ;; sets overlay specifications and the last one inserts optional
98 ;; arguments in current list environment.
100 ;; Table of contents generated from "toc:t" option item are wrapped
101 ;; within a "frame" environment. Those generated from a TOC keyword
102 ;; aren't. TOC keywords accept options enclosed within square
103 ;; brackets (e.g. #+TOC: headlines [currentsection]).
105 ;; Eventually, an export snippet with a value enclosed within angular
106 ;; brackets put at the beginning of an element or object whose type is
107 ;; among `bold', `item', `link', `radio-target' and `target' will
108 ;; control its overlay specifications.
110 ;; On the minor mode side, `org-beamer-select-environment' (bound by
111 ;; default to "C-c C-b") and `org-beamer-insert-options-template' are
112 ;; the two entry points.
114 ;;; Code:
116 (eval-when-compile (require 'cl))
117 (require 'ox-latex)
119 ;; Install a default set-up for Beamer export.
120 (unless (assoc "beamer" org-latex-classes)
121 (add-to-list 'org-latex-classes
122 '("beamer"
123 "\\documentclass[presentation]{beamer}
124 \[DEFAULT-PACKAGES]
125 \[PACKAGES]
126 \[EXTRA]"
127 ("\\section{%s}" . "\\section*{%s}")
128 ("\\subsection{%s}" . "\\subsection*{%s}")
129 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
133 ;;; User-Configurable Variables
135 (defgroup org-export-beamer nil
136 "Options specific for using the beamer class in LaTeX export."
137 :tag "Org Beamer"
138 :group 'org-export
139 :version "24.2")
141 (defcustom org-beamer-frame-level 1
142 "The level at which headlines become frames.
144 Headlines at a lower level will be translated into a sectioning
145 structure. At a higher level, they will be translated into
146 blocks.
148 If a headline with a \"BEAMER_env\" property set to \"frame\" is
149 found within a tree, its level locally overrides this number.
151 This variable has no effect on headlines with the \"BEAMER_env\"
152 property set to either \"ignoreheading\", \"appendix\", or
153 \"note\", which will respectively, be invisible, become an
154 appendix or a note.
156 This integer is relative to the minimal level of a headline
157 within the parse tree, defined as 1."
158 :group 'org-export-beamer
159 :type 'integer)
161 (defcustom org-beamer-frame-default-options ""
162 "Default options string to use for frames.
163 For example, it could be set to \"allowframebreaks\"."
164 :group 'org-export-beamer
165 :type '(string :tag "[options]"))
167 (defcustom org-beamer-column-view-format
168 "%45ITEM %10BEAMER_env(Env) %10BEAMER_act(Act) %4BEAMER_col(Col) %8BEAMER_opt(Opt)"
169 "Column view format that should be used to fill the template."
170 :group 'org-export-beamer
171 :version "24.4"
172 :package-version '(Org . "8.0")
173 :type '(choice
174 (const :tag "Do not insert Beamer column view format" nil)
175 (string :tag "Beamer column view format")))
177 (defcustom org-beamer-theme "default"
178 "Default theme used in Beamer presentations."
179 :group 'org-export-beamer
180 :version "24.4"
181 :package-version '(Org . "8.0")
182 :type '(choice
183 (const :tag "Do not insert a Beamer theme" nil)
184 (string :tag "Beamer theme")))
186 (defcustom org-beamer-environments-extra nil
187 "Environments triggered by tags in Beamer export.
188 Each entry has 4 elements:
190 name Name of the environment
191 key Selection key for `org-beamer-select-environment'
192 open The opening template for the environment, with the following escapes
193 %a the action/overlay specification
194 %A the default action/overlay specification
195 %o the options argument of the template
196 %h the headline text
197 %r the raw headline text (i.e. without any processing)
198 %H if there is headline text, that raw text in {} braces
199 %U if there is headline text, that raw text in [] brackets
200 close The closing string of the environment."
201 :group 'org-export-beamer
202 :version "24.4"
203 :package-version '(Org . "8.1")
204 :type '(repeat
205 (list
206 (string :tag "Environment")
207 (string :tag "Selection key")
208 (string :tag "Begin")
209 (string :tag "End"))))
211 (defcustom org-beamer-outline-frame-title "Outline"
212 "Default title of a frame containing an outline."
213 :group 'org-export-beamer
214 :type '(string :tag "Outline frame title"))
216 (defcustom org-beamer-outline-frame-options ""
217 "Outline frame options appended after \\begin{frame}.
218 You might want to put e.g. \"allowframebreaks=0.9\" here."
219 :group 'org-export-beamer
220 :type '(string :tag "Outline frame options"))
224 ;;; Internal Variables
226 (defconst org-beamer-column-widths
227 "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.0 :ETC"
228 "The column widths that should be installed as allowed property values.")
230 (defconst org-beamer-environments-special
231 '(("againframe" "A")
232 ("appendix" "x")
233 ("column" "c")
234 ("columns" "C")
235 ("frame" "f")
236 ("fullframe" "F")
237 ("ignoreheading" "i")
238 ("note" "n")
239 ("noteNH" "N"))
240 "Alist of environments treated in a special way by the back-end.
241 Keys are environment names, as strings, values are bindings used
242 in `org-beamer-select-environment'. Environments listed here,
243 along with their binding, are hard coded and cannot be modified
244 through `org-beamer-environments-extra' variable.")
246 (defconst org-beamer-environments-default
247 '(("block" "b" "\\begin{block}%a{%h}" "\\end{block}")
248 ("alertblock" "a" "\\begin{alertblock}%a{%h}" "\\end{alertblock}")
249 ("verse" "v" "\\begin{verse}%a %% %h" "\\end{verse}")
250 ("quotation" "q" "\\begin{quotation}%a %% %h" "\\end{quotation}")
251 ("quote" "Q" "\\begin{quote}%a %% %h" "\\end{quote}")
252 ("structureenv" "s" "\\begin{structureenv}%a %% %h" "\\end{structureenv}")
253 ("theorem" "t" "\\begin{theorem}%a%U" "\\end{theorem}")
254 ("definition" "d" "\\begin{definition}%a%U" "\\end{definition}")
255 ("example" "e" "\\begin{example}%a%U" "\\end{example}")
256 ("exampleblock" "E" "\\begin{exampleblock}%a{%h}" "\\end{exampleblock}")
257 ("proof" "p" "\\begin{proof}%a%U" "\\end{proof}")
258 ("beamercolorbox" "o" "\\begin{beamercolorbox}%o{%h}" "\\end{beamercolorbox}"))
259 "Environments triggered by properties in Beamer export.
260 These are the defaults - for user definitions, see
261 `org-beamer-environments-extra'.")
263 (defconst org-beamer-verbatim-elements
264 '(code example-block fixed-width inline-src-block src-block verbatim)
265 "List of element or object types producing verbatim text.
266 This is used internally to determine when a frame should have the
267 \"fragile\" option.")
271 ;;; Internal functions
273 (defun org-beamer--normalize-argument (argument type)
274 "Return ARGUMENT string with proper boundaries.
276 TYPE is a symbol among the following:
277 `action' Return ARGUMENT within angular brackets.
278 `defaction' Return ARGUMENT within both square and angular brackets.
279 `option' Return ARGUMENT within square brackets."
280 (if (not (string-match "\\S-" argument)) ""
281 (case type
282 (action (if (string-match "\\`<.*>\\'" argument) argument
283 (format "<%s>" argument)))
284 (defaction (cond
285 ((string-match "\\`\\[<.*>\\]\\'" argument) argument)
286 ((string-match "\\`<.*>\\'" argument)
287 (format "[%s]" argument))
288 ((string-match "\\`\\[\\(.*\\)\\]\\'" argument)
289 (format "[<%s>]" (match-string 1 argument)))
290 (t (format "[<%s>]" argument))))
291 (option (if (string-match "\\`\\[.*\\]\\'" argument) argument
292 (format "[%s]" argument)))
293 (otherwise argument))))
295 (defun org-beamer--element-has-overlay-p (element)
296 "Non-nil when ELEMENT has an overlay specified.
297 An element has an overlay specification when it starts with an
298 `beamer' export-snippet whose value is between angular brackets.
299 Return overlay specification, as a string, or nil."
300 (let ((first-object (car (org-element-contents element))))
301 (when (eq (org-element-type first-object) 'export-snippet)
302 (let ((value (org-element-property :value first-object)))
303 (and (string-match "\\`<.*>\\'" value) value)))))
307 ;;; Define Back-End
309 (org-export-define-derived-backend 'beamer 'latex
310 :export-block "BEAMER"
311 :menu-entry
312 '(?l 1
313 ((?B "As LaTeX buffer (Beamer)" org-beamer-export-as-latex)
314 (?b "As LaTeX file (Beamer)" org-beamer-export-to-latex)
315 (?P "As PDF file (Beamer)" org-beamer-export-to-pdf)
316 (?O "As PDF file and open (Beamer)"
317 (lambda (a s v b)
318 (if a (org-beamer-export-to-pdf t s v b)
319 (org-open-file (org-beamer-export-to-pdf nil s v b)))))))
320 :options-alist
321 '((:beamer-theme "BEAMER_THEME" nil org-beamer-theme)
322 (:beamer-color-theme "BEAMER_COLOR_THEME" nil nil t)
323 (:beamer-font-theme "BEAMER_FONT_THEME" nil nil t)
324 (:beamer-inner-theme "BEAMER_INNER_THEME" nil nil t)
325 (:beamer-outer-theme "BEAMER_OUTER_THEME" nil nil t)
326 (:beamer-header-extra "BEAMER_HEADER" nil nil newline)
327 ;; Modify existing properties.
328 (:headline-levels nil "H" org-beamer-frame-level)
329 (:latex-class "LATEX_CLASS" nil "beamer" t))
330 :translate-alist '((bold . org-beamer-bold)
331 (export-block . org-beamer-export-block)
332 (export-snippet . org-beamer-export-snippet)
333 (headline . org-beamer-headline)
334 (item . org-beamer-item)
335 (keyword . org-beamer-keyword)
336 (link . org-beamer-link)
337 (plain-list . org-beamer-plain-list)
338 (radio-target . org-beamer-radio-target)
339 (target . org-beamer-target)
340 (template . org-beamer-template)))
344 ;;; Transcode Functions
346 ;;;; Bold
348 (defun org-beamer-bold (bold contents info)
349 "Transcode BLOCK object into Beamer code.
350 CONTENTS is the text being bold. INFO is a plist used as
351 a communication channel."
352 (format "\\alert%s{%s}"
353 (or (org-beamer--element-has-overlay-p bold) "")
354 contents))
357 ;;;; Export Block
359 (defun org-beamer-export-block (export-block contents info)
360 "Transcode an EXPORT-BLOCK element into Beamer code.
361 CONTENTS is nil. INFO is a plist used as a communication
362 channel."
363 (when (member (org-element-property :type export-block) '("BEAMER" "LATEX"))
364 (org-remove-indentation (org-element-property :value export-block))))
367 ;;;; Export Snippet
369 (defun org-beamer-export-snippet (export-snippet contents info)
370 "Transcode an EXPORT-SNIPPET object into Beamer code.
371 CONTENTS is nil. INFO is a plist used as a communication
372 channel."
373 (let ((backend (org-export-snippet-backend export-snippet))
374 (value (org-element-property :value export-snippet)))
375 ;; Only "latex" and "beamer" snippets are retained.
376 (cond ((eq backend 'latex) value)
377 ;; Ignore "beamer" snippets specifying overlays.
378 ((and (eq backend 'beamer)
379 (or (org-export-get-previous-element export-snippet info)
380 (not (string-match "\\`<.*>\\'" value))))
381 value))))
384 ;;;; Headline
386 ;; The main function to translate a headline is
387 ;; `org-beamer-headline'.
389 ;; Depending on the level at which a headline is considered as
390 ;; a frame (given by `org-beamer--frame-level'), the headline is
391 ;; either a section (`org-beamer--format-section'), a frame
392 ;; (`org-beamer--format-frame') or a block
393 ;; (`org-beamer--format-block').
395 ;; `org-beamer-headline' also takes care of special environments
396 ;; like "ignoreheading", "note", "noteNH", "appendix" and
397 ;; "againframe".
399 (defun org-beamer--get-label (headline info)
400 "Return label for HEADLINE, as a string.
402 INFO is a plist used as a communication channel.
404 The value is either the label specified in \"BEAMER_opt\"
405 property, or a fallback value built from headline's number. This
406 function assumes HEADLINE will be treated as a frame."
407 (let ((opt (org-element-property :BEAMER_OPT headline)))
408 (if (and (org-string-nw-p opt)
409 (string-match "\\(?:^\\|,\\)label=\\(.*?\\)\\(?:$\\|,\\)" opt))
410 (match-string 1 opt)
411 (format "sec-%s"
412 (mapconcat 'number-to-string
413 (org-export-get-headline-number headline info)
414 "-")))))
416 (defun org-beamer--frame-level (headline info)
417 "Return frame level in subtree containing HEADLINE.
418 INFO is a plist used as a communication channel."
420 ;; 1. Look for "frame" environment in parents, starting from the
421 ;; farthest.
422 (catch 'exit
423 (mapc (lambda (parent)
424 (let ((env (org-element-property :BEAMER_ENV parent)))
425 (when (and env (member-ignore-case env '("frame" "fullframe")))
426 (throw 'exit (org-export-get-relative-level parent info)))))
427 (nreverse (org-export-get-genealogy headline)))
428 nil)
429 ;; 2. Look for "frame" environment in HEADLINE.
430 (let ((env (org-element-property :BEAMER_ENV headline)))
431 (and env (member-ignore-case env '("frame" "fullframe"))
432 (org-export-get-relative-level headline info)))
433 ;; 3. Look for "frame" environment in sub-tree.
434 (org-element-map headline 'headline
435 (lambda (hl)
436 (let ((env (org-element-property :BEAMER_ENV hl)))
437 (when (and env (member-ignore-case env '("frame" "fullframe")))
438 (org-export-get-relative-level hl info))))
439 info 'first-match)
440 ;; 4. No "frame" environment in tree: use default value.
441 (plist-get info :headline-levels)))
443 (defun org-beamer--format-section (headline contents info)
444 "Format HEADLINE as a sectioning part.
445 CONTENTS holds the contents of the headline. INFO is a plist
446 used as a communication channel."
447 (let ((latex-headline
448 (org-export-data-with-backend
449 headline
450 ;; We create a temporary export back-end which behaves the
451 ;; same as current one, but adds "\protect" in front of the
452 ;; output of some objects.
453 (org-export-create-backend
454 :parent 'latex
455 :transcoders
456 (let ((protected-output
457 (function
458 (lambda (object contents info)
459 (let ((code (org-export-with-backend
460 'beamer object contents info)))
461 (if (org-string-nw-p code) (concat "\\protect" code)
462 code))))))
463 (mapcar #'(lambda (type) (cons type protected-output))
464 '(bold footnote-reference italic strike-through
465 timestamp underline))))
466 info))
467 (mode-specs (org-element-property :BEAMER_ACT headline)))
468 (if (and mode-specs
469 (string-match "\\`\\\\\\(.*?\\)\\(?:\\*\\|\\[.*\\]\\)?{"
470 latex-headline))
471 ;; Insert overlay specifications.
472 (replace-match (concat (match-string 1 latex-headline)
473 (format "<%s>" mode-specs))
474 nil nil latex-headline 1)
475 latex-headline)))
477 (defun org-beamer--format-frame (headline contents info)
478 "Format HEADLINE as a frame.
479 CONTENTS holds the contents of the headline. INFO is a plist
480 used as a communication channel."
481 (let ((fragilep
482 ;; FRAGILEP is non-nil when HEADLINE contains an element
483 ;; among `org-beamer-verbatim-elements'.
484 (org-element-map headline org-beamer-verbatim-elements 'identity
485 info 'first-match)))
486 (concat "\\begin{frame}"
487 ;; Overlay specification, if any. When surrounded by
488 ;; square brackets, consider it as a default
489 ;; specification.
490 (let ((action (org-element-property :BEAMER_ACT headline)))
491 (cond
492 ((not action) "")
493 ((string-match "\\`\\[.*\\]\\'" action )
494 (org-beamer--normalize-argument action 'defaction))
495 (t (org-beamer--normalize-argument action 'action))))
496 ;; Options, if any.
497 (let* ((beamer-opt (org-element-property :BEAMER_OPT headline))
498 (options
499 ;; Collect options from default value and headline's
500 ;; properties. Also add a label for links.
501 (append
502 (org-split-string org-beamer-frame-default-options ",")
503 (and beamer-opt
504 (org-split-string
505 ;; Remove square brackets if user provided
506 ;; them.
507 (and (string-match "^\\[?\\(.*\\)\\]?$" beamer-opt)
508 (match-string 1 beamer-opt))
509 ","))
510 ;; Provide an automatic label for the frame
511 ;; unless the user specified one.
512 (unless (and beamer-opt
513 (string-match "\\(^\\|,\\)label=" beamer-opt))
514 (list
515 (format "label=%s"
516 (org-beamer--get-label headline info)))))))
517 ;; Change options list into a string.
518 (org-beamer--normalize-argument
519 (mapconcat
520 'identity
521 (if (or (not fragilep) (member "fragile" options)) options
522 (cons "fragile" options))
523 ",")
524 'option))
525 ;; Title.
526 (let ((env (org-element-property :BEAMER_ENV headline)))
527 (format "{%s}"
528 (if (and env (equal (downcase env) "fullframe")) ""
529 (org-export-data
530 (org-element-property :title headline) info))))
531 "\n"
532 ;; The following workaround is required in fragile frames
533 ;; as Beamer will append "\par" to the beginning of the
534 ;; contents. So we need to make sure the command is
535 ;; separated from the contents by at least one space. If
536 ;; it isn't, it will create "\parfirst-word" command and
537 ;; remove the first word from the contents in the PDF
538 ;; output.
539 (if (not fragilep) contents
540 (replace-regexp-in-string "\\`\n*" "\\& " (or contents "")))
541 "\\end{frame}")))
543 (defun org-beamer--format-block (headline contents info)
544 "Format HEADLINE as a block.
545 CONTENTS holds the contents of the headline. INFO is a plist
546 used as a communication channel."
547 (let* ((column-width (org-element-property :BEAMER_COL headline))
548 ;; ENVIRONMENT defaults to "block" if none is specified and
549 ;; there is no column specification. If there is a column
550 ;; specified but still no explicit environment, ENVIRONMENT
551 ;; is "column".
552 (environment (let ((env (org-element-property :BEAMER_ENV headline)))
553 (cond
554 ;; "block" is the fallback environment.
555 ((and (not env) (not column-width)) "block")
556 ;; "column" only.
557 ((not env) "column")
558 ;; Use specified environment.
559 (t env))))
560 (raw-title (org-element-property :raw-value headline))
561 (env-format
562 (cond ((member environment '("column" "columns")) nil)
563 ((assoc environment
564 (append org-beamer-environments-extra
565 org-beamer-environments-default)))
566 (t (user-error "Wrong block type at a headline named \"%s\""
567 raw-title))))
568 (title (org-export-data (org-element-property :title headline) info))
569 (options (let ((options (org-element-property :BEAMER_OPT headline)))
570 (if (not options) ""
571 (org-beamer--normalize-argument options 'option))))
572 ;; Start a "columns" environment when explicitly requested or
573 ;; when there is no previous headline or the previous
574 ;; headline do not have a BEAMER_column property.
575 (parent-env (org-element-property
576 :BEAMER_ENV (org-export-get-parent-headline headline)))
577 (start-columns-p
578 (or (equal environment "columns")
579 (and column-width
580 (not (and parent-env
581 (equal (downcase parent-env) "columns")))
582 (or (org-export-first-sibling-p headline info)
583 (not (org-element-property
584 :BEAMER_COL
585 (org-export-get-previous-element
586 headline info)))))))
587 ;; End the "columns" environment when explicitly requested or
588 ;; when there is no next headline or the next headline do not
589 ;; have a BEAMER_column property.
590 (end-columns-p
591 (or (equal environment "columns")
592 (and column-width
593 (not (and parent-env
594 (equal (downcase parent-env) "columns")))
595 (or (org-export-last-sibling-p headline info)
596 (not (org-element-property
597 :BEAMER_COL
598 (org-export-get-next-element headline info))))))))
599 (concat
600 (when start-columns-p
601 ;; Column can accept options only when the environment is
602 ;; explicitly defined.
603 (if (not (equal environment "columns")) "\\begin{columns}\n"
604 (format "\\begin{columns}%s\n" options)))
605 (when column-width
606 (format "\\begin{column}%s{%s}\n"
607 ;; One can specify placement for column only when
608 ;; HEADLINE stands for a column on its own.
609 (if (equal environment "column") options "")
610 (format "%s\\textwidth" column-width)))
611 ;; Block's opening string.
612 (when (nth 2 env-format)
613 (concat
614 (org-fill-template
615 (nth 2 env-format)
616 (nconc
617 ;; If BEAMER_act property has its value enclosed in square
618 ;; brackets, it is a default overlay specification and
619 ;; overlay specification is empty. Otherwise, it is an
620 ;; overlay specification and the default one is nil.
621 (let ((action (org-element-property :BEAMER_ACT headline)))
622 (cond
623 ((not action) (list (cons "a" "") (cons "A" "")))
624 ((string-match "\\`\\[.*\\]\\'" action)
625 (list
626 (cons "A" (org-beamer--normalize-argument action 'defaction))
627 (cons "a" "")))
629 (list (cons "a" (org-beamer--normalize-argument action 'action))
630 (cons "A" "")))))
631 (list (cons "o" options)
632 (cons "h" title)
633 (cons "r" raw-title)
634 (cons "H" (if (equal raw-title "") ""
635 (format "{%s}" raw-title)))
636 (cons "U" (if (equal raw-title "") ""
637 (format "[%s]" raw-title))))))
638 "\n"))
639 contents
640 ;; Block's closing string, if any.
641 (and (nth 3 env-format) (concat (nth 3 env-format) "\n"))
642 (when column-width "\\end{column}\n")
643 (when end-columns-p "\\end{columns}"))))
645 (defun org-beamer-headline (headline contents info)
646 "Transcode HEADLINE element into Beamer code.
647 CONTENTS is the contents of the headline. INFO is a plist used
648 as a communication channel."
649 (unless (org-element-property :footnote-section-p headline)
650 (let ((level (org-export-get-relative-level headline info))
651 (frame-level (org-beamer--frame-level headline info))
652 (environment (let ((env (org-element-property :BEAMER_ENV headline)))
653 (or (org-string-nw-p env) "block"))))
654 (cond
655 ;; Case 1: Resume frame specified by "BEAMER_ref" property.
656 ((equal environment "againframe")
657 (let ((ref (org-element-property :BEAMER_REF headline)))
658 ;; Reference to frame being resumed is mandatory. Ignore
659 ;; the whole headline if it isn't provided.
660 (when (org-string-nw-p ref)
661 (concat "\\againframe"
662 ;; Overlay specification.
663 (let ((overlay (org-element-property :BEAMER_ACT headline)))
664 (when overlay
665 (org-beamer--normalize-argument
666 overlay
667 (if (string-match "^\\[.*\\]$" overlay) 'defaction
668 'action))))
669 ;; Options.
670 (let ((options (org-element-property :BEAMER_OPT headline)))
671 (when options
672 (org-beamer--normalize-argument options 'option)))
673 ;; Resolve reference provided by "BEAMER_ref"
674 ;; property. This is done by building a minimal fake
675 ;; link and calling the appropriate resolve function,
676 ;; depending on the reference syntax.
677 (let* ((type
678 (progn
679 (string-match "^\\(id:\\|#\\|\\*\\)?\\(.*\\)" ref)
680 (cond
681 ((or (not (match-string 1 ref))
682 (equal (match-string 1 ref) "*")) 'fuzzy)
683 ((equal (match-string 1 ref) "id:") 'id)
684 (t 'custom-id))))
685 (link (list 'link (list :path (match-string 2 ref))))
686 (target (if (eq type 'fuzzy)
687 (org-export-resolve-fuzzy-link link info)
688 (org-export-resolve-id-link link info))))
689 ;; Now use user-defined label provided in TARGET
690 ;; headline, or fallback to standard one.
691 (format "{%s}" (org-beamer--get-label target info)))))))
692 ;; Case 2: Creation of an appendix is requested.
693 ((equal environment "appendix")
694 (concat "\\appendix"
695 (org-element-property :BEAMER_ACT headline)
696 "\n"
697 (make-string (org-element-property :pre-blank headline) ?\n)
698 contents))
699 ;; Case 3: Ignore heading.
700 ((equal environment "ignoreheading")
701 (concat (make-string (org-element-property :pre-blank headline) ?\n)
702 contents))
703 ;; Case 4: HEADLINE is a note.
704 ((member environment '("note" "noteNH"))
705 (format "\\note{%s}"
706 (concat (and (equal environment "note")
707 (concat
708 (org-export-data
709 (org-element-property :title headline) info)
710 "\n"))
711 (org-trim contents))))
712 ;; Case 5: HEADLINE is a frame.
713 ((= level frame-level)
714 (org-beamer--format-frame headline contents info))
715 ;; Case 6: Regular section, extracted from
716 ;; `org-latex-classes'.
717 ((< level frame-level)
718 (org-beamer--format-section headline contents info))
719 ;; Case 7: Otherwise, HEADLINE is a block.
720 (t (org-beamer--format-block headline contents info))))))
723 ;;;; Item
725 (defun org-beamer-item (item contents info)
726 "Transcode an ITEM element into Beamer code.
727 CONTENTS holds the contents of the item. INFO is a plist holding
728 contextual information."
729 (let ((action (let ((first-element (car (org-element-contents item))))
730 (and (eq (org-element-type first-element) 'paragraph)
731 (org-beamer--element-has-overlay-p first-element))))
732 (output (org-export-with-backend 'latex item contents info)))
733 (if (not action) output
734 ;; If the item starts with a paragraph and that paragraph starts
735 ;; with an export snippet specifying an overlay, insert it after
736 ;; \item command.
737 (replace-regexp-in-string "\\\\item" (concat "\\\\item" action) output))))
740 ;;;; Keyword
742 (defun org-beamer-keyword (keyword contents info)
743 "Transcode a KEYWORD element into Beamer code.
744 CONTENTS is nil. INFO is a plist used as a communication
745 channel."
746 (let ((key (org-element-property :key keyword))
747 (value (org-element-property :value keyword)))
748 ;; Handle specifically BEAMER and TOC (headlines only) keywords.
749 ;; Otherwise, fallback to `latex' back-end.
750 (cond
751 ((equal key "BEAMER") value)
752 ((and (equal key "TOC") (string-match "\\<headlines\\>" value))
753 (let ((depth (or (and (string-match "[0-9]+" value)
754 (string-to-number (match-string 0 value)))
755 (plist-get info :with-toc)))
756 (options (and (string-match "\\[.*?\\]" value)
757 (match-string 0 value))))
758 (concat
759 (when (wholenump depth) (format "\\setcounter{tocdepth}{%s}\n" depth))
760 "\\tableofcontents" options)))
761 (t (org-export-with-backend 'latex keyword contents info)))))
764 ;;;; Link
766 (defun org-beamer-link (link contents info)
767 "Transcode a LINK object into Beamer code.
768 CONTENTS is the description part of the link. INFO is a plist
769 used as a communication channel."
770 (let ((type (org-element-property :type link))
771 (path (org-element-property :path link)))
772 ;; Use \hyperlink command for all internal links.
773 (cond
774 ((equal type "radio")
775 (let ((destination (org-export-resolve-radio-link link info)))
776 (when destination
777 (format "\\hyperlink%s{%s}{%s}"
778 (or (org-beamer--element-has-overlay-p link) "")
779 (org-export-solidify-link-text path)
780 (org-export-data (org-element-contents destination) info)))))
781 ((and (member type '("custom-id" "fuzzy" "id"))
782 (let ((destination (if (string= type "fuzzy")
783 (org-export-resolve-fuzzy-link link info)
784 (org-export-resolve-id-link link info))))
785 (case (org-element-type destination)
786 (headline
787 (let ((label
788 (format "sec-%s"
789 (mapconcat
790 'number-to-string
791 (org-export-get-headline-number
792 destination info)
793 "-"))))
794 (if (and (plist-get info :section-numbers) (not contents))
795 (format "\\ref{%s}" label)
796 (format "\\hyperlink%s{%s}{%s}"
797 (or (org-beamer--element-has-overlay-p link) "")
798 label
799 contents))))
800 (target
801 (let ((path (org-export-solidify-link-text path)))
802 (if (not contents) (format "\\ref{%s}" path)
803 (format "\\hyperlink%s{%s}{%s}"
804 (or (org-beamer--element-has-overlay-p link) "")
805 path
806 contents))))))))
807 ;; Otherwise, use `latex' back-end.
808 (t (org-export-with-backend 'latex link contents info)))))
811 ;;;; Plain List
813 ;; Plain lists support `:environment', `:overlay' and `:options'
814 ;; attributes.
816 (defun org-beamer-plain-list (plain-list contents info)
817 "Transcode a PLAIN-LIST element into Beamer code.
818 CONTENTS is the contents of the list. INFO is a plist holding
819 contextual information."
820 (let* ((type (org-element-property :type plain-list))
821 (attributes (org-combine-plists
822 (org-export-read-attribute :attr_latex plain-list)
823 (org-export-read-attribute :attr_beamer plain-list)))
824 (latex-type (let ((env (plist-get attributes :environment)))
825 (cond (env)
826 ((eq type 'ordered) "enumerate")
827 ((eq type 'descriptive) "description")
828 (t "itemize")))))
829 (org-latex--wrap-label
830 plain-list
831 (format "\\begin{%s}%s%s\n%s\\end{%s}"
832 latex-type
833 ;; Default overlay specification, if any.
834 (org-beamer--normalize-argument
835 (or (plist-get attributes :overlay) "")
836 'defaction)
837 ;; Second optional argument depends on the list type.
838 (org-beamer--normalize-argument
839 (or (plist-get attributes :options) "")
840 'option)
841 ;; Eventually insert contents and close environment.
842 contents
843 latex-type))))
846 ;;;; Radio Target
848 (defun org-beamer-radio-target (radio-target text info)
849 "Transcode a RADIO-TARGET object into Beamer code.
850 TEXT is the text of the target. INFO is a plist holding
851 contextual information."
852 (format "\\hypertarget%s{%s}{%s}"
853 (or (org-beamer--element-has-overlay-p radio-target) "")
854 (org-export-solidify-link-text
855 (org-element-property :value radio-target))
856 text))
859 ;;;; Target
861 (defun org-beamer-target (target contents info)
862 "Transcode a TARGET object into Beamer code.
863 CONTENTS is nil. INFO is a plist holding contextual
864 information."
865 (format "\\hypertarget{%s}{}"
866 (org-export-solidify-link-text (org-element-property :value target))))
869 ;;;; Template
871 ;; Template used is similar to the one used in `latex' back-end,
872 ;; excepted for the table of contents and Beamer themes.
874 (defun org-beamer-template (contents info)
875 "Return complete document string after Beamer conversion.
876 CONTENTS is the transcoded contents string. INFO is a plist
877 holding export options."
878 (let ((title (org-export-data (plist-get info :title) info)))
879 (concat
880 ;; 1. Time-stamp.
881 (and (plist-get info :time-stamp-file)
882 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
883 ;; 2. Document class and packages.
884 (let* ((class (plist-get info :latex-class))
885 (class-options (plist-get info :latex-class-options))
886 (header (nth 1 (assoc class org-latex-classes)))
887 (document-class-string
888 (and (stringp header)
889 (if (not class-options) header
890 (replace-regexp-in-string
891 "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
892 class-options header t nil 1)))))
893 (if (not document-class-string)
894 (user-error "Unknown LaTeX class `%s'" class)
895 (org-latex-guess-babel-language
896 (org-latex-guess-inputenc
897 (org-element-normalize-string
898 (org-splice-latex-header
899 document-class-string
900 org-latex-default-packages-alist
901 org-latex-packages-alist nil
902 (concat (org-element-normalize-string
903 (plist-get info :latex-header))
904 (org-element-normalize-string
905 (plist-get info :latex-header-extra))
906 (plist-get info :beamer-header-extra)))))
907 info)))
908 ;; 3. Insert themes.
909 (let ((format-theme
910 (function
911 (lambda (prop command)
912 (let ((theme (plist-get info prop)))
913 (when theme
914 (concat command
915 (if (not (string-match "\\[.*\\]" theme))
916 (format "{%s}\n" theme)
917 (format "%s{%s}\n"
918 (match-string 0 theme)
919 (org-trim
920 (replace-match "" nil nil theme)))))))))))
921 (mapconcat (lambda (args) (apply format-theme args))
922 '((:beamer-theme "\\usetheme")
923 (:beamer-color-theme "\\usecolortheme")
924 (:beamer-font-theme "\\usefonttheme")
925 (:beamer-inner-theme "\\useinnertheme")
926 (:beamer-outer-theme "\\useoutertheme"))
927 ""))
928 ;; 4. Possibly limit depth for headline numbering.
929 (let ((sec-num (plist-get info :section-numbers)))
930 (when (integerp sec-num)
931 (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
932 ;; 5. Author.
933 (let ((author (and (plist-get info :with-author)
934 (let ((auth (plist-get info :author)))
935 (and auth (org-export-data auth info)))))
936 (email (and (plist-get info :with-email)
937 (org-export-data (plist-get info :email) info))))
938 (cond ((and author email (not (string= "" email)))
939 (format "\\author{%s\\thanks{%s}}\n" author email))
940 (author (format "\\author{%s}\n" author))
941 (t "\\author{}\n")))
942 ;; 6. Date.
943 (let ((date (and (plist-get info :with-date) (org-export-get-date info))))
944 (format "\\date{%s}\n" (org-export-data date info)))
945 ;; 7. Title
946 (format "\\title{%s}\n" title)
947 ;; 8. Hyperref options.
948 (when (plist-get info :latex-hyperref-p)
949 (format "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={%s}}\n"
950 (or (plist-get info :keywords) "")
951 (or (plist-get info :description) "")
952 (if (not (plist-get info :with-creator)) ""
953 (plist-get info :creator))))
954 ;; 9. Document start.
955 "\\begin{document}\n\n"
956 ;; 10. Title command.
957 (org-element-normalize-string
958 (cond ((string= "" title) nil)
959 ((not (stringp org-latex-title-command)) nil)
960 ((string-match "\\(?:[^%]\\|^\\)%s"
961 org-latex-title-command)
962 (format org-latex-title-command title))
963 (t org-latex-title-command)))
964 ;; 11. Table of contents.
965 (let ((depth (plist-get info :with-toc)))
966 (when depth
967 (concat
968 (format "\\begin{frame}%s{%s}\n"
969 (org-beamer--normalize-argument
970 org-beamer-outline-frame-options 'option)
971 org-beamer-outline-frame-title)
972 (when (wholenump depth)
973 (format "\\setcounter{tocdepth}{%d}\n" depth))
974 "\\tableofcontents\n"
975 "\\end{frame}\n\n")))
976 ;; 12. Document's body.
977 contents
978 ;; 13. Creator.
979 (let ((creator-info (plist-get info :with-creator)))
980 (cond
981 ((not creator-info) "")
982 ((eq creator-info 'comment)
983 (format "%% %s\n" (plist-get info :creator)))
984 (t (concat (plist-get info :creator) "\n"))))
985 ;; 14. Document end.
986 "\\end{document}")))
990 ;;; Minor Mode
993 (defvar org-beamer-mode-map (make-sparse-keymap)
994 "The keymap for `org-beamer-mode'.")
995 (define-key org-beamer-mode-map "\C-c\C-b" 'org-beamer-select-environment)
997 ;;;###autoload
998 (define-minor-mode org-beamer-mode
999 "Support for editing Beamer oriented Org mode files."
1000 nil " Bm" 'org-beamer-mode-map)
1002 (when (fboundp 'font-lock-add-keywords)
1003 (font-lock-add-keywords
1004 'org-mode
1005 '((":\\(B_[a-z]+\\|BMCOL\\):" 1 'org-beamer-tag prepend))
1006 'prepend))
1008 (defface org-beamer-tag '((t (:box (:line-width 1 :color grey40))))
1009 "The special face for beamer tags."
1010 :group 'org-export-beamer)
1012 (defun org-beamer-property-changed (property value)
1013 "Track the BEAMER_env property with tags.
1014 PROPERTY is the name of the modified property. VALUE is its new
1015 value."
1016 (cond
1017 ((equal property "BEAMER_env")
1018 (save-excursion
1019 (org-back-to-heading t)
1020 ;; Filter out Beamer-related tags and install environment tag.
1021 (let ((tags (org-remove-if (lambda (x) (string-match "^B_" x))
1022 (org-get-tags)))
1023 (env-tag (and (org-string-nw-p value) (concat "B_" value))))
1024 (org-set-tags-to (if env-tag (cons env-tag tags) tags))
1025 (when env-tag (org-toggle-tag env-tag 'on)))))
1026 ((equal property "BEAMER_col")
1027 (org-toggle-tag "BMCOL" (if (org-string-nw-p value) 'on 'off)))))
1029 (add-hook 'org-property-changed-functions 'org-beamer-property-changed)
1031 (defun org-beamer-allowed-property-values (property)
1032 "Supply allowed values for PROPERTY."
1033 (cond
1034 ((and (equal property "BEAMER_env")
1035 (not (org-entry-get nil (concat property "_ALL") 'inherit)))
1036 ;; If no allowed values for BEAMER_env have been defined,
1037 ;; supply all defined environments
1038 (mapcar 'car (append org-beamer-environments-special
1039 org-beamer-environments-extra
1040 org-beamer-environments-default)))
1041 ((and (equal property "BEAMER_col")
1042 (not (org-entry-get nil (concat property "_ALL") 'inherit)))
1043 ;; If no allowed values for BEAMER_col have been defined,
1044 ;; supply some
1045 (org-split-string org-beamer-column-widths " "))))
1047 (add-hook 'org-property-allowed-value-functions
1048 'org-beamer-allowed-property-values)
1052 ;;; Commands
1054 ;;;###autoload
1055 (defun org-beamer-export-as-latex
1056 (&optional async subtreep visible-only body-only ext-plist)
1057 "Export current buffer as a Beamer buffer.
1059 If narrowing is active in the current buffer, only export its
1060 narrowed part.
1062 If a region is active, export that region.
1064 A non-nil optional argument ASYNC means the process should happen
1065 asynchronously. The resulting buffer should be accessible
1066 through the `org-export-stack' interface.
1068 When optional argument SUBTREEP is non-nil, export the sub-tree
1069 at point, extracting information from the headline properties
1070 first.
1072 When optional argument VISIBLE-ONLY is non-nil, don't export
1073 contents of hidden elements.
1075 When optional argument BODY-ONLY is non-nil, only write code
1076 between \"\\begin{document}\" and \"\\end{document}\".
1078 EXT-PLIST, when provided, is a property list with external
1079 parameters overriding Org default settings, but still inferior to
1080 file-local settings.
1082 Export is done in a buffer named \"*Org BEAMER Export*\", which
1083 will be displayed when `org-export-show-temporary-export-buffer'
1084 is non-nil."
1085 (interactive)
1086 (org-export-to-buffer 'beamer "*Org BEAMER Export*"
1087 async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
1089 ;;;###autoload
1090 (defun org-beamer-export-to-latex
1091 (&optional async subtreep visible-only body-only ext-plist)
1092 "Export current buffer as a Beamer presentation (tex).
1094 If narrowing is active in the current buffer, only export its
1095 narrowed part.
1097 If a region is active, export that region.
1099 A non-nil optional argument ASYNC means the process should happen
1100 asynchronously. The resulting file should be accessible through
1101 the `org-export-stack' interface.
1103 When optional argument SUBTREEP is non-nil, export the sub-tree
1104 at point, extracting information from the headline properties
1105 first.
1107 When optional argument VISIBLE-ONLY is non-nil, don't export
1108 contents of hidden elements.
1110 When optional argument BODY-ONLY is non-nil, only write code
1111 between \"\\begin{document}\" and \"\\end{document}\".
1113 EXT-PLIST, when provided, is a property list with external
1114 parameters overriding Org default settings, but still inferior to
1115 file-local settings.
1117 Return output file's name."
1118 (interactive)
1119 (let ((file (org-export-output-file-name ".tex" subtreep)))
1120 (org-export-to-file 'beamer file
1121 async subtreep visible-only body-only ext-plist)))
1123 ;;;###autoload
1124 (defun org-beamer-export-to-pdf
1125 (&optional async subtreep visible-only body-only ext-plist)
1126 "Export current buffer as a Beamer presentation (PDF).
1128 If narrowing is active in the current buffer, only export its
1129 narrowed part.
1131 If a region is active, export that region.
1133 A non-nil optional argument ASYNC means the process should happen
1134 asynchronously. The resulting file should be accessible through
1135 the `org-export-stack' interface.
1137 When optional argument SUBTREEP is non-nil, export the sub-tree
1138 at point, extracting information from the headline properties
1139 first.
1141 When optional argument VISIBLE-ONLY is non-nil, don't export
1142 contents of hidden elements.
1144 When optional argument BODY-ONLY is non-nil, only write code
1145 between \"\\begin{document}\" and \"\\end{document}\".
1147 EXT-PLIST, when provided, is a property list with external
1148 parameters overriding Org default settings, but still inferior to
1149 file-local settings.
1151 Return PDF file's name."
1152 (interactive)
1153 (let ((file (org-export-output-file-name ".tex" subtreep)))
1154 (org-export-to-file 'beamer file
1155 async subtreep visible-only body-only ext-plist
1156 (lambda (file) (org-latex-compile file)))))
1158 ;;;###autoload
1159 (defun org-beamer-select-environment ()
1160 "Select the environment to be used by beamer for this entry.
1161 While this uses (for convenience) a tag selection interface, the
1162 result of this command will be that the BEAMER_env *property* of
1163 the entry is set.
1165 In addition to this, the command will also set a tag as a visual
1166 aid, but the tag does not have any semantic meaning."
1167 (interactive)
1168 ;; Make sure `org-beamer-environments-special' has a higher
1169 ;; priority than `org-beamer-environments-extra'.
1170 (let* ((envs (append org-beamer-environments-special
1171 org-beamer-environments-extra
1172 org-beamer-environments-default))
1173 (org-tag-alist
1174 (append '((:startgroup))
1175 (mapcar (lambda (e) (cons (concat "B_" (car e))
1176 (string-to-char (nth 1 e))))
1177 envs)
1178 '((:endgroup))
1179 '(("BMCOL" . ?|))))
1180 (org-fast-tag-selection-single-key t))
1181 (org-set-tags)
1182 (let ((tags (or (ignore-errors (org-get-tags-string)) "")))
1183 (cond
1184 ;; For a column, automatically ask for its width.
1185 ((eq org-last-tag-selection-key ?|)
1186 (if (string-match ":BMCOL:" tags)
1187 (org-set-property "BEAMER_col" (read-string "Column width: "))
1188 (org-delete-property "BEAMER_col")))
1189 ;; For an "againframe" section, automatically ask for reference
1190 ;; to resumed frame and overlay specifications.
1191 ((eq org-last-tag-selection-key ?A)
1192 (if (equal (org-entry-get nil "BEAMER_env") "againframe")
1193 (progn (org-entry-delete nil "BEAMER_env")
1194 (org-entry-delete nil "BEAMER_ref")
1195 (org-entry-delete nil "BEAMER_act"))
1196 (org-entry-put nil "BEAMER_env" "againframe")
1197 (org-set-property
1198 "BEAMER_ref"
1199 (read-string "Frame reference (*Title, #custom-id, id:...): "))
1200 (org-set-property "BEAMER_act"
1201 (read-string "Overlay specification: "))))
1202 ((string-match (concat ":B_\\(" (mapconcat 'car envs "\\|") "\\):") tags)
1203 (org-entry-put nil "BEAMER_env" (match-string 1 tags)))
1204 (t (org-entry-delete nil "BEAMER_env"))))))
1206 ;;;###autoload
1207 (defun org-beamer-insert-options-template (&optional kind)
1208 "Insert a settings template, to make sure users do this right."
1209 (interactive (progn
1210 (message "Current [s]ubtree or [g]lobal?")
1211 (if (eq (read-char-exclusive) ?g) (list 'global)
1212 (list 'subtree))))
1213 (if (eq kind 'subtree)
1214 (progn
1215 (org-back-to-heading t)
1216 (org-reveal)
1217 (org-entry-put nil "EXPORT_LaTeX_CLASS" "beamer")
1218 (org-entry-put nil "EXPORT_LaTeX_CLASS_OPTIONS" "[presentation]")
1219 (org-entry-put nil "EXPORT_FILE_NAME" "presentation.pdf")
1220 (when org-beamer-column-view-format
1221 (org-entry-put nil "COLUMNS" org-beamer-column-view-format))
1222 (org-entry-put nil "BEAMER_col_ALL" org-beamer-column-widths))
1223 (insert "#+LaTeX_CLASS: beamer\n")
1224 (insert "#+LaTeX_CLASS_OPTIONS: [presentation]\n")
1225 (when org-beamer-theme (insert "#+BEAMER_THEME: " org-beamer-theme "\n"))
1226 (when org-beamer-column-view-format
1227 (insert "#+COLUMNS: " org-beamer-column-view-format "\n"))
1228 (insert "#+PROPERTY: BEAMER_col_ALL " org-beamer-column-widths "\n")))
1230 ;;;###autoload
1231 (defun org-beamer-publish-to-latex (plist filename pub-dir)
1232 "Publish an Org file to a Beamer presentation (LaTeX).
1234 FILENAME is the filename of the Org file to be published. PLIST
1235 is the property list for the given project. PUB-DIR is the
1236 publishing directory.
1238 Return output file name."
1239 (org-publish-org-to 'beamer filename ".tex" plist pub-dir))
1241 ;;;###autoload
1242 (defun org-beamer-publish-to-pdf (plist filename pub-dir)
1243 "Publish an Org file to a Beamer presentation (PDF, via LaTeX).
1245 FILENAME is the filename of the Org file to be published. PLIST
1246 is the property list for the given project. PUB-DIR is the
1247 publishing directory.
1249 Return output file name."
1250 ;; Unlike to `org-beamer-publish-to-latex', PDF file is generated in
1251 ;; working directory and then moved to publishing directory.
1252 (org-publish-attachment
1253 plist
1254 (org-latex-compile (org-publish-org-to 'beamer filename ".tex" plist))
1255 pub-dir))
1258 (provide 'ox-beamer)
1260 ;; Local variables:
1261 ;; generated-autoload-file: "org-loaddefs.el"
1262 ;; End:
1264 ;;; ox-beamer.el ends here