ox-beamer.el 43 KB

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