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
259 :export-block
"BEAMER"
261 ((:beamer-theme
"BEAMER_THEME" nil org-e-beamer-theme
)
262 (:beamer-color-theme
"BEAMER_COLOR_THEME" nil nil t
)
263 (:beamer-font-theme
"BEAMER_FONT_THEME" nil nil t
)
264 (:beamer-inner-theme
"BEAMER_INNER_THEME" nil nil t
)
265 (:beamer-outer-theme
"BEAMER_OUTER_THEME" nil nil t
)
266 (:headline-levels nil
"H" org-e-beamer-frame-level
))
267 :translate-alist
((bold . org-e-beamer-bold
)
268 (export-block . org-e-beamer-export-block
)
269 (export-snippet . org-e-beamer-export-snippet
)
270 (headline . org-e-beamer-headline
)
271 (item . org-e-beamer-item
)
272 (keyword . org-e-beamer-keyword
)
273 (link . org-e-beamer-link
)
274 (plain-list . org-e-beamer-plain-list
)
275 (radio-target . org-e-beamer-radio-target
)
276 (target . org-e-beamer-target
)
277 (template . org-e-beamer-template
)))
281 ;;; Transcode Functions
285 (defun org-e-beamer-bold (bold contents info
)
286 "Transcode BLOCK object into Beamer code.
287 CONTENTS is the text being bold. INFO is a plist used as
288 a communication channel."
289 (format "\\alert%s{%s}"
290 (or (org-e-beamer--element-has-overlay-p bold
) "")
296 (defun org-e-beamer-export-block (export-block contents info
)
297 "Transcode an EXPORT-BLOCK element into Beamer code.
298 CONTENTS is nil. INFO is a plist used as a communication
300 (when (member (org-element-property :type export-block
) '("BEAMER" "LATEX"))
301 (org-remove-indentation (org-element-property :value export-block
))))
306 (defun org-e-beamer-export-snippet (export-snippet contents info
)
307 "Transcode an EXPORT-SNIPPET object into Beamer code.
308 CONTENTS is nil. INFO is a plist used as a communication
310 (let ((backend (org-export-snippet-backend export-snippet
))
311 (value (org-element-property :value export-snippet
)))
312 ;; Only "e-latex" and "e-beamer" snippets are retained.
313 (cond ((eq backend
'e-latex
) value
)
314 ;; Ignore "e-beamer" snippets specifying overlays.
315 ((and (eq backend
'e-beamer
)
316 (or (org-export-get-previous-element export-snippet info
)
317 (not (string-match "\\`<.*>\\'" value
))))
323 ;; The main function to translate an headline is
324 ;; `org-e-beamer-headline'.
326 ;; Depending on the level at which an headline is considered as
327 ;; a frame (given by `org-e-beamer--frame-level'), the headline is
328 ;; either a section (`org-e-beamer--format-section'), a frame
329 ;; (`org-e-beamer--format-frame') or a block
330 ;; (`org-e-beamer--format-block').
332 ;; `org-e-beamer-headline' also takes care of special environments
333 ;; like "ignoreheading", "note", "noteNH" and "appendix".
335 (defun org-e-beamer--frame-level (headline info
)
336 "Return frame level in subtree containing HEADLINE.
337 INFO is a plist used as a communication channel."
339 ;; 1. Look for "frame" environment in parents, starting from the
342 (mapc (lambda (parent)
343 (when (equal (org-element-property :beamer-env parent
) "frame")
344 (throw 'exit
(org-export-get-relative-level parent info
))))
345 (reverse (org-export-get-genealogy headline
)))
347 ;; 2. Look for "frame" environment in HEADLINE.
348 (and (equal (org-element-property :beamer-env headline
) "frame")
349 (org-export-get-relative-level headline info
))
350 ;; 3. Look for "frame" environment in sub-tree.
354 (when (equal (org-element-property :beamer-env hl
) "frame")
355 (org-export-get-relative-level hl info
)))
357 ;; 4. No "frame" environment in tree: use default value.
358 (plist-get info
:headline-levels
)))
360 (defun org-e-beamer--format-section (headline contents info
)
361 "Format HEADLINE as a sectioning part.
362 CONTENTS holds the contents of the headline. INFO is a plist
363 used as a communication channel."
364 ;; Use `e-latex' back-end output, inserting overlay specifications
366 (let ((latex-headline
367 (funcall (cdr (assq 'headline org-e-latex-translate-alist
))
368 headline contents info
))
369 (mode-specs (org-element-property :beamer-act headline
)))
371 (string-match "\\`\\\\\\(.*?\\)\\(?:\\*\\|\\[.*\\]\\)?{"
373 (replace-match (concat (match-string 1 latex-headline
)
374 (format "<%s>" mode-specs
))
375 nil nil latex-headline
1)
378 (defun org-e-beamer--format-frame (headline contents info
)
379 "Format HEADLINE as a frame.
380 CONTENTS holds the contents of the headline. INFO is a plist
381 used as a communication channel."
383 ;; FRAGILEP is non-nil when HEADLINE contains an element
384 ;; among `org-e-beamer-verbatim-elements'.
385 (org-element-map headline org-e-beamer-verbatim-elements
'identity
387 (concat "\\begin{frame}"
388 ;; Overlay specification, if any. If is surrounded by square
389 ;; brackets, consider it as a default specification.
390 (let ((action (org-element-property :beamer-act headline
)))
393 ((string-match "\\`\\[.*\\]\\'" action
)
394 (org-e-beamer--normalize-argument action
'defaction
))
395 (t (org-e-beamer--normalize-argument action
'action
))))
398 ;; Collect options from default value and headline's
399 ;; properties. Also add a label for links.
401 (org-split-string org-e-beamer-frame-default-options
403 (let ((opt (org-element-property :beamer-opt headline
)))
404 (and opt
(org-split-string
405 ;; Remove square brackets if user
407 (and (string-match "^\\[?\\(.*\\)\\]?$" opt
)
408 (match-string 1 opt
))
411 (format "label=sec-%s"
414 (org-export-get-headline-number headline info
)
416 ;; Change options list into a string.
417 (org-e-beamer--normalize-argument
420 (if (or (not fragilep
) (member "fragile" options
)) options
421 (cons "fragile" options
))
426 (org-export-data (org-element-property :title headline
)
429 ;; The following workaround is required in fragile frames
430 ;; as Beamer will append "\par" to the beginning of the
431 ;; contents. So we need to make sure the command is
432 ;; separated from the contents by at least one space. If
433 ;; it isn't, it will create "\parfirst-word" command and
434 ;; remove the first word from the contents in the PDF
436 (if (not fragilep
) contents
437 (replace-regexp-in-string "\\`\n*" "\\& " contents
))
440 (defun org-e-beamer--format-block (headline contents info
)
441 "Format HEADLINE as a block.
442 CONTENTS holds the contents of the headline. INFO is a plist
443 used as a communication channel."
444 (let* ((column-width (org-element-property :beamer-col headline
))
445 ;; Environment defaults to "block" if none is specified and
446 ;; there is no column specification. If there is a column
447 ;; specified but still no explicit environment, ENVIRONMENT
449 (environment (let ((env (org-element-property :beamer-env headline
)))
451 ;; "block" is the fallback environment.
452 ((and (not env
) (not column-width
)) "block")
455 ;; Use specified environment.
456 (t (downcase env
)))))
457 (env-format (when environment
459 (append org-e-beamer-environments-special
460 org-e-beamer-environments-extra
461 org-e-beamer-environments-default
))))
462 (title (org-export-data (org-element-property :title headline
) info
))
463 ;; Start a columns environment when there is no previous
464 ;; headline or the previous headline do not have
465 ;; a BEAMER_column property.
468 (or (org-export-first-sibling-p headline info
)
469 (not (org-element-property
471 (org-export-get-previous-element headline info
))))))
472 ;; Ends a columns environment when there is no next headline
473 ;; or the next headline do not have a BEAMER_column property.
476 (or (org-export-last-sibling-p headline info
)
477 (not (org-element-property
479 (org-export-get-next-element headline info
)))))))
481 (when start-columns-p
"\\begin{columns}\n")
483 (format "\\begin{column}%s{%s}\n"
484 ;; One can specify placement for column only when
485 ;; HEADLINE stands for a column on its own.
486 (if (not environment
) ""
487 (let ((options (org-element-property :beamer-opt headline
)))
489 (org-e-beamer--normalize-argument options
'option
))))
490 (format "%s\\textwidth" column-width
)))
491 ;; Block's opening string.
497 ;; If BEAMER_act property has its value enclosed in square
498 ;; brackets, it is a default overlay specification and
499 ;; overlay specification is empty. Otherwise, it is an
500 ;; overlay specification and the default one is nil.
501 (let ((action (org-element-property :beamer-act headline
)))
503 ((not action
) (list (cons "a" "") (cons "A" "")))
504 ((string-match "\\`\\[.*\\]\\'" action
)
507 (org-e-beamer--normalize-argument action
'defaction
))
512 (org-e-beamer--normalize-argument action
'action
))
516 (org-element-property :beamer-opt headline
)))
518 (org-e-beamer--normalize-argument options
'option
))))
520 (cons "H" (if (equal title
"") "" (format "{%s}" title
)))
521 (cons "U" (if (equal title
"") "" (format "[%s]" title
))))))
524 ;; Block's closing string.
525 (when environment
(concat (nth 3 env-format
) "\n"))
526 (when column-width
"\\end{column}\n")
527 (when end-columns-p
"\\end{columns}"))))
529 (defun org-e-beamer-headline (headline contents info
)
530 "Transcode HEADLINE element into Beamer code.
531 CONTENTS is the contents of the headline. INFO is a plist used
532 as a communication channel."
533 (unless (org-element-property :footnote-section-p headline
)
534 (let ((level (org-export-get-relative-level headline info
))
535 (frame-level (org-e-beamer--frame-level headline info
))
536 (environment (let ((env (org-element-property :beamer-env headline
)))
537 (if (stringp env
) (downcase env
) "block"))))
539 ;; Creation of an appendix is requested.
540 ((equal environment
"appendix")
542 (org-element-property :beamer-act headline
)
544 (make-string (org-element-property :pre-blank headline
) ?
\n)
546 ((equal environment
"ignoreheading")
547 (concat (make-string (org-element-property :pre-blank headline
) ?
\n)
549 ;; HEADLINE is a note.
550 ((member environment
'("note" "noteNH"))
552 (concat (and (equal environment
"note")
555 (org-element-property :title headline
) info
)
557 (org-trim contents
))))
558 ;; HEADLINE is a frame.
559 ((or (equal environment
"frame") (= level frame-level
))
560 (org-e-beamer--format-frame headline contents info
))
561 ;; Regular section, extracted from `org-e-latex-classes'.
562 ((< level frame-level
)
563 (org-e-beamer--format-section headline contents info
))
564 ;; Otherwise, HEADLINE is a block.
565 (t (org-e-beamer--format-block headline contents info
))))))
570 (defun org-e-beamer-item (item contents info
)
571 "Transcode an ITEM element into Beamer code.
572 CONTENTS holds the contents of the item. INFO is a plist holding
573 contextual information."
574 (let ((action (let ((first-element (car (org-element-contents item
))))
575 (and (eq (org-element-type first-element
) 'paragraph
)
576 (org-e-beamer--element-has-overlay-p first-element
))))
577 (output (funcall (cdr (assq 'item org-e-latex-translate-alist
))
578 item contents info
)))
579 (if (not action
) output
580 ;; If the item starts with a paragraph and that paragraph starts
581 ;; with an export snippet specifying an overlay, insert it after
583 (replace-regexp-in-string "\\\\item" (concat "\\\\item" action
) output
))))
588 (defun org-e-beamer-keyword (keyword contents info
)
589 "Transcode a KEYWORD element into Beamer code.
590 CONTENTS is nil. INFO is a plist used as a communication
592 (let ((key (org-element-property :key keyword
))
593 (value (org-element-property :value keyword
)))
594 ;; Handle specifically BEAMER and TOC (headlines only) keywords.
595 ;; Otherwise, fallback to `e-latex' back-end.
597 ((equal key
"BEAMER") value
)
598 ((and (equal key
"TOC") (string-match "\\<headlines\\>" value
))
599 (let ((depth (or (and (string-match "[0-9]+" value
)
600 (string-to-number (match-string 0 value
)))
601 (plist-get info
:with-toc
)))
602 (options (and (string-match "\\[.*?\\]" value
)
603 (match-string 0 value
))))
606 (when (wholenump depth
) (format "\\setcounter{tocdepth}{%s}\n" depth
))
607 "\\tableofcontents" options
"\n"
609 (t (funcall (cdr (assq 'keyword org-e-latex-translate-alist
))
610 keyword contents info
)))))
615 (defun org-e-beamer-link (link contents info
)
616 "Transcode a LINK object into Beamer code.
617 CONTENTS is the description part of the link. INFO is a plist
618 used as a communication channel."
619 (let ((type (org-element-property :type link
))
620 (path (org-element-property :path link
)))
621 ;; Use \hyperlink command for all internal links.
623 ((equal type
"radio")
624 (let ((destination (org-export-resolve-radio-link link info
)))
626 (format "\\hyperlink%s{%s}{%s}"
627 (or (org-e-beamer--element-has-overlay-p link
) "")
628 (org-export-solidify-link-text path
)
629 (org-export-data (org-element-contents destination
) info
)))))
630 ((and (member type
'("custom-id" "fuzzy" "id"))
631 (let ((destination (if (string= type
"fuzzy")
632 (org-export-resolve-fuzzy-link link info
)
633 (org-export-resolve-id-link link info
))))
634 (case (org-element-type destination
)
640 (org-export-get-headline-number
643 (if (and (plist-get info
:section-numbers
) (not contents
))
644 (format "\\ref{%s}" label
)
645 (format "\\hyperlink%s{%s}{%s}"
646 (or (org-e-beamer--element-has-overlay-p link
) "")
650 (let ((path (org-export-solidify-link-text path
)))
651 (if (not contents
) (format "\\ref{%s}" path
)
652 (format "\\hyperlink%s{%s}{%s}"
653 (or (org-e-beamer--element-has-overlay-p link
) "")
656 ;; Otherwise, use `e-latex' back-end.
657 (t (funcall (cdr (assq 'link org-e-latex-translate-alist
))
658 link contents info
)))))
663 ;; Plain lists support `:overlay' (for any type), `:template' (for
664 ;; ordered lists only) and `:long-text' (for description lists only)
667 (defun org-e-beamer-plain-list (plain-list contents info
)
668 "Transcode a PLAIN-LIST element into Beamer code.
669 CONTENTS is the contents of the list. INFO is a plist holding
670 contextual information."
671 (let* ((type (org-element-property :type plain-list
))
672 (attributes (org-export-read-attribute :attr_beamer plain-list
))
673 (latex-type (cond ((eq type
'ordered
) "enumerate")
674 ((eq type
'descriptive
) "description")
676 (org-e-latex--wrap-label
678 (format "\\begin{%s}%s%s\n%s\\end{%s}"
680 ;; Default overlay specification, if any.
681 (let ((overlay (plist-get attributes
:overlay
)))
683 (org-e-beamer--normalize-argument overlay
'defaction
)))
684 ;; Second optional argument depends on the list type.
687 (let ((template (plist-get attributes
:template
)))
688 (if (not template
) ""
689 (org-e-beamer--normalize-argument template
'option
))))
691 (let ((long-text (plist-get attributes
:long-text
)))
692 (if (not long-text
) ""
693 (org-e-beamer--normalize-argument long-text
'option
))))
694 ;; There's no second argument for un-ordered lists.
696 ;; Eventually insert contents and close environment.
703 (defun org-e-beamer-radio-target (radio-target text info
)
704 "Transcode a RADIO-TARGET object into Beamer code.
705 TEXT is the text of the target. INFO is a plist holding
706 contextual information."
707 (format "\\hypertarget%s{%s}{%s}"
708 (or (org-e-beamer--element-has-overlay-p radio-target
) "")
709 (org-export-solidify-link-text
710 (org-element-property :value radio-target
))
716 (defun org-e-beamer-target (target contents info
)
717 "Transcode a TARGET object into Beamer code.
718 CONTENTS is nil. INFO is a plist holding contextual
720 (format "\\hypertarget{%s}{}"
721 (org-export-solidify-link-text (org-element-property :value target
))))
726 ;; Template used is similar to the one used in `e-latex' back-end,
727 ;; excepted for the table of contents and Beamer themes.
729 (defun org-e-beamer-template (contents info
)
730 "Return complete document string after Beamer conversion.
731 CONTENTS is the transcoded contents string. INFO is a plist
732 holding export options."
733 (let ((title (org-export-data (plist-get info
:title
) info
)))
736 (and (plist-get info
:time-stamp-file
)
737 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
738 ;; 2. Document class and packages.
739 (let ((class (plist-get info
:latex-class
))
740 (class-options (plist-get info
:latex-class-options
)))
741 (org-element-normalize-string
742 (let* ((header (nth 1 (assoc class org-e-latex-classes
)))
743 (document-class-string
744 (and (stringp header
)
746 (replace-regexp-in-string
747 "^[ \t]*\\\\documentclass\\(\\[.*?\\]\\)"
748 class-options header t nil
1)
750 (when document-class-string
751 (org-e-latex--guess-babel-language
752 (org-e-latex--guess-inputenc
753 (org-splice-latex-header
754 document-class-string
755 org-export-latex-default-packages-alist
; defined in org.el
756 org-export-latex-packages-alist nil
; defined in org.el
757 (plist-get info
:latex-header-extra
)))
762 (lambda (prop command
)
763 (let ((theme (plist-get info prop
)))
766 (if (not (string-match "\\[.*\\]" theme
))
767 (format "{%s}\n" theme
)
769 (match-string 0 theme
)
771 (replace-match "" nil nil theme
)))))))))))
772 (mapconcat (lambda (args) (apply format-theme args
))
773 '((:beamer-theme
"\\usetheme")
774 (:beamer-color-theme
"\\usecolortheme")
775 (:beamer-font-theme
"\\usefonttheme")
776 (:beamer-inner-theme
"\\useinnertheme")
777 (:beamer-outer-theme
"\\useoutertheme"))
779 ;; 4. Possibly limit depth for headline numbering.
780 (let ((sec-num (plist-get info
:section-numbers
)))
781 (when (integerp sec-num
)
782 (format "\\setcounter{secnumdepth}{%d}\n" sec-num
)))
784 (let ((author (and (plist-get info
:with-author
)
785 (let ((auth (plist-get info
:author
)))
786 (and auth
(org-export-data auth info
)))))
787 (email (and (plist-get info
:with-email
)
788 (org-export-data (plist-get info
:email
) info
))))
789 (cond ((and author email
(not (string= "" email
)))
790 (format "\\author{%s\\thanks{%s}}\n" author email
))
791 (author (format "\\author{%s}\n" author
))
794 (format "\\date{%s}\n" (org-export-data (plist-get info
:date
) info
))
796 (format "\\title{%s}\n" title
)
797 ;; 8. Hyperref options.
798 (format "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={%s}}\n"
799 (or (plist-get info
:keywords
) "")
800 (or (plist-get info
:description
) "")
801 (if (not (plist-get info
:with-creator
)) ""
802 (plist-get info
:creator
)))
803 ;; 9. Document start.
804 "\\begin{document}\n\n"
805 ;; 10. Title command.
806 (org-element-normalize-string
807 (cond ((string= "" title
) nil
)
808 ((not (stringp org-e-latex-title-command
)) nil
)
809 ((string-match "\\(?:[^%]\\|^\\)%s"
810 org-e-latex-title-command
)
811 (format org-e-latex-title-command title
))
812 (t org-e-latex-title-command
)))
813 ;; 11. Table of contents.
814 (let ((depth (plist-get info
:with-toc
)))
817 (format "\\begin{frame}%s{%s}\n"
818 (org-e-beamer--normalize-argument
819 org-e-beamer-outline-frame-options
'option
)
820 org-e-beamer-outline-frame-title
)
821 (when (wholenump depth
)
822 (format "\\setcounter{tocdepth}{%d}\n" depth
))
823 "\\tableofcontents\n"
824 "\\end{frame}\n\n")))
825 ;; 12. Document's body.
828 (let ((creator-info (plist-get info
:with-creator
)))
830 ((not creator-info
) "")
831 ((eq creator-info
'comment
)
832 (format "%% %s\n" (plist-get info
:creator
)))
833 (t (concat (plist-get info
:creator
) "\n"))))
842 (defvar org-e-beamer-mode-map
(make-sparse-keymap)
843 "The keymap for `org-e-beamer-mode'.")
844 (define-key org-e-beamer-mode-map
"\C-c\C-b" 'org-e-beamer-select-environment
)
847 (define-minor-mode org-e-beamer-mode
848 "Support for editing Beamer oriented Org mode files."
849 nil
" Bm" 'org-e-beamer-mode-map
)
851 (when (fboundp 'font-lock-add-keywords
)
852 (font-lock-add-keywords
854 '((":\\(B_[a-z]+\\|BMCOL\\):" 1 'org-e-beamer-tag prepend
))
857 (defface org-e-beamer-tag
'((t (:box
(:line-width
1 :color grey40
))))
858 "The special face for beamer tags."
859 :group
'org-export-e-beamer
)
861 (defun org-e-beamer-property-changed (property value
)
862 "Track the BEAMER_env property with tags.
863 PROPERTY is the name of the modified property. VALUE is its new
866 ((equal property
"BEAMER_env")
868 (org-back-to-heading t
)
869 (let ((tags (org-get-tags)))
870 (setq tags
(delq nil
(mapcar (lambda (x)
871 (if (string-match "^B_" x
) nil x
))
873 (org-set-tags-to tags
))
874 (when (org-string-nw-p value
) (org-toggle-tag (concat "B_" value
) 'on
))))
875 ((equal property
"BEAMER_col")
876 (org-toggle-tag "BMCOL" (if (org-string-nw-p value
) 'on
'off
)))))
878 (add-hook 'org-property-changed-functions
'org-e-beamer-property-changed
)
880 (defun org-e-beamer-allowed-property-values (property)
881 "Supply allowed values for PROPERTY."
883 ((and (equal property
"BEAMER_env")
884 (not (org-entry-get nil
(concat property
"_ALL") 'inherit
)))
885 ;; If no allowed values for BEAMER_env have been defined,
886 ;; supply all defined environments
887 (mapcar 'car
(append org-e-beamer-environments-special
888 org-e-beamer-environments-extra
889 org-e-beamer-environments-default
)))
890 ((and (equal property
"BEAMER_col")
891 (not (org-entry-get nil
(concat property
"_ALL") 'inherit
)))
892 ;; If no allowed values for BEAMER_col have been defined,
894 (org-split-string org-e-beamer-column-widths
" "))))
896 (add-hook 'org-property-allowed-value-functions
897 'org-e-beamer-allowed-property-values
)
904 (defun org-e-beamer-export-as-latex
905 (&optional subtreep visible-only body-only ext-plist
)
906 "Export current buffer as a Beamer buffer.
908 If narrowing is active in the current buffer, only export its
911 If a region is active, export that region.
913 When optional argument SUBTREEP is non-nil, export the sub-tree
914 at point, extracting information from the headline properties
917 When optional argument VISIBLE-ONLY is non-nil, don't export
918 contents of hidden elements.
920 When optional argument BODY-ONLY is non-nil, only write code
921 between \"\\begin{document}\" and \"\\end{document}\".
923 EXT-PLIST, when provided, is a property list with external
924 parameters overriding Org default settings, but still inferior to
927 Export is done in a buffer named \"*Org E-BEAMER Export*\", which
928 will be displayed when `org-export-show-temporary-export-buffer'
931 (let ((outbuf (org-export-to-buffer
932 'e-beamer
"*Org E-BEAMER Export*"
933 subtreep visible-only body-only ext-plist
)))
934 (with-current-buffer outbuf
(LaTeX-mode))
935 (when org-export-show-temporary-export-buffer
936 (switch-to-buffer-other-window outbuf
))))
939 (defun org-e-beamer-export-to-latex
940 (&optional subtreep visible-only body-only ext-plist pub-dir
)
941 "Export current buffer as a Beamer presentation (tex).
943 If narrowing is active in the current buffer, only export its
946 If a region is active, export that region.
948 When optional argument SUBTREEP is non-nil, export the sub-tree
949 at point, extracting information from the headline properties
952 When optional argument VISIBLE-ONLY is non-nil, don't export
953 contents of hidden elements.
955 When optional argument BODY-ONLY is non-nil, only write code
956 between \"\\begin{document}\" and \"\\end{document}\".
958 EXT-PLIST, when provided, is a property list with external
959 parameters overriding Org default settings, but still inferior to
962 When optional argument PUB-DIR is set, use it as the publishing
965 Return output file's name."
967 (let ((outfile (org-export-output-file-name ".tex" subtreep pub-dir
)))
969 'e-beamer outfile subtreep visible-only body-only ext-plist
)))
972 (defun org-e-beamer-export-to-pdf
973 (&optional subtreep visible-only body-only ext-plist pub-dir
)
974 "Export current buffer as a Beamer presentation (PDF).
976 If narrowing is active in the current buffer, only export its
979 If a region is active, export that region.
981 When optional argument SUBTREEP is non-nil, export the sub-tree
982 at point, extracting information from the headline properties
985 When optional argument VISIBLE-ONLY is non-nil, don't export
986 contents of hidden elements.
988 When optional argument BODY-ONLY is non-nil, only write code
989 between \"\\begin{document}\" and \"\\end{document}\".
991 EXT-PLIST, when provided, is a property list with external
992 parameters overriding Org default settings, but still inferior to
995 When optional argument PUB-DIR is set, use it as the publishing
998 Return PDF file's name."
1000 (org-e-latex-compile
1001 (org-e-beamer-export-to-latex
1002 subtreep visible-only body-only ext-plist pub-dir
)))
1005 (defun org-e-beamer-select-environment ()
1006 "Select the environment to be used by beamer for this entry.
1007 While this uses (for convenience) a tag selection interface, the
1008 result of this command will be that the BEAMER_env *property* of
1011 In addition to this, the command will also set a tag as a visual
1012 aid, but the tag does not have any semantic meaning."
1014 ;; Make sure `org-e-beamer-environments-special' has a higher
1015 ;; priority than `org-e-beamer-environments-extra'.
1016 (let* ((envs (append org-e-beamer-environments-special
1017 org-e-beamer-environments-extra
1018 org-e-beamer-environments-default
))
1020 (append '((:startgroup
))
1021 (mapcar (lambda (e) (cons (concat "B_" (car e
))
1022 (string-to-char (nth 1 e
))))
1026 (org-fast-tag-selection-single-key t
))
1028 (let ((tags (or (ignore-errors (org-get-tags-string)) "")))
1030 ((eq org-last-tag-selection-key ?|
)
1031 (if (string-match ":BMCOL:" tags
)
1032 (org-set-property "BEAMER_col" (read-string "Column width: "))
1033 (org-delete-property "BEAMER_col")))
1034 ((string-match (concat ":B_\\("
1035 (mapconcat 'car envs
"\\|")
1038 (org-entry-put nil
"BEAMER_env" (match-string 1 tags
)))
1039 (t (org-entry-delete nil
"BEAMER_env"))))))
1042 (defun org-e-beamer-insert-options-template (&optional kind
)
1043 "Insert a settings template, to make sure users do this right."
1045 (message "Current [s]ubtree or [g]lobal?")
1046 (if (eq (read-char-exclusive) ?g
) (list 'global
)
1048 (if (eq kind
'subtree
)
1050 (org-back-to-heading t
)
1052 (org-entry-put nil
"LaTeX_CLASS" "beamer")
1053 (org-entry-put nil
"LaTeX_CLASS_OPTIONS" "[presentation]")
1054 (org-entry-put nil
"EXPORT_FILE_NAME" "presentation.pdf")
1055 (when org-e-beamer-column-view-format
1056 (org-entry-put nil
"COLUMNS" org-e-beamer-column-view-format
))
1057 (org-entry-put nil
"BEAMER_col_ALL" org-e-beamer-column-widths
))
1058 (insert "#+LaTeX_CLASS: beamer\n")
1059 (insert "#+LaTeX_CLASS_OPTIONS: [presentation]\n")
1060 (when org-e-beamer-theme
1061 (insert "#+BEAMER_THEME: " org-e-beamer-theme
"\n"))
1062 (when org-e-beamer-column-view-format
1063 (insert "#+COLUMNS: " org-e-beamer-column-view-format
"\n"))
1064 (insert "#+PROPERTY: BEAMER_col_ALL " org-e-beamer-column-widths
"\n")))
1067 (provide 'org-e-beamer
)
1068 ;;; org-e-beamer.el ends here