Function: org-beamer--format-frame

org-beamer--format-frame is a byte-compiled function defined in ox-beamer.el.gz.

Signature

(org-beamer--format-frame HEADLINE CONTENTS INFO)

Documentation

Format HEADLINE as a frame.

CONTENTS holds the contents of the headline. INFO is a plist used as a communication channel.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-beamer.el.gz
(defun org-beamer--format-frame (headline contents info)
  "Format HEADLINE as a frame.
CONTENTS holds the contents of the headline.  INFO is a plist
used as a communication channel."
  (let* ((fragilep
	  ;; FRAGILEP is non-nil when HEADLINE contains an element
	  ;; among `org-beamer-verbatim-elements'.
	  (org-element-map headline org-beamer-verbatim-elements 'identity
			   info 'first-match))
         ;; If FRAGILEP is non-nil and CONTENTS contains an occurrence
         ;; of \begin{frame} or \end{frame}, then set the FRAME
         ;; environment to be `org-beamer-frame-environment';
         ;; otherwise, use "frame". If the selected environment is not
         ;; "frame", then add the property :beamer-define-frame to
         ;; INFO and set it to t.
         (frame (let ((selection
                       (or (and fragilep
                                (or (string-match-p "\\\\begin{frame}" contents)
                                    (string-match-p "\\\\end{frame}" contents))
                                org-beamer-frame-environment)
                           "frame")))
                  (unless (string= selection "frame")
                    (setq info (plist-put info :beamer-define-frame t)))
                  selection)))
    (concat "\\begin{" frame "}"
	    ;; Overlay specification, if any. When surrounded by
	    ;; square brackets, consider it as a default
	    ;; specification.
	    (let ((action (org-element-property :BEAMER_ACT headline)))
	      (cond
	       ((not action) "")
	       ((string-match "\\`\\[.*\\]\\'" action )
		(org-beamer--normalize-argument action 'defaction))
	       (t (org-beamer--normalize-argument action 'action))))
	    ;; Options, if any.
	    (let* ((beamer-opt (org-element-property :BEAMER_OPT headline))
		   (options
		    ;; Collect nonempty options from default value and
		    ;; headline's properties.
		    (cl-remove-if-not #'org-string-nw-p
                                      (append
                                       (org-split-string
                                        (plist-get info :beamer-frame-default-options) ",")
                                       (and beamer-opt
                                            (org-split-string
                                             ;; Remove square brackets if user provided
                                             ;; them.
                                             (and (string-match "^\\[?\\(.*\\)\\]?$" beamer-opt)
                                                  (match-string 1 beamer-opt))
                                             ",")))))
		   (fragile
		    ;; Add "fragile" option if necessary.
		    (and fragilep
			 (not (member "fragile" options))
			 (list "fragile")))
		   (label
		    ;; Provide an automatic label for the frame unless
		    ;; the user specified one.  Also refrain from
		    ;; labeling `allowframebreaks' frames; this is not
		    ;; allowed by Beamer.
		    (and (not (member "allowframebreaks" options))
			 (not (cl-some (lambda (s) (string-match-p "^label=" s))
				       options))
			 (list
			  (let ((label (org-beamer--get-label headline info)))
			    ;; Labels containing colons need to be
			    ;; wrapped within braces.
			    (format (if (string-match-p ":" label)
					"label={%s}"
				      "label=%s")
				    label))))))
	      ;; Change options list into a string.
	      (org-beamer--normalize-argument
	       (mapconcat #'identity (append label fragile options) ",")
	       'option))
	    ;; Title.
	    (let ((env (org-element-property :BEAMER_ENV headline)))
	      (format "{%s}"
		      (if (and env (equal (downcase env) "fullframe")) ""
			(org-export-data
			 (org-element-property :title headline) info))))
	    "\n"
	    ;; The following workaround is required in fragile frames
	    ;; as Beamer will append "\par" to the beginning of the
	    ;; contents.  So we need to make sure the command is
	    ;; separated from the contents by at least one space.  If
	    ;; it isn't, it will create "\parfirst-word" command and
	    ;; remove the first word from the contents in the PDF
	    ;; output.
	    (if (not fragilep) contents
	      (replace-regexp-in-string "\\`\n*" "\\& " (or contents "")))
	    "\\end{" frame "}")))