ox-beamer.el 43 KB

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