org-pcomplete: Fix completion for block boundaries
[org-mode.git] / lisp / ox-beamer.el
blobb6e0f3a688d1b7cf126983fb4ca1a8fa54f226c6
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 %H if there is headline text, that text in {} braces
198 %U if there is headline text, that text in [] brackets
199 close The closing string of the environment."
200 :group 'org-export-beamer
201 :version "24.4"
202 :package-version '(Org . "8.0")
203 :type '(repeat
204 (list
205 (string :tag "Environment")
206 (string :tag "Selection key")
207 (string :tag "Begin")
208 (string :tag "End"))))
210 (defcustom org-beamer-outline-frame-title "Outline"
211 "Default title of a frame containing an outline."
212 :group 'org-export-beamer
213 :type '(string :tag "Outline frame title"))
215 (defcustom org-beamer-outline-frame-options ""
216 "Outline frame options appended after \\begin{frame}.
217 You might want to put e.g. \"allowframebreaks=0.9\" here."
218 :group 'org-export-beamer
219 :type '(string :tag "Outline frame options"))
223 ;;; Internal Variables
225 (defconst org-beamer-column-widths
226 "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.0 :ETC"
227 "The column widths that should be installed as allowed property values.")
229 (defconst org-beamer-environments-special
230 '(("againframe" "A")
231 ("appendix" "x")
232 ("column" "c")
233 ("columns" "C")
234 ("frame" "f")
235 ("fullframe" "F")
236 ("ignoreheading" "i")
237 ("note" "n")
238 ("noteNH" "N"))
239 "Alist of environments treated in a special way by the back-end.
240 Keys are environment names, as strings, values are bindings used
241 in `org-beamer-select-environment'. Environments listed here,
242 along with their binding, are hard coded and cannot be modified
243 through `org-beamer-environments-extra' variable.")
245 (defconst org-beamer-environments-default
246 '(("block" "b" "\\begin{block}%a{%h}" "\\end{block}")
247 ("alertblock" "a" "\\begin{alertblock}%a{%h}" "\\end{alertblock}")
248 ("verse" "v" "\\begin{verse}%a %% %h" "\\end{verse}")
249 ("quotation" "q" "\\begin{quotation}%a %% %h" "\\end{quotation}")
250 ("quote" "Q" "\\begin{quote}%a %% %h" "\\end{quote}")
251 ("structureenv" "s" "\\begin{structureenv}%a %% %h" "\\end{structureenv}")
252 ("theorem" "t" "\\begin{theorem}%a%U" "\\end{theorem}")
253 ("definition" "d" "\\begin{definition}%a%U" "\\end{definition}")
254 ("example" "e" "\\begin{example}%a%U" "\\end{example}")
255 ("exampleblock" "E" "\\begin{exampleblock}%a{%h}" "\\end{exampleblock}")
256 ("proof" "p" "\\begin{proof}%a%U" "\\end{proof}")
257 ("beamercolorbox" "o" "\\begin{beamercolorbox}%o{%h}" "\\end{beamercolorbox}"))
258 "Environments triggered by properties in Beamer export.
259 These are the defaults - for user definitions, see
260 `org-beamer-environments-extra'.")
262 (defconst org-beamer-verbatim-elements
263 '(code example-block fixed-width inline-src-block src-block verbatim)
264 "List of element or object types producing verbatim text.
265 This is used internally to determine when a frame should have the
266 \"fragile\" option.")
270 ;;; Internal functions
272 (defun org-beamer--normalize-argument (argument type)
273 "Return ARGUMENT string with proper boundaries.
275 TYPE is a symbol among the following:
276 `action' Return ARGUMENT within angular brackets.
277 `defaction' Return ARGUMENT within both square and angular brackets.
278 `option' Return ARGUMENT within square brackets."
279 (if (not (string-match "\\S-" argument)) ""
280 (case type
281 (action (if (string-match "\\`<.*>\\'" argument) argument
282 (format "<%s>" argument)))
283 (defaction (cond
284 ((string-match "\\`\\[<.*>\\]\\'" argument) argument)
285 ((string-match "\\`<.*>\\'" argument)
286 (format "[%s]" argument))
287 ((string-match "\\`\\[\\(.*\\)\\]\\'" argument)
288 (format "[<%s>]" (match-string 1 argument)))
289 (t (format "[<%s>]" argument))))
290 (option (if (string-match "\\`\\[.*\\]\\'" argument) argument
291 (format "[%s]" argument)))
292 (otherwise argument))))
294 (defun org-beamer--element-has-overlay-p (element)
295 "Non-nil when ELEMENT has an overlay specified.
296 An element has an overlay specification when it starts with an
297 `beamer' export-snippet whose value is between angular brackets.
298 Return overlay specification, as a string, or nil."
299 (let ((first-object (car (org-element-contents element))))
300 (when (eq (org-element-type first-object) 'export-snippet)
301 (let ((value (org-element-property :value first-object)))
302 (and (string-match "\\`<.*>\\'" value) value)))))
306 ;;; Define Back-End
308 (org-export-define-derived-backend 'beamer 'latex
309 :export-block "BEAMER"
310 :menu-entry
311 '(?l 1
312 ((?B "As LaTeX buffer (Beamer)" org-beamer-export-as-latex)
313 (?b "As LaTeX file (Beamer)" org-beamer-export-to-latex)
314 (?P "As PDF file (Beamer)" org-beamer-export-to-pdf)
315 (?O "As PDF file and open (Beamer)"
316 (lambda (a s v b)
317 (if a (org-beamer-export-to-pdf t s v b)
318 (org-open-file (org-beamer-export-to-pdf nil s v b)))))))
319 :options-alist
320 '((:beamer-theme "BEAMER_THEME" nil org-beamer-theme)
321 (:beamer-color-theme "BEAMER_COLOR_THEME" nil nil t)
322 (:beamer-font-theme "BEAMER_FONT_THEME" nil nil t)
323 (:beamer-inner-theme "BEAMER_INNER_THEME" nil nil t)
324 (:beamer-outer-theme "BEAMER_OUTER_THEME" nil nil t)
325 (:beamer-header-extra "BEAMER_HEADER" nil nil newline)
326 ;; Modify existing properties.
327 (:headline-levels nil "H" org-beamer-frame-level)
328 (:latex-class "LATEX_CLASS" nil "beamer" t))
329 :translate-alist '((bold . org-beamer-bold)
330 (export-block . org-beamer-export-block)
331 (export-snippet . org-beamer-export-snippet)
332 (headline . org-beamer-headline)
333 (item . org-beamer-item)
334 (keyword . org-beamer-keyword)
335 (link . org-beamer-link)
336 (plain-list . org-beamer-plain-list)
337 (radio-target . org-beamer-radio-target)
338 (target . org-beamer-target)
339 (template . org-beamer-template)))
343 ;;; Transcode Functions
345 ;;;; Bold
347 (defun org-beamer-bold (bold contents info)
348 "Transcode BLOCK object into Beamer code.
349 CONTENTS is the text being bold. INFO is a plist used as
350 a communication channel."
351 (format "\\alert%s{%s}"
352 (or (org-beamer--element-has-overlay-p bold) "")
353 contents))
356 ;;;; Export Block
358 (defun org-beamer-export-block (export-block contents info)
359 "Transcode an EXPORT-BLOCK element into Beamer code.
360 CONTENTS is nil. INFO is a plist used as a communication
361 channel."
362 (when (member (org-element-property :type export-block) '("BEAMER" "LATEX"))
363 (org-remove-indentation (org-element-property :value export-block))))
366 ;;;; Export Snippet
368 (defun org-beamer-export-snippet (export-snippet contents info)
369 "Transcode an EXPORT-SNIPPET object into Beamer code.
370 CONTENTS is nil. INFO is a plist used as a communication
371 channel."
372 (let ((backend (org-export-snippet-backend export-snippet))
373 (value (org-element-property :value export-snippet)))
374 ;; Only "latex" and "beamer" snippets are retained.
375 (cond ((eq backend 'latex) value)
376 ;; Ignore "beamer" snippets specifying overlays.
377 ((and (eq backend 'beamer)
378 (or (org-export-get-previous-element export-snippet info)
379 (not (string-match "\\`<.*>\\'" value))))
380 value))))
383 ;;;; Headline
385 ;; The main function to translate a headline is
386 ;; `org-beamer-headline'.
388 ;; Depending on the level at which a headline is considered as
389 ;; a frame (given by `org-beamer--frame-level'), the headline is
390 ;; either a section (`org-beamer--format-section'), a frame
391 ;; (`org-beamer--format-frame') or a block
392 ;; (`org-beamer--format-block').
394 ;; `org-beamer-headline' also takes care of special environments
395 ;; like "ignoreheading", "note", "noteNH", "appendix" and
396 ;; "againframe".
398 (defun org-beamer--get-label (headline info)
399 "Return label for HEADLINE, as a string.
401 INFO is a plist used as a communication channel.
403 The value is either the label specified in \"BEAMER_opt\"
404 property, or a fallback value built from headline's number. This
405 function assumes HEADLINE will be treated as a frame."
406 (let ((opt (org-element-property :BEAMER_OPT headline)))
407 (if (and (org-string-nw-p opt)
408 (string-match "\\(?:^\\|,\\)label=\\(.*?\\)\\(?:$\\|,\\)" opt))
409 (match-string 1 opt)
410 (format "sec-%s"
411 (mapconcat 'number-to-string
412 (org-export-get-headline-number headline info)
413 "-")))))
415 (defun org-beamer--frame-level (headline info)
416 "Return frame level in subtree containing HEADLINE.
417 INFO is a plist used as a communication channel."
419 ;; 1. Look for "frame" environment in parents, starting from the
420 ;; farthest.
421 (catch 'exit
422 (mapc (lambda (parent)
423 (let ((env (org-element-property :BEAMER_ENV parent)))
424 (when (and env (member-ignore-case env '("frame" "fullframe")))
425 (throw 'exit (org-export-get-relative-level parent info)))))
426 (nreverse (org-export-get-genealogy headline)))
427 nil)
428 ;; 2. Look for "frame" environment in HEADLINE.
429 (let ((env (org-element-property :BEAMER_ENV headline)))
430 (and env (member-ignore-case env '("frame" "fullframe"))
431 (org-export-get-relative-level headline info)))
432 ;; 3. Look for "frame" environment in sub-tree.
433 (org-element-map headline 'headline
434 (lambda (hl)
435 (let ((env (org-element-property :BEAMER_ENV hl)))
436 (when (and env (member-ignore-case env '("frame" "fullframe")))
437 (org-export-get-relative-level hl info))))
438 info 'first-match)
439 ;; 4. No "frame" environment in tree: use default value.
440 (plist-get info :headline-levels)))
442 (defun org-beamer--format-section (headline contents info)
443 "Format HEADLINE as a sectioning part.
444 CONTENTS holds the contents of the headline. INFO is a plist
445 used as a communication channel."
446 ;; Use `latex' back-end output, inserting overlay specifications
447 ;; if possible.
448 (let ((latex-headline (org-export-with-backend 'latex headline contents info))
449 (mode-specs (org-element-property :BEAMER_ACT headline)))
450 (if (and mode-specs
451 (string-match "\\`\\\\\\(.*?\\)\\(?:\\*\\|\\[.*\\]\\)?{"
452 latex-headline))
453 (replace-match (concat (match-string 1 latex-headline)
454 (format "<%s>" mode-specs))
455 nil nil latex-headline 1)
456 latex-headline)))
458 (defun org-beamer--format-frame (headline contents info)
459 "Format HEADLINE as a frame.
460 CONTENTS holds the contents of the headline. INFO is a plist
461 used as a communication channel."
462 (let ((fragilep
463 ;; FRAGILEP is non-nil when HEADLINE contains an element
464 ;; among `org-beamer-verbatim-elements'.
465 (org-element-map headline org-beamer-verbatim-elements 'identity
466 info 'first-match)))
467 (concat "\\begin{frame}"
468 ;; Overlay specification, if any. When surrounded by
469 ;; square brackets, consider it as a default
470 ;; specification.
471 (let ((action (org-element-property :BEAMER_ACT headline)))
472 (cond
473 ((not action) "")
474 ((string-match "\\`\\[.*\\]\\'" action )
475 (org-beamer--normalize-argument action 'defaction))
476 (t (org-beamer--normalize-argument action 'action))))
477 ;; Options, if any.
478 (let* ((beamer-opt (org-element-property :BEAMER_OPT headline))
479 (options
480 ;; Collect options from default value and headline's
481 ;; properties. Also add a label for links.
482 (append
483 (org-split-string org-beamer-frame-default-options ",")
484 (and beamer-opt
485 (org-split-string
486 ;; Remove square brackets if user provided
487 ;; them.
488 (and (string-match "^\\[?\\(.*\\)\\]?$" beamer-opt)
489 (match-string 1 beamer-opt))
490 ","))
491 ;; Provide an automatic label for the frame
492 ;; unless the user specified one.
493 (unless (and beamer-opt
494 (string-match "\\(^\\|,\\)label=" beamer-opt))
495 (list
496 (format "label=%s"
497 (org-beamer--get-label headline info)))))))
498 ;; Change options list into a string.
499 (org-beamer--normalize-argument
500 (mapconcat
501 'identity
502 (if (or (not fragilep) (member "fragile" options)) options
503 (cons "fragile" options))
504 ",")
505 'option))
506 ;; Title.
507 (let ((env (org-element-property :BEAMER_ENV headline)))
508 (format "{%s}"
509 (if (and env (equal (downcase env) "fullframe")) ""
510 (org-export-data
511 (org-element-property :title headline) info))))
512 "\n"
513 ;; The following workaround is required in fragile frames
514 ;; as Beamer will append "\par" to the beginning of the
515 ;; contents. So we need to make sure the command is
516 ;; separated from the contents by at least one space. If
517 ;; it isn't, it will create "\parfirst-word" command and
518 ;; remove the first word from the contents in the PDF
519 ;; output.
520 (if (not fragilep) contents
521 (replace-regexp-in-string "\\`\n*" "\\& " (or contents "")))
522 "\\end{frame}")))
524 (defun org-beamer--format-block (headline contents info)
525 "Format HEADLINE as a block.
526 CONTENTS holds the contents of the headline. INFO is a plist
527 used as a communication channel."
528 (let* ((column-width (org-element-property :BEAMER_COL headline))
529 ;; ENVIRONMENT defaults to "block" if none is specified and
530 ;; there is no column specification. If there is a column
531 ;; specified but still no explicit environment, ENVIRONMENT
532 ;; is "column".
533 (environment (let ((env (org-element-property :BEAMER_ENV headline)))
534 (cond
535 ;; "block" is the fallback environment.
536 ((and (not env) (not column-width)) "block")
537 ;; "column" only.
538 ((not env) "column")
539 ;; Use specified environment.
540 (t env))))
541 (env-format (unless (member environment '("column" "columns"))
542 (assoc environment
543 (append org-beamer-environments-special
544 org-beamer-environments-extra
545 org-beamer-environments-default))))
546 (title (org-export-data (org-element-property :title headline) info))
547 (options (let ((options (org-element-property :BEAMER_OPT headline)))
548 (if (not options) ""
549 (org-beamer--normalize-argument options 'option))))
550 ;; Start a "columns" environment when explicitly requested or
551 ;; when there is no previous headline or the previous
552 ;; headline do not have a BEAMER_column property.
553 (parent-env (org-element-property
554 :BEAMER_ENV (org-export-get-parent-headline headline)))
555 (start-columns-p
556 (or (equal environment "columns")
557 (and column-width
558 (not (and parent-env
559 (equal (downcase parent-env) "columns")))
560 (or (org-export-first-sibling-p headline info)
561 (not (org-element-property
562 :BEAMER_COL
563 (org-export-get-previous-element
564 headline info)))))))
565 ;; End the "columns" environment when explicitly requested or
566 ;; when there is no next headline or the next headline do not
567 ;; have a BEAMER_column property.
568 (end-columns-p
569 (or (equal environment "columns")
570 (and column-width
571 (not (and parent-env
572 (equal (downcase parent-env) "columns")))
573 (or (org-export-last-sibling-p headline info)
574 (not (org-element-property
575 :BEAMER_COL
576 (org-export-get-next-element headline info))))))))
577 (concat
578 (when start-columns-p
579 ;; Column can accept options only when the environment is
580 ;; explicitly defined.
581 (if (not (equal environment "columns")) "\\begin{columns}\n"
582 (format "\\begin{columns}%s\n" options)))
583 (when column-width
584 (format "\\begin{column}%s{%s}\n"
585 ;; One can specify placement for column only when
586 ;; HEADLINE stands for a column on its own.
587 (if (equal environment "column") options "")
588 (format "%s\\textwidth" column-width)))
589 ;; Block's opening string.
590 (when env-format
591 (concat
592 (org-fill-template
593 (nth 2 env-format)
594 (nconc
595 ;; If BEAMER_act property has its value enclosed in square
596 ;; brackets, it is a default overlay specification and
597 ;; overlay specification is empty. Otherwise, it is an
598 ;; overlay specification and the default one is nil.
599 (let ((action (org-element-property :BEAMER_ACT headline)))
600 (cond
601 ((not action) (list (cons "a" "") (cons "A" "")))
602 ((string-match "\\`\\[.*\\]\\'" action)
603 (list
604 (cons "A" (org-beamer--normalize-argument action 'defaction))
605 (cons "a" "")))
607 (list (cons "a" (org-beamer--normalize-argument action 'action))
608 (cons "A" "")))))
609 (list (cons "o" options)
610 (cons "h" title)
611 (cons "H" (if (equal title "") "" (format "{%s}" title)))
612 (cons "U" (if (equal title "") "" (format "[%s]" title))))))
613 "\n"))
614 contents
615 ;; Block's closing string.
616 (when environment (concat (nth 3 env-format) "\n"))
617 (when column-width "\\end{column}\n")
618 (when end-columns-p "\\end{columns}"))))
620 (defun org-beamer-headline (headline contents info)
621 "Transcode HEADLINE element into Beamer code.
622 CONTENTS is the contents of the headline. INFO is a plist used
623 as a communication channel."
624 (unless (org-element-property :footnote-section-p headline)
625 (let ((level (org-export-get-relative-level headline info))
626 (frame-level (org-beamer--frame-level headline info))
627 (environment (let ((env (org-element-property :BEAMER_ENV headline)))
628 (or (org-string-nw-p env) "block"))))
629 (cond
630 ;; Case 1: Resume frame specified by "BEAMER_ref" property.
631 ((equal environment "againframe")
632 (let ((ref (org-element-property :BEAMER_REF headline)))
633 ;; Reference to frame being resumed is mandatory. Ignore
634 ;; the whole headline if it isn't provided.
635 (when (org-string-nw-p ref)
636 (concat "\\againframe"
637 ;; Overlay specification.
638 (let ((overlay (org-element-property :BEAMER_ACT headline)))
639 (when overlay
640 (org-beamer--normalize-argument
641 overlay
642 (if (string-match "^\\[.*\\]$" overlay) 'defaction
643 'action))))
644 ;; Options.
645 (let ((options (org-element-property :BEAMER_OPT headline)))
646 (when options
647 (org-beamer--normalize-argument options 'option)))
648 ;; Resolve reference provided by "BEAMER_ref"
649 ;; property. This is done by building a minimal fake
650 ;; link and calling the appropriate resolve function,
651 ;; depending on the reference syntax.
652 (let* ((type
653 (progn
654 (string-match "^\\(id:\\|#\\|\\*\\)?\\(.*\\)" ref)
655 (cond
656 ((or (not (match-string 1 ref))
657 (equal (match-string 1 ref) "*")) 'fuzzy)
658 ((equal (match-string 1 ref) "id:") 'id)
659 (t 'custom-id))))
660 (link (list 'link (list :path (match-string 2 ref))))
661 (target (if (eq type 'fuzzy)
662 (org-export-resolve-fuzzy-link link info)
663 (org-export-resolve-id-link link info))))
664 ;; Now use user-defined label provided in TARGET
665 ;; headline, or fallback to standard one.
666 (format "{%s}" (org-beamer--get-label target info)))))))
667 ;; Case 2: Creation of an appendix is requested.
668 ((equal environment "appendix")
669 (concat "\\appendix"
670 (org-element-property :BEAMER_ACT headline)
671 "\n"
672 (make-string (org-element-property :pre-blank headline) ?\n)
673 contents))
674 ;; Case 3: Ignore heading.
675 ((equal environment "ignoreheading")
676 (concat (make-string (org-element-property :pre-blank headline) ?\n)
677 contents))
678 ;; Case 4: HEADLINE is a note.
679 ((member environment '("note" "noteNH"))
680 (format "\\note{%s}"
681 (concat (and (equal environment "note")
682 (concat
683 (org-export-data
684 (org-element-property :title headline) info)
685 "\n"))
686 (org-trim contents))))
687 ;; Case 5: HEADLINE is a frame.
688 ((= level frame-level)
689 (org-beamer--format-frame headline contents info))
690 ;; Case 6: Regular section, extracted from
691 ;; `org-latex-classes'.
692 ((< level frame-level)
693 (org-beamer--format-section headline contents info))
694 ;; Case 7: Otherwise, HEADLINE is a block.
695 (t (org-beamer--format-block headline contents info))))))
698 ;;;; Item
700 (defun org-beamer-item (item contents info)
701 "Transcode an ITEM element into Beamer code.
702 CONTENTS holds the contents of the item. INFO is a plist holding
703 contextual information."
704 (let ((action (let ((first-element (car (org-element-contents item))))
705 (and (eq (org-element-type first-element) 'paragraph)
706 (org-beamer--element-has-overlay-p first-element))))
707 (output (org-export-with-backend 'latex item contents info)))
708 (if (not action) output
709 ;; If the item starts with a paragraph and that paragraph starts
710 ;; with an export snippet specifying an overlay, insert it after
711 ;; \item command.
712 (replace-regexp-in-string "\\\\item" (concat "\\\\item" action) output))))
715 ;;;; Keyword
717 (defun org-beamer-keyword (keyword contents info)
718 "Transcode a KEYWORD element into Beamer code.
719 CONTENTS is nil. INFO is a plist used as a communication
720 channel."
721 (let ((key (org-element-property :key keyword))
722 (value (org-element-property :value keyword)))
723 ;; Handle specifically BEAMER and TOC (headlines only) keywords.
724 ;; Otherwise, fallback to `latex' back-end.
725 (cond
726 ((equal key "BEAMER") value)
727 ((and (equal key "TOC") (string-match "\\<headlines\\>" value))
728 (let ((depth (or (and (string-match "[0-9]+" value)
729 (string-to-number (match-string 0 value)))
730 (plist-get info :with-toc)))
731 (options (and (string-match "\\[.*?\\]" value)
732 (match-string 0 value))))
733 (concat
734 (when (wholenump depth) (format "\\setcounter{tocdepth}{%s}\n" depth))
735 "\\tableofcontents" options)))
736 (t (org-export-with-backend 'latex keyword contents info)))))
739 ;;;; Link
741 (defun org-beamer-link (link contents info)
742 "Transcode a LINK object into Beamer code.
743 CONTENTS is the description part of the link. INFO is a plist
744 used as a communication channel."
745 (let ((type (org-element-property :type link))
746 (path (org-element-property :path link)))
747 ;; Use \hyperlink command for all internal links.
748 (cond
749 ((equal type "radio")
750 (let ((destination (org-export-resolve-radio-link link info)))
751 (when destination
752 (format "\\hyperlink%s{%s}{%s}"
753 (or (org-beamer--element-has-overlay-p link) "")
754 (org-export-solidify-link-text path)
755 (org-export-data (org-element-contents destination) info)))))
756 ((and (member type '("custom-id" "fuzzy" "id"))
757 (let ((destination (if (string= type "fuzzy")
758 (org-export-resolve-fuzzy-link link info)
759 (org-export-resolve-id-link link info))))
760 (case (org-element-type destination)
761 (headline
762 (let ((label
763 (format "sec-%s"
764 (mapconcat
765 'number-to-string
766 (org-export-get-headline-number
767 destination info)
768 "-"))))
769 (if (and (plist-get info :section-numbers) (not contents))
770 (format "\\ref{%s}" label)
771 (format "\\hyperlink%s{%s}{%s}"
772 (or (org-beamer--element-has-overlay-p link) "")
773 label
774 contents))))
775 (target
776 (let ((path (org-export-solidify-link-text path)))
777 (if (not contents) (format "\\ref{%s}" path)
778 (format "\\hyperlink%s{%s}{%s}"
779 (or (org-beamer--element-has-overlay-p link) "")
780 path
781 contents))))))))
782 ;; Otherwise, use `latex' back-end.
783 (t (org-export-with-backend 'latex link contents info)))))
786 ;;;; Plain List
788 ;; Plain lists support `:environment', `:overlay' and `:options'
789 ;; attributes.
791 (defun org-beamer-plain-list (plain-list contents info)
792 "Transcode a PLAIN-LIST element into Beamer code.
793 CONTENTS is the contents of the list. INFO is a plist holding
794 contextual information."
795 (let* ((type (org-element-property :type plain-list))
796 (attributes (org-combine-plists
797 (org-export-read-attribute :attr_latex plain-list)
798 (org-export-read-attribute :attr_beamer plain-list)))
799 (latex-type (let ((env (plist-get attributes :environment)))
800 (cond (env)
801 ((eq type 'ordered) "enumerate")
802 ((eq type 'descriptive) "description")
803 (t "itemize")))))
804 (org-latex--wrap-label
805 plain-list
806 (format "\\begin{%s}%s%s\n%s\\end{%s}"
807 latex-type
808 ;; Default overlay specification, if any.
809 (org-beamer--normalize-argument
810 (or (plist-get attributes :overlay) "")
811 'defaction)
812 ;; Second optional argument depends on the list type.
813 (org-beamer--normalize-argument
814 (or (plist-get attributes :options) "")
815 'option)
816 ;; Eventually insert contents and close environment.
817 contents
818 latex-type))))
821 ;;;; Radio Target
823 (defun org-beamer-radio-target (radio-target text info)
824 "Transcode a RADIO-TARGET object into Beamer code.
825 TEXT is the text of the target. INFO is a plist holding
826 contextual information."
827 (format "\\hypertarget%s{%s}{%s}"
828 (or (org-beamer--element-has-overlay-p radio-target) "")
829 (org-export-solidify-link-text
830 (org-element-property :value radio-target))
831 text))
834 ;;;; Target
836 (defun org-beamer-target (target contents info)
837 "Transcode a TARGET object into Beamer code.
838 CONTENTS is nil. INFO is a plist holding contextual
839 information."
840 (format "\\hypertarget{%s}{}"
841 (org-export-solidify-link-text (org-element-property :value target))))
844 ;;;; Template
846 ;; Template used is similar to the one used in `latex' back-end,
847 ;; excepted for the table of contents and Beamer themes.
849 (defun org-beamer-template (contents info)
850 "Return complete document string after Beamer conversion.
851 CONTENTS is the transcoded contents string. INFO is a plist
852 holding export options."
853 (let ((title (org-export-data (plist-get info :title) info)))
854 (concat
855 ;; 1. Time-stamp.
856 (and (plist-get info :time-stamp-file)
857 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
858 ;; 2. Document class and packages.
859 (let* ((class (plist-get info :latex-class))
860 (class-options (plist-get info :latex-class-options))
861 (header (nth 1 (assoc class org-latex-classes)))
862 (document-class-string
863 (and (stringp header)
864 (if (not class-options) header
865 (replace-regexp-in-string
866 "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
867 class-options header t nil 1)))))
868 (if (not document-class-string)
869 (user-error "Unknown LaTeX class `%s'" class)
870 (org-latex-guess-babel-language
871 (org-latex-guess-inputenc
872 (org-element-normalize-string
873 (org-splice-latex-header
874 document-class-string
875 org-latex-default-packages-alist
876 org-latex-packages-alist nil
877 (concat (org-element-normalize-string
878 (plist-get info :latex-header))
879 (org-element-normalize-string
880 (plist-get info :latex-header-extra))
881 (plist-get info :beamer-header-extra)))))
882 info)))
883 ;; 3. Insert themes.
884 (let ((format-theme
885 (function
886 (lambda (prop command)
887 (let ((theme (plist-get info prop)))
888 (when theme
889 (concat command
890 (if (not (string-match "\\[.*\\]" theme))
891 (format "{%s}\n" theme)
892 (format "%s{%s}\n"
893 (match-string 0 theme)
894 (org-trim
895 (replace-match "" nil nil theme)))))))))))
896 (mapconcat (lambda (args) (apply format-theme args))
897 '((:beamer-theme "\\usetheme")
898 (:beamer-color-theme "\\usecolortheme")
899 (:beamer-font-theme "\\usefonttheme")
900 (:beamer-inner-theme "\\useinnertheme")
901 (:beamer-outer-theme "\\useoutertheme"))
902 ""))
903 ;; 4. Possibly limit depth for headline numbering.
904 (let ((sec-num (plist-get info :section-numbers)))
905 (when (integerp sec-num)
906 (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
907 ;; 5. Author.
908 (let ((author (and (plist-get info :with-author)
909 (let ((auth (plist-get info :author)))
910 (and auth (org-export-data auth info)))))
911 (email (and (plist-get info :with-email)
912 (org-export-data (plist-get info :email) info))))
913 (cond ((and author email (not (string= "" email)))
914 (format "\\author{%s\\thanks{%s}}\n" author email))
915 (author (format "\\author{%s}\n" author))
916 (t "\\author{}\n")))
917 ;; 6. Date.
918 (let ((date (and (plist-get info :with-date) (org-export-get-date info))))
919 (format "\\date{%s}\n" (org-export-data date info)))
920 ;; 7. Title
921 (format "\\title{%s}\n" title)
922 ;; 8. Hyperref options.
923 (when (plist-get info :latex-hyperref-p)
924 (format "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={%s}}\n"
925 (or (plist-get info :keywords) "")
926 (or (plist-get info :description) "")
927 (if (not (plist-get info :with-creator)) ""
928 (plist-get info :creator))))
929 ;; 9. Document start.
930 "\\begin{document}\n\n"
931 ;; 10. Title command.
932 (org-element-normalize-string
933 (cond ((string= "" title) nil)
934 ((not (stringp org-latex-title-command)) nil)
935 ((string-match "\\(?:[^%]\\|^\\)%s"
936 org-latex-title-command)
937 (format org-latex-title-command title))
938 (t org-latex-title-command)))
939 ;; 11. Table of contents.
940 (let ((depth (plist-get info :with-toc)))
941 (when depth
942 (concat
943 (format "\\begin{frame}%s{%s}\n"
944 (org-beamer--normalize-argument
945 org-beamer-outline-frame-options 'option)
946 org-beamer-outline-frame-title)
947 (when (wholenump depth)
948 (format "\\setcounter{tocdepth}{%d}\n" depth))
949 "\\tableofcontents\n"
950 "\\end{frame}\n\n")))
951 ;; 12. Document's body.
952 contents
953 ;; 13. Creator.
954 (let ((creator-info (plist-get info :with-creator)))
955 (cond
956 ((not creator-info) "")
957 ((eq creator-info 'comment)
958 (format "%% %s\n" (plist-get info :creator)))
959 (t (concat (plist-get info :creator) "\n"))))
960 ;; 14. Document end.
961 "\\end{document}")))
965 ;;; Minor Mode
968 (defvar org-beamer-mode-map (make-sparse-keymap)
969 "The keymap for `org-beamer-mode'.")
970 (define-key org-beamer-mode-map "\C-c\C-b" 'org-beamer-select-environment)
972 ;;;###autoload
973 (define-minor-mode org-beamer-mode
974 "Support for editing Beamer oriented Org mode files."
975 nil " Bm" 'org-beamer-mode-map)
977 (when (fboundp 'font-lock-add-keywords)
978 (font-lock-add-keywords
979 'org-mode
980 '((":\\(B_[a-z]+\\|BMCOL\\):" 1 'org-beamer-tag prepend))
981 'prepend))
983 (defface org-beamer-tag '((t (:box (:line-width 1 :color grey40))))
984 "The special face for beamer tags."
985 :group 'org-export-beamer)
987 (defun org-beamer-property-changed (property value)
988 "Track the BEAMER_env property with tags.
989 PROPERTY is the name of the modified property. VALUE is its new
990 value."
991 (cond
992 ((equal property "BEAMER_env")
993 (save-excursion
994 (org-back-to-heading t)
995 ;; Filter out Beamer-related tags and install environment tag.
996 (let ((tags (org-remove-if (lambda (x) (string-match "^B_" x))
997 (org-get-tags)))
998 (env-tag (and (org-string-nw-p value) (concat "B_" value))))
999 (org-set-tags-to (if env-tag (cons env-tag tags) tags))
1000 (when env-tag (org-toggle-tag env-tag 'on)))))
1001 ((equal property "BEAMER_col")
1002 (org-toggle-tag "BMCOL" (if (org-string-nw-p value) 'on 'off)))))
1004 (add-hook 'org-property-changed-functions 'org-beamer-property-changed)
1006 (defun org-beamer-allowed-property-values (property)
1007 "Supply allowed values for PROPERTY."
1008 (cond
1009 ((and (equal property "BEAMER_env")
1010 (not (org-entry-get nil (concat property "_ALL") 'inherit)))
1011 ;; If no allowed values for BEAMER_env have been defined,
1012 ;; supply all defined environments
1013 (mapcar 'car (append org-beamer-environments-special
1014 org-beamer-environments-extra
1015 org-beamer-environments-default)))
1016 ((and (equal property "BEAMER_col")
1017 (not (org-entry-get nil (concat property "_ALL") 'inherit)))
1018 ;; If no allowed values for BEAMER_col have been defined,
1019 ;; supply some
1020 (org-split-string org-beamer-column-widths " "))))
1022 (add-hook 'org-property-allowed-value-functions
1023 'org-beamer-allowed-property-values)
1027 ;;; Commands
1029 ;;;###autoload
1030 (defun org-beamer-export-as-latex
1031 (&optional async subtreep visible-only body-only ext-plist)
1032 "Export current buffer as a Beamer buffer.
1034 If narrowing is active in the current buffer, only export its
1035 narrowed part.
1037 If a region is active, export that region.
1039 A non-nil optional argument ASYNC means the process should happen
1040 asynchronously. The resulting buffer should be accessible
1041 through the `org-export-stack' interface.
1043 When optional argument SUBTREEP is non-nil, export the sub-tree
1044 at point, extracting information from the headline properties
1045 first.
1047 When optional argument VISIBLE-ONLY is non-nil, don't export
1048 contents of hidden elements.
1050 When optional argument BODY-ONLY is non-nil, only write code
1051 between \"\\begin{document}\" and \"\\end{document}\".
1053 EXT-PLIST, when provided, is a property list with external
1054 parameters overriding Org default settings, but still inferior to
1055 file-local settings.
1057 Export is done in a buffer named \"*Org BEAMER Export*\", which
1058 will be displayed when `org-export-show-temporary-export-buffer'
1059 is non-nil."
1060 (interactive)
1061 (if async
1062 (org-export-async-start
1063 (lambda (output)
1064 (with-current-buffer (get-buffer-create "*Org BEAMER Export*")
1065 (erase-buffer)
1066 (insert output)
1067 (goto-char (point-min))
1068 (LaTeX-mode)
1069 (org-export-add-to-stack (current-buffer) 'beamer)))
1070 `(org-export-as 'beamer ,subtreep ,visible-only ,body-only
1071 ',ext-plist))
1072 (let ((outbuf (org-export-to-buffer
1073 'beamer "*Org BEAMER Export*"
1074 subtreep visible-only body-only ext-plist)))
1075 (with-current-buffer outbuf (LaTeX-mode))
1076 (when org-export-show-temporary-export-buffer
1077 (switch-to-buffer-other-window outbuf)))))
1079 ;;;###autoload
1080 (defun org-beamer-export-to-latex
1081 (&optional async subtreep visible-only body-only ext-plist)
1082 "Export current buffer as a Beamer presentation (tex).
1084 If narrowing is active in the current buffer, only export its
1085 narrowed part.
1087 If a region is active, export that region.
1089 A non-nil optional argument ASYNC means the process should happen
1090 asynchronously. The resulting file should be accessible through
1091 the `org-export-stack' interface.
1093 When optional argument SUBTREEP is non-nil, export the sub-tree
1094 at point, extracting information from the headline properties
1095 first.
1097 When optional argument VISIBLE-ONLY is non-nil, don't export
1098 contents of hidden elements.
1100 When optional argument BODY-ONLY is non-nil, only write code
1101 between \"\\begin{document}\" and \"\\end{document}\".
1103 EXT-PLIST, when provided, is a property list with external
1104 parameters overriding Org default settings, but still inferior to
1105 file-local settings.
1107 Return output file's name."
1108 (interactive)
1109 (let ((outfile (org-export-output-file-name ".tex" subtreep)))
1110 (if async
1111 (org-export-async-start
1112 (lambda (f) (org-export-add-to-stack f 'beamer))
1113 `(expand-file-name
1114 (org-export-to-file
1115 'beamer ,outfile ,subtreep ,visible-only ,body-only
1116 ',ext-plist)))
1117 (org-export-to-file
1118 'beamer outfile subtreep visible-only body-only ext-plist))))
1120 ;;;###autoload
1121 (defun org-beamer-export-to-pdf
1122 (&optional async subtreep visible-only body-only ext-plist)
1123 "Export current buffer as a Beamer presentation (PDF).
1125 If narrowing is active in the current buffer, only export its
1126 narrowed part.
1128 If a region is active, export that region.
1130 A non-nil optional argument ASYNC means the process should happen
1131 asynchronously. The resulting file should be accessible through
1132 the `org-export-stack' interface.
1134 When optional argument SUBTREEP is non-nil, export the sub-tree
1135 at point, extracting information from the headline properties
1136 first.
1138 When optional argument VISIBLE-ONLY is non-nil, don't export
1139 contents of hidden elements.
1141 When optional argument BODY-ONLY is non-nil, only write code
1142 between \"\\begin{document}\" and \"\\end{document}\".
1144 EXT-PLIST, when provided, is a property list with external
1145 parameters overriding Org default settings, but still inferior to
1146 file-local settings.
1148 Return PDF file's name."
1149 (interactive)
1150 (if async
1151 (let ((outfile (org-export-output-file-name ".tex" subtreep)))
1152 (org-export-async-start
1153 (lambda (f) (org-export-add-to-stack f 'beamer))
1154 `(expand-file-name
1155 (org-latex-compile
1156 (org-export-to-file
1157 'beamer ,outfile ,subtreep ,visible-only ,body-only
1158 ',ext-plist)))))
1159 (org-latex-compile
1160 (org-beamer-export-to-latex
1161 nil subtreep visible-only body-only ext-plist))))
1163 ;;;###autoload
1164 (defun org-beamer-select-environment ()
1165 "Select the environment to be used by beamer for this entry.
1166 While this uses (for convenience) a tag selection interface, the
1167 result of this command will be that the BEAMER_env *property* of
1168 the entry is set.
1170 In addition to this, the command will also set a tag as a visual
1171 aid, but the tag does not have any semantic meaning."
1172 (interactive)
1173 ;; Make sure `org-beamer-environments-special' has a higher
1174 ;; priority than `org-beamer-environments-extra'.
1175 (let* ((envs (append org-beamer-environments-special
1176 org-beamer-environments-extra
1177 org-beamer-environments-default))
1178 (org-tag-alist
1179 (append '((:startgroup))
1180 (mapcar (lambda (e) (cons (concat "B_" (car e))
1181 (string-to-char (nth 1 e))))
1182 envs)
1183 '((:endgroup))
1184 '(("BMCOL" . ?|))))
1185 (org-fast-tag-selection-single-key t))
1186 (org-set-tags)
1187 (let ((tags (or (ignore-errors (org-get-tags-string)) "")))
1188 (cond
1189 ;; For a column, automatically ask for its width.
1190 ((eq org-last-tag-selection-key ?|)
1191 (if (string-match ":BMCOL:" tags)
1192 (org-set-property "BEAMER_col" (read-string "Column width: "))
1193 (org-delete-property "BEAMER_col")))
1194 ;; For an "againframe" section, automatically ask for reference
1195 ;; to resumed frame and overlay specifications.
1196 ((eq org-last-tag-selection-key ?A)
1197 (if (equal (org-entry-get nil "BEAMER_env") "againframe")
1198 (progn (org-entry-delete nil "BEAMER_env")
1199 (org-entry-delete nil "BEAMER_ref")
1200 (org-entry-delete nil "BEAMER_act"))
1201 (org-entry-put nil "BEAMER_env" "againframe")
1202 (org-set-property
1203 "BEAMER_ref"
1204 (read-string "Frame reference (*Title, #custom-id, id:...): "))
1205 (org-set-property "BEAMER_act"
1206 (read-string "Overlay specification: "))))
1207 ((string-match (concat ":B_\\(" (mapconcat 'car envs "\\|") "\\):") tags)
1208 (org-entry-put nil "BEAMER_env" (match-string 1 tags)))
1209 (t (org-entry-delete nil "BEAMER_env"))))))
1211 ;;;###autoload
1212 (defun org-beamer-insert-options-template (&optional kind)
1213 "Insert a settings template, to make sure users do this right."
1214 (interactive (progn
1215 (message "Current [s]ubtree or [g]lobal?")
1216 (if (eq (read-char-exclusive) ?g) (list 'global)
1217 (list 'subtree))))
1218 (if (eq kind 'subtree)
1219 (progn
1220 (org-back-to-heading t)
1221 (org-reveal)
1222 (org-entry-put nil "EXPORT_LaTeX_CLASS" "beamer")
1223 (org-entry-put nil "EXPORT_LaTeX_CLASS_OPTIONS" "[presentation]")
1224 (org-entry-put nil "EXPORT_FILE_NAME" "presentation.pdf")
1225 (when org-beamer-column-view-format
1226 (org-entry-put nil "COLUMNS" org-beamer-column-view-format))
1227 (org-entry-put nil "BEAMER_col_ALL" org-beamer-column-widths))
1228 (insert "#+LaTeX_CLASS: beamer\n")
1229 (insert "#+LaTeX_CLASS_OPTIONS: [presentation]\n")
1230 (when org-beamer-theme (insert "#+BEAMER_THEME: " org-beamer-theme "\n"))
1231 (when org-beamer-column-view-format
1232 (insert "#+COLUMNS: " org-beamer-column-view-format "\n"))
1233 (insert "#+PROPERTY: BEAMER_col_ALL " org-beamer-column-widths "\n")))
1235 ;;;###autoload
1236 (defun org-beamer-publish-to-latex (plist filename pub-dir)
1237 "Publish an Org file to a Beamer presentation (LaTeX).
1239 FILENAME is the filename of the Org file to be published. PLIST
1240 is the property list for the given project. PUB-DIR is the
1241 publishing directory.
1243 Return output file name."
1244 (org-publish-org-to 'beamer filename ".tex" plist pub-dir))
1246 ;;;###autoload
1247 (defun org-beamer-publish-to-pdf (plist filename pub-dir)
1248 "Publish an Org file to a Beamer presentation (PDF, via LaTeX).
1250 FILENAME is the filename of the Org file to be published. PLIST
1251 is the property list for the given project. PUB-DIR is the
1252 publishing directory.
1254 Return output file name."
1255 ;; Unlike to `org-beamer-publish-to-latex', PDF file is generated in
1256 ;; working directory and then moved to publishing directory.
1257 (org-publish-attachment
1258 plist
1259 (org-latex-compile (org-publish-org-to 'beamer filename ".tex" plist))
1260 pub-dir))
1263 (provide 'ox-beamer)
1265 ;; Local variables:
1266 ;; generated-autoload-file: "org-loaddefs.el"
1267 ;; End:
1269 ;;; ox-beamer.el ends here