config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

ox-beamer.el (46652B)


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