diff options
author | Sébastien Delafond <sdelafond@gmail.com> | 2016-11-07 10:41:54 +0100 |
---|---|---|
committer | Sébastien Delafond <sdelafond@gmail.com> | 2016-11-07 10:41:54 +0100 |
commit | 1a7cd65ca362047cd97d4127d49108994baebc6c (patch) | |
tree | f18735f3b77120ef2e91043f2f662b03e47ccbb0 /lisp/ox-beamer.el | |
parent | 55074078ca876273e3fa58ee6838cba90d2b6100 (diff) | |
parent | ec84430cf4e09ba25ec675debdf802bc28111e06 (diff) |
Merge tag 'upstream/9.0'
Upstream version 9.0
Diffstat (limited to 'lisp/ox-beamer.el')
-rw-r--r-- | lisp/ox-beamer.el | 135 |
1 files changed, 57 insertions, 78 deletions
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el index 7afe390..c254c0b 100644 --- a/lisp/ox-beamer.el +++ b/lisp/ox-beamer.el @@ -1,4 +1,4 @@ -;;; ox-beamer.el --- Beamer Back-End for Org Export Engine +;;; ox-beamer.el --- Beamer Back-End for Org Export Engine -*- lexical-binding: t; -*- ;; Copyright (C) 2007-2016 Free Software Foundation, Inc. @@ -29,7 +29,7 @@ ;;; Code: -(eval-when-compile (require 'cl)) +(require 'cl-lib) (require 'ox-latex) ;; Install a default set-up for Beamer export. @@ -140,7 +140,7 @@ You might want to put e.g. \"allowframebreaks=0.9\" here." The format string should have at most one \"%s\"-expression, which is replaced with the subtitle." :group 'org-export-beamer - :version "25.1" + :version "25.2" :package-version '(Org . "8.3") :type '(string :tag "Format string")) @@ -202,19 +202,14 @@ TYPE is a symbol among the following: `defaction' Return ARGUMENT within both square and angular brackets. `option' Return ARGUMENT within square brackets." (if (not (string-match "\\S-" argument)) "" - (case type - (action (if (string-match "\\`<.*>\\'" argument) argument - (format "<%s>" argument))) - (defaction (cond - ((string-match "\\`\\[<.*>\\]\\'" argument) argument) - ((string-match "\\`<.*>\\'" argument) - (format "[%s]" argument)) - ((string-match "\\`\\[\\(.*\\)\\]\\'" argument) - (format "[<%s>]" (match-string 1 argument))) - (t (format "[<%s>]" argument)))) - (option (if (string-match "\\`\\[.*\\]\\'" argument) argument - (format "[%s]" argument))) - (otherwise argument)))) + (cl-case type + (action (format "<%s>" (org-unbracket-string "<" ">" argument))) + (defaction + (format "[<%s>]" + (org-unbracket-string "<" ">" (org-unbracket-string "[" "]" argument)))) + (option (format "[%s]" (org-unbracket-string "[" "]" argument))) + (otherwise (error "Invalid `type' argument to `org-beamer--normalize-argument': %s" + type))))) (defun org-beamer--element-has-overlay-p (element) "Non-nil when ELEMENT has an overlay specified. @@ -224,14 +219,14 @@ Return overlay specification, as a string, or nil." (let ((first-object (car (org-element-contents element)))) (when (eq (org-element-type first-object) 'export-snippet) (let ((value (org-element-property :value first-object))) - (and (string-match "\\`<.*>\\'" value) value))))) + (and (string-prefix-p "<" value) (string-suffix-p ">" value) + value))))) ;;; Define Back-End (org-export-define-derived-backend 'beamer 'latex - :export-block "BEAMER" :menu-entry '(?l 1 ((?B "As LaTeX buffer (Beamer)" org-beamer-export-as-latex) @@ -274,7 +269,7 @@ Return overlay specification, as a string, or nil." ;;;; Bold -(defun org-beamer-bold (bold contents info) +(defun org-beamer-bold (bold contents _info) "Transcode BLOCK object into Beamer code. CONTENTS is the text being bold. INFO is a plist used as a communication channel." @@ -285,7 +280,7 @@ a communication channel." ;;;; Export Block -(defun org-beamer-export-block (export-block contents info) +(defun org-beamer-export-block (export-block _contents _info) "Transcode an EXPORT-BLOCK element into Beamer code. CONTENTS is nil. INFO is a plist used as a communication channel." @@ -295,7 +290,7 @@ channel." ;;;; Export Snippet -(defun org-beamer-export-snippet (export-snippet contents info) +(defun org-beamer-export-snippet (export-snippet _contents info) "Transcode an EXPORT-SNIPPET object into Beamer code. CONTENTS is nil. INFO is a plist used as a communication channel." @@ -331,17 +326,21 @@ channel." INFO is a plist used as a communication channel. The value is either the label specified in \"BEAMER_opt\" -property, or a unique internal label. This function assumes -HEADLINE will be treated as a frame." - (let ((opt (org-element-property :BEAMER_OPT headline))) - (if (and (stringp opt) - (string-match "\\(?:^\\|,\\)label=\\(.*?\\)\\(?:$\\|,\\)" opt)) - (let ((label (match-string 1 opt))) - ;; Strip protective braces, if any. - (if (org-string-match-p "\\`{.*}\\'" label) - (substring label 1 -1) - label)) - (format "sec:%s" (org-export-get-reference headline info))))) +property, the custom ID, if there is one and +`:latex-prefer-user-labels' property has a non nil value, or +a unique internal label. This function assumes HEADLINE will be +treated as a frame." + (cond + ((let ((opt (org-element-property :BEAMER_OPT headline))) + (and (stringp opt) + (string-match "\\(?:^\\|,\\)label=\\(.*?\\)\\(?:$\\|,\\)" opt) + (let ((label (match-string 1 opt))) + (if (string-match-p "\\`{.*}\\'" label) + (substring label 1 -1) + label))))) + ((and (plist-get info :latex-prefer-user-labels) + (org-element-property :CUSTOM_ID headline))) + (t (format "sec:%s" (org-export-get-reference headline info))))) (defun org-beamer--frame-level (headline info) "Return frame level in subtree containing HEADLINE. @@ -448,7 +447,7 @@ used as a communication channel." (let ((label (org-beamer--get-label headline info))) ;; Labels containing colons need to be ;; wrapped within braces. - (format (if (org-string-match-p ":" label) + (format (if (string-match-p ":" label) "label={%s}" "label=%s") label))))))) @@ -560,7 +559,8 @@ used as a communication channel." (let ((action (org-element-property :BEAMER_ACT headline))) (cond ((not action) (list (cons "a" "") (cons "A" "") (cons "R" ""))) - ((string-match "\\`\\[.*\\]\\'" action) + ((and (string-prefix-p "[" action) + (string-suffix-p "]" action)) (list (cons "A" (org-beamer--normalize-argument action 'defaction)) (cons "a" "") @@ -676,7 +676,7 @@ contextual information." (list (cons 'item - (lambda (item c i) + (lambda (item _c _i) (let ((action (let ((first (car (org-element-contents item)))) (and (eq (org-element-type first) 'paragraph) @@ -720,8 +720,7 @@ channel." "Transcode a LINK object into Beamer code. CONTENTS is the description part of the link. INFO is a plist used as a communication channel." - (let ((type (org-element-property :type link)) - (path (org-element-property :path link))) + (let ((type (org-element-property :type link))) (cond ;; Link type is handled by a special function. ((org-export-custom-protocol-maybe link contents 'beamer)) @@ -737,7 +736,7 @@ used as a communication channel." (let ((destination (if (string= type "fuzzy") (org-export-resolve-fuzzy-link link info) (org-export-resolve-id-link link info)))) - (case (org-element-type destination) + (cl-case (org-element-type destination) (headline (let ((label (format "sec-%s" @@ -813,7 +812,7 @@ contextual information." ;;;; Target -(defun org-beamer-target (target contents info) +(defun org-beamer-target (target _contents info) "Transcode a TARGET object into Beamer code. CONTENTS is nil. INFO is a plist holding contextual information." @@ -832,34 +831,14 @@ holding export options." (let ((title (org-export-data (plist-get info :title) info)) (subtitle (org-export-data (plist-get info :subtitle) info))) (concat - ;; 1. Time-stamp. + ;; Time-stamp. (and (plist-get info :time-stamp-file) (format-time-string "%% Created %Y-%m-%d %a %H:%M\n")) - ;; 2. Document class and packages. - (let* ((class (plist-get info :latex-class)) - (class-options (plist-get info :latex-class-options)) - (header (nth 1 (assoc class org-latex-classes))) - (document-class-string - (and (stringp header) - (if (not class-options) header - (replace-regexp-in-string - "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)" - class-options header t nil 1))))) - (if (not document-class-string) - (user-error "Unknown LaTeX class `%s'" class) - (org-latex-guess-babel-language - (org-latex-guess-inputenc - (org-element-normalize-string - (org-splice-latex-header - document-class-string - org-latex-default-packages-alist - org-latex-packages-alist nil - (concat (org-element-normalize-string - (plist-get info :latex-header)) - (org-element-normalize-string - (plist-get info :latex-header-extra)))))) - info))) - ;; 3. Insert themes. + ;; LaTeX compiler + (org-latex--insert-compiler info) + ;; Document class and packages. + (org-latex--make-preamble info) + ;; Insert themes. (let ((format-theme (function (lambda (prop command) @@ -879,11 +858,11 @@ holding export options." (:beamer-inner-theme "\\useinnertheme") (:beamer-outer-theme "\\useoutertheme")) "")) - ;; 4. Possibly limit depth for headline numbering. + ;; Possibly limit depth for headline numbering. (let ((sec-num (plist-get info :section-numbers))) (when (integerp sec-num) (format "\\setcounter{secnumdepth}{%d}\n" sec-num))) - ;; 5. Author. + ;; Author. (let ((author (and (plist-get info :with-author) (let ((auth (plist-get info :author))) (and auth (org-export-data auth info))))) @@ -892,14 +871,14 @@ holding export options." (cond ((and author email (not (string= "" email))) (format "\\author{%s\\thanks{%s}}\n" author email)) ((or author email) (format "\\author{%s}\n" (or author email))))) - ;; 6. Date. + ;; Date. (let ((date (and (plist-get info :with-date) (org-export-get-date info)))) (format "\\date{%s}\n" (org-export-data date info))) - ;; 7. Title + ;; Title (format "\\title{%s}\n" title) (when (org-string-nw-p subtitle) (concat (format (plist-get info :beamer-subtitle-format) subtitle) "\n")) - ;; 8. Beamer-header + ;; Beamer-header (let ((beamer-header (plist-get info :beamer-header))) (when beamer-header (format "%s\n" (plist-get info :beamer-header)))) @@ -907,9 +886,9 @@ holding export options." (let ((template (plist-get info :latex-hyperref-template))) (and (stringp template) (format-spec template (org-latex--format-spec info)))) - ;; 10. Document start. + ;; Document start. "\\begin{document}\n\n" - ;; 11. Title command. + ;; Title command. (org-element-normalize-string (cond ((not (plist-get info :with-title)) nil) ((string= "" title) nil) @@ -918,7 +897,7 @@ holding export options." org-latex-title-command) (format org-latex-title-command title)) (t org-latex-title-command))) - ;; 12. Table of contents. + ;; Table of contents. (let ((depth (plist-get info :with-toc))) (when depth (concat @@ -930,13 +909,13 @@ holding export options." (format "\\setcounter{tocdepth}{%d}\n" depth)) "\\tableofcontents\n" "\\end{frame}\n\n"))) - ;; 13. Document's body. + ;; Document's body. contents - ;; 14. Creator. + ;; Creator. (if (plist-get info :with-creator) (concat (plist-get info :creator) "\n") "") - ;; 15. Document end. + ;; Document end. "\\end{document}"))) @@ -972,7 +951,7 @@ value." (save-excursion (org-back-to-heading t) ;; Filter out Beamer-related tags and install environment tag. - (let ((tags (org-remove-if (lambda (x) (string-match "^B_" x)) + (let ((tags (cl-remove-if (lambda (x) (string-match "^B_" x)) (org-get-tags))) (env-tag (and (org-string-nw-p value) (concat "B_" value)))) (org-set-tags-to (if env-tag (cons env-tag tags) tags)) @@ -1124,7 +1103,7 @@ aid, but the tag does not have any semantic meaning." (let* ((envs (append org-beamer-environments-special org-beamer-environments-extra org-beamer-environments-default)) - (org-tag-alist + (org-current-tag-alist (append '((:startgroup)) (mapcar (lambda (e) (cons (concat "B_" (car e)) (string-to-char (nth 1 e)))) |