1 ;;; org-e-beamer.el --- Beamer Back-End for Org Export Engine
3 ;; Copyright (C) 2007-2012 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/>.
24 ;; This library implements both a Beamer back-end, derived from the
25 ;; LaTeX one and a minor mode easing structure edition of the
28 ;; Depending on the desired output format, three commands are provided
29 ;; for export: `org-e-beamer-export-as-latex' (temporary buffer),
30 ;; `org-e-beamer-export-to-latex' ("tex" file) and
31 ;; `org-e-beamer-export-to-pdf' ("pdf" file).
33 ;; On top of buffer keywords supported by `e-latex' back-end (see
34 ;; `org-e-latex-options-alist'), this back-end introduces the
35 ;; following keywords: "BEAMER_THEME", "BEAMER_COLOR_THEME",
36 ;; "BEAMER_FONT_THEME", "BEAMER_INNER_THEME" and "BEAMER_OUTER_THEME".
37 ;; All accept options in square brackets.
39 ;; Moreover, headlines now fall into three categories: sectioning
40 ;; elements, frames and blocks.
42 ;; - Like `e-latex' back-end sectioning elements are still set through
43 ;; `org-e-latex-classes' variable.
45 ;; - Headlines become frames when their level is equal to
46 ;; `org-e-beamer-frame-level' (or "H" value in the OPTIONS line).
47 ;; Though, if an headline in the current tree has a "BEAMER_env"
48 ;; (see below) property set to "frame", its level overrides the
51 ;; - All frames' children become block environments. Special block
52 ;; types can be enforced by setting headline's "BEAMER_env" property
53 ;; to an appropriate value (see `org-e-beamer-environments-default'
54 ;; for supported value and `org-e-beamer-environments-extra' for
57 ;; - As a special case, if the "BEAMER_env" property is set to either
58 ;; "appendix", "note" or "noteNH", the headline will become,
59 ;; respectively, an appendix, a note (within frame or between frame,
60 ;; depending on its level) and a note with its title ignored.
62 ;; Also, an headline with an "ignoreheading" value will have its
63 ;; contents only inserted in the output. This special value is
64 ;; useful to have data between frames, or to properly close
65 ;; a "column" environment.
67 ;; Along with "BEAMER_env", headlines also support "BEAMER_act" and
68 ;; "BEAMER_opt" properties. The former is translated as an
69 ;; overlay/action specification (or a default overlay specification
70 ;; when enclosed within square brackets) whereas the latter specifies
71 ;; options for the current frame ("fragile" option is added
72 ;; automatically, though).
74 ;; Every plain list has support for `:overlay' attribute (through
75 ;; ATTR_BEAMER affiliated keyword). Also, ordered (resp. description)
76 ;; lists make use of `:template' (resp. `:long-text') attribute.
78 ;; Eventually, an export snippet with a value enclosed within angular
79 ;; brackets put at the beginning of an element or object whose type is
80 ;; among `bold', `item', `link', `radio-target' and `target' will
81 ;; control its overlay specifications.
83 ;; On the minor mode side, `org-e-beamer-select-environment' (bound by
84 ;; default to "C-c C-b") and `org-e-beamer-insert-options-template'
85 ;; are the two entry points.
89 (require 'org-e-latex
)
93 ;;; User-Configurable Variables
95 (defgroup org-export-e-beamer nil
96 "Options specific for using the beamer class in LaTeX export."
101 (defcustom org-e-beamer-frame-level
1
102 "The level at which headlines become frames.
104 Headlines at a lower level will be translated into a sectioning
105 structure. At a higher level, they will be translated into
108 If an headline with a \"BEAMER_env\" property set to \"frame\" is
109 found within a tree, its level locally overrides this number.
111 This variable has no effect on headlines with the \"BEAMER_env\"
112 property set to either \"ignoreheading\", \"appendix\", or
113 \"note\", which will respectively, be invisible, become an
116 This integer is relative to the minimal level of an headline
117 within the parse tree, defined as 1."
118 :group
'org-export-e-beamer
121 (defcustom org-e-beamer-frame-default-options
""
122 "Default options string to use for frames.
123 For example, it could be set to \"allowframebreaks\"."
124 :group
'org-export-e-beamer
125 :type
'(string :tag
"[options]"))
127 (defcustom org-e-beamer-column-view-format
128 "%45ITEM %10BEAMER_env(Env) %10BEAMER_act(Act) %4BEAMER_col(Col) %8BEAMER_opt(Opt)"
129 "Column view format that should be used to fill the template."
130 :group
'org-export-e-beamer
132 (const :tag
"Do not insert Beamer column view format" nil
)
133 (string :tag
"Beamer column view format")))
135 (defcustom org-e-beamer-theme
"default"
136 "Default theme used in Beamer presentations."
137 :group
'org-export-e-beamer
139 (const :tag
"Do not insert a Beamer theme" nil
)
140 (string :tag
"Beamer theme")))
142 (defcustom org-e-beamer-environments-extra nil
143 "Environments triggered by tags in Beamer export.
144 Each entry has 4 elements:
146 name Name of the environment
147 key Selection key for `org-e-beamer-select-environment'
148 open The opening template for the environment, with the following escapes
149 %a the action/overlay specification
150 %A the default action/overlay specification
151 %o the options argument of the template
153 %H if there is headline text, that text in {} braces
154 %U if there is headline text, that text in [] brackets
155 close The closing string of the environment."
156 :group
'org-export-e-beamer
159 (string :tag
"Environment")
160 (string :tag
"Selection key")
161 (string :tag
"Begin")
162 (string :tag
"End"))))
164 (defcustom org-e-beamer-outline-frame-title
"Outline"
165 "Default title of a frame containing an outline."
166 :group
'org-export-e-beamer
167 :type
'(string :tag
"Outline frame title"))
169 (defcustom org-e-beamer-outline-frame-options nil
170 "Outline frame options appended after \\begin{frame}.
171 You might want to put e.g. \"allowframebreaks=0.9\" here."
172 :group
'org-export-e-beamer
173 :type
'(string :tag
"Outline frame options"))
177 ;;; Internal Variables
179 (defconst org-e-beamer-column-widths
180 "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.0 :ETC"
181 "The column widths that should be installed as allowed property values.")
183 (defconst org-e-beamer-environments-special
187 ("ignoreheading" "i")
190 "Alist of environments treated in a special way by the back-end.
191 Keys are environment names, as strings, values are bindings used
192 in `org-e-beamer-select-environment'. Environments listed here,
193 along with their binding, are hard coded and cannot be modified
194 through `org-e-beamer-environments-extra' variable.")
196 (defconst org-e-beamer-environments-default
197 '(("block" "b" "\\begin{block}%a{%h}" "\\end{block}")
198 ("alertblock" "a" "\\begin{alertblock}%a{%h}" "\\end{alertblock}")
199 ("verse" "v" "\\begin{verse}%a %% %h" "\\end{verse}")
200 ("quotation" "q" "\\begin{quotation}%a %% %h" "\\end{quotation}")
201 ("quote" "Q" "\\begin{quote}%a %% %h" "\\end{quote}")
202 ("structureenv" "s" "\\begin{structureenv}%a %% %h" "\\end{structureenv}")
203 ("theorem" "t" "\\begin{theorem}%a%U" "\\end{theorem}")
204 ("definition" "d" "\\begin{definition}%a%U" "\\end{definition}")
205 ("example" "e" "\\begin{example}%a%U" "\\end{example}")
206 ("exampleblock" "E" "\\begin{exampleblock}%a{%h}" "\\end{exampleblock}")
207 ("proof" "p" "\\begin{proof}%a%U" "\\end{proof}")
208 ("beamercolorbox" "o" "\\begin{beamercolorbox}%o{%h}" "\\end{beamercolorbox}"))
209 "Environments triggered by properties in Beamer export.
210 These are the defaults - for user definitions, see
211 `org-e-beamer-environments-extra'.")
213 (defconst org-e-beamer-verbatim-elements
214 '(code example-block fixed-width inline-src-block src-block verbatim
)
215 "List of element or object types producing verbatim text.
216 This is used internally to determine when a frame should have the
217 \"fragile\" option.")
221 ;;; Internal functions
223 (defun org-e-beamer--normalize-argument (argument type
)
224 "Return ARGUMENT string with proper boundaries.
226 TYPE is a symbol among the following:
227 `action' Return ARGUMENT within angular brackets.
228 `defaction' Return ARGUMENT within both square and angular brackets.
229 `option' Return ARGUMENT within square brackets."
231 (action (if (string-match "\\`<.*>\\'" argument
) argument
232 (format "<%s>" argument
)))
234 ((string-match "\\`\\[<.*>\\]\\'" argument
) argument
)
235 ((string-match "\\`<.*>\\'" argument
)
236 (format "[%s]" argument
))
237 ((string-match "\\`\\[\\(.*\\)\\]\\'" argument
)
238 (format "[<%s>]" (match-string 1 argument
)))
239 (t (format "[<%s>]" argument
))))
240 (option (if (string-match "\\`\\[.*\\]\\'" argument
) argument
241 (format "[%s]" argument
)))
242 (otherwise argument
)))
244 (defun org-e-beamer--element-has-overlay-p (element)
245 "Non-nil when ELEMENT has an overlay specified.
246 An element has an overlay specification when it starts with an
247 `e-beamer' export-snippet whose value is between angular
248 brackets. Return overlay specification, as a string, or nil."
249 (let ((first-object (car (org-element-contents element
))))
250 (when (eq (org-element-type first-object
) 'export-snippet
)
251 (let ((value (org-element-property :value first-object
)))
252 (and (string-match "\\`<.*>\\'" value
) value
)))))
258 (org-export-define-derived-backend e-beamer e-latex
260 ((:beamer-theme
"BEAMER_THEME" nil org-e-beamer-theme
)
261 (:beamer-color-theme
"BEAMER_COLOR_THEME" nil nil t
)
262 (:beamer-font-theme
"BEAMER_FONT_THEME" nil nil t
)
263 (:beamer-inner-theme
"BEAMER_INNER_THEME" nil nil t
)
264 (:beamer-outer-theme
"BEAMER_OUTER_THEME" nil nil t
)
265 (:headline-levels nil
"H" org-e-beamer-frame-level
))
266 :translate-alist
((bold . org-e-beamer-bold
)
267 (export-block . org-e-beamer-export-block
)
268 (export-snippet . org-e-beamer-export-snippet
)
269 (headline . org-e-beamer-headline
)
270 (item . org-e-beamer-item
)
271 (keyword . org-e-beamer-keyword
)
272 (link . org-e-beamer-link
)
273 (plain-list . org-e-beamer-plain-list
)
274 (radio-target . org-e-beamer-radio-target
)
275 (target . org-e-beamer-target
)
276 (template . org-e-beamer-template
)))
280 ;;; Transcode Functions
284 (defun org-e-beamer-bold (bold contents info
)
285 "Transcode BLOCK object into Beamer code.
286 CONTENTS is the text being bold. INFO is a plist used as
287 a communication channel."
288 (format "\\alert%s{%s}"
289 (or (org-e-beamer--element-has-overlay-p bold
) "")
295 (defun org-e-beamer-export-block (export-block contents info
)
296 "Transcode an EXPORT-BLOCK element into Beamer code.
297 CONTENTS is nil. INFO is a plist used as a communication
299 (when (member (org-element-property :type export-block
) '("BEAMER" "LATEX"))
300 (org-remove-indentation (org-element-property :value export-block
))))
305 (defun org-e-beamer-export-snippet (export-snippet contents info
)
306 "Transcode an EXPORT-SNIPPET object into Beamer code.
307 CONTENTS is nil. INFO is a plist used as a communication
309 (let ((backend (org-export-snippet-backend export-snippet
))
310 (value (org-element-property :value export-snippet
)))
311 ;; Only "e-latex" and "e-beamer" snippets are retained.
312 (cond ((eq backend
'e-latex
) value
)
313 ;; Ignore "e-beamer" snippets specifying overlays.
314 ((and (eq backend
'e-beamer
)
315 (or (org-export-get-previous-element export-snippet
)
316 (not (string-match "\\`<.*>\\'" value
))))
322 ;; The main function to translate an headline is
323 ;; `org-e-beamer-headline'.
325 ;; Depending on the level at which an headline is considered as
326 ;; a frame (given by `org-e-beamer--frame-level'), the headline is
327 ;; either a section (`org-e-beamer--format-section'), a frame
328 ;; (`org-e-beamer--format-frame') or a block
329 ;; (`org-e-beamer--format-block').
331 ;; `org-e-beamer-headline' also takes care of special environments
332 ;; like "ignoreheading", "note", "noteNH" and "appendix".
334 (defun org-e-beamer--frame-level (headline info
)
335 "Return frame level in subtree containing HEADLINE.
336 INFO is a plist used as a communication channel."
338 ;; 1. Look for "frame" environment in parents, starting from the
341 (mapc (lambda (parent)
342 (when (equal (org-element-property :beamer-env parent
) "frame")
343 (throw 'exit
(org-export-get-relative-level parent info
))))
344 (reverse (org-export-get-genealogy headline
)))
346 ;; 2. Look for "frame" environment in HEADLINE.
347 (and (equal (org-element-property :beamer-env headline
) "frame")
348 (org-export-get-relative-level headline info
))
349 ;; 3. Look for "frame" environment in sub-tree.
353 (when (equal (org-element-property :beamer-env hl
) "frame")
354 (org-export-get-relative-level hl info
)))
356 ;; 4. No "frame" environment in tree: use default value.
357 (plist-get info
:headline-levels
)))
359 (defun org-e-beamer--format-section (headline contents info
)
360 "Format HEADLINE as a sectioning part.
361 CONTENTS holds the contents of the headline. INFO is a plist
362 used as a communication channel."
363 ;; Use `e-latex' back-end output, inserting overlay specifications
365 (let ((latex-headline
366 (funcall (cdr (assq 'headline org-e-latex-translate-alist
))
367 headline contents info
))
368 (mode-specs (org-element-property :beamer-act headline
)))
370 (string-match "\\`\\\\\\(.*?\\)\\(?:\\*\\|\\[.*\\]\\)?{"
372 (replace-match (concat (match-string 1 latex-headline
)
373 (format "<%s>" mode-specs
))
374 nil nil latex-headline
1)
377 (defun org-e-beamer--format-frame (headline contents info
)
378 "Format HEADLINE as a frame.
379 CONTENTS holds the contents of the headline. INFO is a plist
380 used as a communication channel."
381 (concat "\\begin{frame}"
382 ;; Overlay specification, if any. If is surrounded by square
383 ;; brackets, consider it as a default specification.
384 (let ((action (org-element-property :beamer-act headline
)))
387 ((string-match "\\`\\[.*\\]\\'" action
)
388 (org-e-beamer--normalize-argument action
'defaction
))
389 (t (org-e-beamer--normalize-argument action
'action
))))
392 ;; Collect options from default value and headline's
393 ;; properties. Also add a label for links.
395 (org-split-string org-e-beamer-frame-default-options
397 (let ((opt (org-element-property :beamer-opt headline
)))
398 (and opt
(org-split-string
399 ;; Remove square brackets if user
401 (and (string-match "^\\[?\\(.*\\)\\]?$" opt
)
402 (match-string 1 opt
))
405 (format "label=sec-%s"
408 (org-export-get-headline-number headline info
)
410 ;; Change options list into a string. FRAGILEP is non-nil
411 ;; when HEADLINE contains an element among
412 ;; `org-e-beamer-verbatim-elements'.
413 (let ((fragilep (org-element-map
414 headline org-e-beamer-verbatim-elements
'identity
416 (org-e-beamer--normalize-argument
419 (if (or (not fragilep
) (member "fragile" options
)) options
420 (cons "fragile" options
))
425 (org-export-data (org-element-property :title headline
)
431 (defun org-e-beamer--format-block (headline contents info
)
432 "Format HEADLINE as a block.
433 CONTENTS holds the contents of the headline. INFO is a plist
434 used as a communication channel."
435 (let* ((column-width (org-element-property :beamer-col headline
))
436 ;; Environment defaults to "block" if none is specified and
437 ;; there is no column specification. If there is a column
438 ;; specified but still no explicit environment, ENVIRONMENT
440 (environment (let ((env (org-element-property :beamer-env headline
)))
442 ;; "block" is the fallback environment.
443 ((and (not env
) (not column-width
)) "block")
446 ;; Use specified environment.
447 (t (downcase env
)))))
448 (env-format (when environment
450 (append org-e-beamer-environments-special
451 org-e-beamer-environments-extra
452 org-e-beamer-environments-default
))))
453 (title (org-export-data (org-element-property :title headline
) info
))
454 ;; Start a columns environment when there is no previous
455 ;; headline or the previous headline do not have
456 ;; a BEAMER_column property.
459 (or (org-export-first-sibling-p headline
)
460 (not (org-element-property
462 (org-export-get-previous-element headline
))))))
463 ;; Ends a columns environment when there is no next headline
464 ;; or the next headline do not have a BEAMER_column property.
467 (or (org-export-last-sibling-p headline
)
468 (not (org-element-property
470 (org-export-get-next-element headline
)))))))
472 (when start-columns-p
"\\begin{columns}\n")
474 (format "\\begin{column}%s{%s}\n"
475 ;; One can specify placement for column only when
476 ;; HEADLINE stands for a column on its own.
477 (if (not environment
) ""
478 (let ((options (org-element-property :beamer-opt headline
)))
480 (org-e-beamer--normalize-argument options
'option
))))
481 (format "%s\\textwidth" column-width
)))
482 ;; Block's opening string.
488 ;; If BEAMER_act property has its value enclosed in square
489 ;; brackets, it is a default overlay specification and
490 ;; overlay specification is empty. Otherwise, it is an
491 ;; overlay specification and the default one is nil.
492 (let ((action (org-element-property :beamer-act headline
)))
494 ((not action
) (list (cons "a" "") (cons "A" "")))
495 ((string-match "\\`\\[.*\\]\\'" action
)
498 (org-e-beamer--normalize-argument action
'defaction
))
503 (org-e-beamer--normalize-argument action
'action
))
507 (org-element-property :beamer-opt headline
)))
509 (org-e-beamer--normalize-argument options
'option
))))
511 (cons "H" (if (equal title
"") "" (format "{%s}" title
)))
512 (cons "U" (if (equal title
"") "" (format "[%s]" title
))))))
515 ;; Block's closing string.
516 (when environment
(concat (nth 3 env-format
) "\n"))
517 (when column-width
"\\end{column}\n")
518 (when end-columns-p
"\\end{columns}"))))
520 (defun org-e-beamer-headline (headline contents info
)
521 "Transcode HEADLINE element into Beamer code.
522 CONTENTS is the contents of the headline. INFO is a plist used
523 as a communication channel."
524 (unless (org-element-property :footnote-section-p headline
)
525 (let ((level (org-export-get-relative-level headline info
))
526 (frame-level (org-e-beamer--frame-level headline info
))
527 (environment (let ((env (org-element-property :beamer-env headline
)))
528 (if (stringp env
) (downcase env
) "block"))))
530 ;; Creation of an appendix is requested.
531 ((equal environment
"appendix")
533 (org-element-property :beamer-act headline
)
535 (make-string (org-element-property :pre-blank headline
) ?
\n)
537 ((equal environment
"ignoreheading")
538 (concat (make-string (org-element-property :pre-blank headline
) ?
\n)
540 ;; HEADLINE is a note.
541 ((member environment
'("note" "noteNH"))
543 (concat (and (equal environment
"note")
546 (org-element-property :title headline
) info
)
548 (org-trim contents
))))
549 ;; HEADLINE is a frame.
550 ((or (equal environment
"frame") (= level frame-level
))
551 (org-e-beamer--format-frame headline contents info
))
552 ;; Regular section, extracted from `org-e-latex-classes'.
553 ((< level frame-level
)
554 (org-e-beamer--format-section headline contents info
))
555 ;; Otherwise, HEADLINE is a block.
556 (t (org-e-beamer--format-block headline contents info
))))))
561 (defun org-e-beamer-item (item contents info
)
562 "Transcode an ITEM element into Beamer code.
563 CONTENTS holds the contents of the item. INFO is a plist holding
564 contextual information."
565 (let ((action (let ((first-element (car (org-element-contents item
))))
566 (and (eq (org-element-type first-element
) 'paragraph
)
567 (org-e-beamer--element-has-overlay-p first-element
))))
568 (output (funcall (cdr (assq 'item org-e-latex-translate-alist
))
569 item contents info
)))
570 (if (not action
) output
571 ;; If the item starts with a paragraph and that paragraph starts
572 ;; with an export snippet specifying an overlay, insert it after
574 (replace-regexp-in-string "\\\\item" (concat "\\\\item" action
) output
))))
579 (defun org-e-beamer-keyword (keyword contents info
)
580 "Transcode a KEYWORD element into Beamer code.
581 CONTENTS is nil. INFO is a plist used as a communication
583 (let ((key (org-element-property :key keyword
))
584 (value (org-element-property :value keyword
)))
585 ;; Handle specifically BEAMER and TOC (headlines only) keywords.
586 ;; Otherwise, fallback to `e-latex' back-end.
588 ((equal key
"BEAMER") value
)
589 ((and (equal key
"TOC") (string-match "\\<headlines\\>" value
))
590 (let ((depth (or (and (string-match "[0-9]+" value
)
591 (string-to-number (match-string 0 value
)))
592 (plist-get info
:with-toc
)))
593 (options (and (string-match "\\[.*?\\]" value
)
594 (match-string 0 value
))))
597 (when (wholenump depth
) (format "\\setcounter{tocdepth}{%s}\n" depth
))
598 "\\tableofcontents" options
"\n"
600 (t (funcall (cdr (assq 'keyword org-e-latex-translate-alist
))
601 keyword contents info
)))))
606 (defun org-e-beamer-link (link contents info
)
607 "Transcode a LINK object into Beamer code.
608 CONTENTS is the description part of the link. INFO is a plist
609 used as a communication channel."
610 (let ((type (org-element-property :type link
))
611 (path (org-element-property :path link
)))
612 ;; Use \hyperlink command for all internal links.
614 ((equal type
"radio")
615 (let ((destination (org-export-resolve-radio-link link info
)))
617 (format "\\hyperlink%s{%s}{%s}"
618 (or (org-e-beamer--element-has-overlay-p link
) "")
619 (org-export-solidify-link-text path
)
620 (org-export-data (org-element-contents destination
) info
)))))
621 ((and (member type
'("custom-id" "fuzzy" "id"))
622 (let ((destination (if (string= type
"fuzzy")
623 (org-export-resolve-fuzzy-link link info
)
624 (org-export-resolve-id-link link info
))))
625 (case (org-element-type destination
)
631 (org-export-get-headline-number
634 (if (and (plist-get info
:section-numbers
) (not contents
))
635 (format "\\ref{%s}" label
)
636 (format "\\hyperlink%s{%s}{%s}"
637 (or (org-e-beamer--element-has-overlay-p link
) "")
641 (let ((path (org-export-solidify-link-text path
)))
642 (if (not contents
) (format "\\ref{%s}" path
)
643 (format "\\hyperlink%s{%s}{%s}"
644 (or (org-e-beamer--element-has-overlay-p link
) "")
647 ;; Otherwise, use `e-latex' back-end.
648 (t (funcall (cdr (assq 'link org-e-latex-translate-alist
))
649 link contents info
)))))
654 ;; Plain lists support `:overlay' (for any type), `:template' (for
655 ;; ordered lists only) and `:long-text' (for description lists only)
658 (defun org-e-beamer-plain-list (plain-list contents info
)
659 "Transcode a PLAIN-LIST element into Beamer code.
660 CONTENTS is the contents of the list. INFO is a plist holding
661 contextual information."
662 (let* ((type (org-element-property :type plain-list
))
663 (attributes (org-export-read-attribute :attr_beamer plain-list
))
664 (latex-type (cond ((eq type
'ordered
) "enumerate")
665 ((eq type
'descriptive
) "description")
667 (org-e-latex--wrap-label
669 (format "\\begin{%s}%s%s\n%s\\end{%s}"
671 ;; Default overlay specification, if any.
672 (let ((overlay (plist-get attributes
:overlay
)))
674 (org-e-beamer--normalize-argument overlay
'defaction
)))
675 ;; Second optional argument depends on the list type.
678 (let ((template (plist-get attributes
:template
)))
679 (if (not template
) ""
680 (org-e-beamer--normalize-argument template
'option
))))
682 (let ((long-text (plist-get attributes
:long-text
)))
683 (if (not long-text
) ""
684 (org-e-beamer--normalize-argument long-text
'option
))))
685 ;; There's no second argument for un-ordered lists.
687 ;; Eventually insert contents and close environment.
694 (defun org-e-beamer-radio-target (radio-target text info
)
695 "Transcode a RADIO-TARGET object into Beamer code.
696 TEXT is the text of the target. INFO is a plist holding
697 contextual information."
698 (format "\\hypertarget%s{%s}{%s}"
699 (or (org-e-beamer--element-has-overlay-p radio-target
) "")
700 (org-export-solidify-link-text
701 (org-element-property :value radio-target
))
707 (defun org-e-beamer-target (target contents info
)
708 "Transcode a TARGET object into Beamer code.
709 CONTENTS is nil. INFO is a plist holding contextual
711 (format "\\hypertarget{%s}{}"
712 (org-export-solidify-link-text (org-element-property :value target
))))
717 ;; Template used is similar to the one used in `e-latex' back-end,
718 ;; excepted for the table of contents and Beamer themes.
720 (defun org-e-beamer-template (contents info
)
721 "Return complete document string after Beamer conversion.
722 CONTENTS is the transcoded contents string. INFO is a plist
723 holding export options."
724 (let ((title (org-export-data (plist-get info
:title
) info
)))
727 (and (plist-get info
:time-stamp-file
)
728 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
729 ;; 2. Document class and packages.
730 (let ((class (plist-get info
:latex-class
))
731 (class-options (plist-get info
:latex-class-options
)))
732 (org-element-normalize-string
733 (let* ((header (nth 1 (assoc class org-e-latex-classes
)))
734 (document-class-string
735 (and (stringp header
)
737 (replace-regexp-in-string
738 "^[ \t]*\\\\documentclass\\(\\[.*?\\]\\)"
739 class-options header t nil
1)
741 (when document-class-string
742 (org-e-latex--guess-babel-language
743 (org-e-latex--guess-inputenc
744 (org-splice-latex-header
745 document-class-string
746 org-export-latex-default-packages-alist
; defined in org.el
747 org-export-latex-packages-alist nil
; defined in org.el
748 (plist-get info
:latex-header-extra
)))
753 (lambda (prop command
)
754 (let ((theme (plist-get info prop
)))
757 (if (not (string-match "\\[.*\\]" theme
))
758 (format "{%s}\n" theme
)
760 (match-string 0 theme
)
762 (replace-match "" nil nil theme
)))))))))))
763 (mapconcat (lambda (args) (apply format-theme args
))
764 '((:beamer-theme
"\\usetheme")
765 (:beamer-color-theme
"\\usecolortheme")
766 (:beamer-font-theme
"\\usefonttheme")
767 (:beamer-inner-theme
"\\useinnertheme")
768 (:beamer-outer-theme
"\\useoutertheme"))
770 ;; 4. Possibly limit depth for headline numbering.
771 (let ((sec-num (plist-get info
:section-numbers
)))
772 (when (integerp sec-num
)
773 (format "\\setcounter{secnumdepth}{%d}\n" sec-num
)))
775 (let ((author (and (plist-get info
:with-author
)
776 (let ((auth (plist-get info
:author
)))
777 (and auth
(org-export-data auth info
)))))
778 (email (and (plist-get info
:with-email
)
779 (org-export-data (plist-get info
:email
) info
))))
780 (cond ((and author email
(not (string= "" email
)))
781 (format "\\author{%s\\thanks{%s}}\n" author email
))
782 (author (format "\\author{%s}\n" author
))
785 (format "\\date{%s}\n" (org-export-data (plist-get info
:date
) info
))
787 (format "\\title{%s}\n" title
)
788 ;; 8. Hyperref options.
789 (format "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={%s}}\n"
790 (or (plist-get info
:keywords
) "")
791 (or (plist-get info
:description
) "")
792 (if (not (plist-get info
:with-creator
)) ""
793 (plist-get info
:creator
)))
794 ;; 9. Document start.
795 "\\begin{document}\n\n"
796 ;; 10. Title command.
797 (org-element-normalize-string
798 (cond ((string= "" title
) nil
)
799 ((not (stringp org-e-latex-title-command
)) nil
)
800 ((string-match "\\(?:[^%]\\|^\\)%s"
801 org-e-latex-title-command
)
802 (format org-e-latex-title-command title
))
803 (t org-e-latex-title-command
)))
804 ;; 11. Table of contents.
805 (let ((depth (plist-get info
:with-toc
)))
808 (format "\\begin{frame}%s{%s}\n"
809 (org-e-beamer--normalize-argument
810 org-e-beamer-outline-frame-options
'option
)
811 org-e-beamer-outline-frame-title
)
812 (when (wholenump depth
)
813 (format "\\setcounter{tocdepth}{%d}\n" depth
))
814 "\\tableofcontents\n"
815 "\\end{frame}\n\n")))
816 ;; 12. Document's body.
819 (let ((creator-info (plist-get info
:with-creator
)))
821 ((not creator-info
) "")
822 ((eq creator-info
'comment
)
823 (format "%% %s\n" (plist-get info
:creator
)))
824 (t (concat (plist-get info
:creator
) "\n"))))
833 (defvar org-e-beamer-mode-map
(make-sparse-keymap)
834 "The keymap for `org-e-beamer-mode'.")
835 (define-key org-e-beamer-mode-map
"\C-c\C-b" 'org-e-beamer-select-environment
)
838 (define-minor-mode org-e-beamer-mode
839 "Support for editing Beamer oriented Org mode files."
840 nil
" Bm" 'org-e-beamer-mode-map
)
842 (when (fboundp 'font-lock-add-keywords
)
843 (font-lock-add-keywords
845 '((":\\(B_[a-z]+\\|BMCOL\\):" 1 'org-e-beamer-tag prepend
))
848 (defface org-e-beamer-tag
'((t (:box
(:line-width
1 :color grey40
))))
849 "The special face for beamer tags."
850 :group
'org-export-e-beamer
)
852 (defun org-e-beamer-property-changed (property value
)
853 "Track the BEAMER_env property with tags.
854 PROPERTY is the name of the modified property. VALUE is its new
857 ((equal property
"BEAMER_env")
859 (org-back-to-heading t
)
860 (let ((tags (org-get-tags)))
861 (setq tags
(delq nil
(mapcar (lambda (x)
862 (if (string-match "^B_" x
) nil x
))
864 (org-set-tags-to tags
))
865 (when (org-string-nw-p value
) (org-toggle-tag (concat "B_" value
) 'on
))))
866 ((equal property
"BEAMER_col")
867 (org-toggle-tag "BMCOL" (if (org-string-nw-p value
) 'on
'off
)))))
869 (add-hook 'org-property-changed-functions
'org-e-beamer-property-changed
)
871 (defun org-e-beamer-allowed-property-values (property)
872 "Supply allowed values for PROPERTY."
874 ((and (equal property
"BEAMER_env")
875 (not (org-entry-get nil
(concat property
"_ALL") 'inherit
)))
876 ;; If no allowed values for BEAMER_env have been defined,
877 ;; supply all defined environments
878 (mapcar 'car
(append org-e-beamer-environments-special
879 org-e-beamer-environments-extra
880 org-e-beamer-environments-default
)))
881 ((and (equal property
"BEAMER_col")
882 (not (org-entry-get nil
(concat property
"_ALL") 'inherit
)))
883 ;; If no allowed values for BEAMER_col have been defined,
885 (org-split-string org-e-beamer-column-widths
" "))))
887 (add-hook 'org-property-allowed-value-functions
888 'org-e-beamer-allowed-property-values
)
895 (defun org-e-beamer-export-as-latex
896 (&optional subtreep visible-only body-only ext-plist
)
897 "Export current buffer as a Beamer buffer.
899 If narrowing is active in the current buffer, only export its
902 If a region is active, export that region.
904 When optional argument SUBTREEP is non-nil, export the sub-tree
905 at point, extracting information from the headline properties
908 When optional argument VISIBLE-ONLY is non-nil, don't export
909 contents of hidden elements.
911 When optional argument BODY-ONLY is non-nil, only write code
912 between \"\\begin{document}\" and \"\\end{document}\".
914 EXT-PLIST, when provided, is a property list with external
915 parameters overriding Org default settings, but still inferior to
918 Export is done in a buffer named \"*Org E-BEAMER Export*\", which
919 will be displayed when `org-export-show-temporary-export-buffer'
922 (let ((outbuf (org-export-to-buffer
923 'e-beamer
"*Org E-BEAMER Export*"
924 subtreep visible-only body-only ext-plist
)))
925 (with-current-buffer outbuf
(LaTeX-mode))
926 (when org-export-show-temporary-export-buffer
927 (switch-to-buffer-other-window outbuf
))))
930 (defun org-e-beamer-export-to-latex
931 (&optional subtreep visible-only body-only ext-plist pub-dir
)
932 "Export current buffer as a Beamer presentation (tex).
934 If narrowing is active in the current buffer, only export its
937 If a region is active, export that region.
939 When optional argument SUBTREEP is non-nil, export the sub-tree
940 at point, extracting information from the headline properties
943 When optional argument VISIBLE-ONLY is non-nil, don't export
944 contents of hidden elements.
946 When optional argument BODY-ONLY is non-nil, only write code
947 between \"\\begin{document}\" and \"\\end{document}\".
949 EXT-PLIST, when provided, is a property list with external
950 parameters overriding Org default settings, but still inferior to
953 When optional argument PUB-DIR is set, use it as the publishing
956 Return output file's name."
958 (let ((outfile (org-export-output-file-name ".tex" subtreep pub-dir
)))
960 'e-beamer outfile subtreep visible-only body-only ext-plist
)))
963 (defun org-e-beamer-export-to-pdf
964 (&optional subtreep visible-only body-only ext-plist pub-dir
)
965 "Export current buffer as a BEAMER presentation (PDF).
967 If narrowing is active in the current buffer, only export its
970 If a region is active, export that region.
972 When optional argument SUBTREEP is non-nil, export the sub-tree
973 at point, extracting information from the headline properties
976 When optional argument VISIBLE-ONLY is non-nil, don't export
977 contents of hidden elements.
979 When optional argument BODY-ONLY is non-nil, only write code
980 between \"\\begin{document}\" and \"\\end{document}\".
982 EXT-PLIST, when provided, is a property list with external
983 parameters overriding Org default settings, but still inferior to
986 When optional argument PUB-DIR is set, use it as the publishing
989 Return PDF file's name."
992 (org-e-beamer-export-to-latex
993 subtreep visible-only body-only ext-plist pub-dir
)))
996 (defun org-e-beamer-select-environment ()
997 "Select the environment to be used by beamer for this entry.
998 While this uses (for convenience) a tag selection interface, the
999 result of this command will be that the BEAMER_env *property* of
1002 In addition to this, the command will also set a tag as a visual
1003 aid, but the tag does not have any semantic meaning."
1005 ;; Make sure `org-e-beamer-environments-special' has a higher
1006 ;; priority than `org-e-beamer-environments-extra'.
1007 (let* ((envs (append org-e-beamer-environments-special
1008 org-e-beamer-environments-extra
1009 org-e-beamer-environments-default
))
1011 (append '((:startgroup
))
1012 (mapcar (lambda (e) (cons (concat "B_" (car e
))
1013 (string-to-char (nth 1 e
))))
1017 (org-fast-tag-selection-single-key t
))
1019 (let ((tags (or (ignore-errors (org-get-tags-string)) "")))
1021 ((eq org-last-tag-selection-key ?|
)
1022 (if (string-match ":BMCOL:" tags
)
1023 (org-set-property "BEAMER_col" (read-string "Column width: "))
1024 (org-delete-property "BEAMER_col")))
1025 ((string-match (concat ":B_\\("
1026 (mapconcat 'car envs
"\\|")
1029 (org-entry-put nil
"BEAMER_env" (match-string 1 tags
)))
1030 (t (org-entry-delete nil
"BEAMER_env"))))))
1033 (defun org-e-beamer-insert-options-template (&optional kind
)
1034 "Insert a settings template, to make sure users do this right."
1036 (message "Current [s]ubtree or [g]lobal?")
1037 (if (eq (read-char-exclusive) ?g
) (list 'global
)
1039 (if (eq kind
'subtree
)
1041 (org-back-to-heading t
)
1043 (org-entry-put nil
"LaTeX_CLASS" "beamer")
1044 (org-entry-put nil
"LaTeX_CLASS_OPTIONS" "[presentation]")
1045 (org-entry-put nil
"EXPORT_FILE_NAME" "presentation.pdf")
1046 (when org-e-beamer-column-view-format
1047 (org-entry-put nil
"COLUMNS" org-e-beamer-column-view-format
))
1048 (org-entry-put nil
"BEAMER_col_ALL" org-e-beamer-column-widths
))
1049 (insert "#+LaTeX_CLASS: beamer\n")
1050 (insert "#+LaTeX_CLASS_OPTIONS: [presentation]\n")
1051 (when org-e-beamer-theme
1052 (insert "#+BEAMER_THEME: " org-e-beamer-theme
"\n"))
1053 (when org-e-beamer-column-view-format
1054 (insert "#+COLUMNS: " org-e-beamer-column-view-format
"\n"))
1055 (insert "#+PROPERTY: BEAMER_col_ALL " org-e-beamer-column-widths
"\n")))
1058 (provide 'org-e-beamer
)
1059 ;;; org-e-beamer.el ends here