ox-beamer.el 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. ;;; ox-beamer.el --- Beamer Back-End for Org Export Engine
  2. ;; Copyright (C) 2007-2015 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. (eval-when-compile (require 'cl))
  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. (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. :export-block "BEAMER"
  191. :menu-entry
  192. '(?l 1
  193. ((?B "As LaTeX buffer (Beamer)" org-beamer-export-as-latex)
  194. (?b "As LaTeX file (Beamer)" org-beamer-export-to-latex)
  195. (?P "As PDF file (Beamer)" org-beamer-export-to-pdf)
  196. (?O "As PDF file and open (Beamer)"
  197. (lambda (a s v b)
  198. (if a (org-beamer-export-to-pdf t s v b)
  199. (org-open-file (org-beamer-export-to-pdf nil s v b)))))))
  200. :options-alist
  201. '((:headline-levels nil "H" org-beamer-frame-level)
  202. (:latex-class "LATEX_CLASS" nil "beamer" t)
  203. (:beamer-subtitle-format nil nil org-beamer-subtitle-format)
  204. (:beamer-column-view-format "COLUMNS" nil org-beamer-column-view-format)
  205. (:beamer-theme "BEAMER_THEME" nil org-beamer-theme)
  206. (:beamer-color-theme "BEAMER_COLOR_THEME" nil nil t)
  207. (:beamer-font-theme "BEAMER_FONT_THEME" nil nil t)
  208. (:beamer-inner-theme "BEAMER_INNER_THEME" nil nil t)
  209. (:beamer-outer-theme "BEAMER_OUTER_THEME" nil nil t)
  210. (:beamer-header "BEAMER_HEADER" nil nil newline)
  211. (:beamer-environments-extra nil nil org-beamer-environments-extra)
  212. (:beamer-frame-default-options nil nil org-beamer-frame-default-options)
  213. (:beamer-outline-frame-options nil nil org-beamer-outline-frame-options)
  214. (:beamer-outline-frame-title nil nil org-beamer-outline-frame-title))
  215. :translate-alist '((bold . org-beamer-bold)
  216. (export-block . org-beamer-export-block)
  217. (export-snippet . org-beamer-export-snippet)
  218. (headline . org-beamer-headline)
  219. (item . org-beamer-item)
  220. (keyword . org-beamer-keyword)
  221. (link . org-beamer-link)
  222. (plain-list . org-beamer-plain-list)
  223. (radio-target . org-beamer-radio-target)
  224. (target . org-beamer-target)
  225. (template . org-beamer-template)))
  226. ;;; Transcode Functions
  227. ;;;; Bold
  228. (defun org-beamer-bold (bold contents info)
  229. "Transcode BLOCK object into Beamer code.
  230. CONTENTS is the text being bold. INFO is a plist used as
  231. a communication channel."
  232. (format "\\alert%s{%s}"
  233. (or (org-beamer--element-has-overlay-p bold) "")
  234. contents))
  235. ;;;; Export Block
  236. (defun org-beamer-export-block (export-block contents info)
  237. "Transcode an EXPORT-BLOCK element into Beamer code.
  238. CONTENTS is nil. INFO is a plist used as a communication
  239. channel."
  240. (when (member (org-element-property :type export-block) '("BEAMER" "LATEX"))
  241. (org-remove-indentation (org-element-property :value export-block))))
  242. ;;;; Export Snippet
  243. (defun org-beamer-export-snippet (export-snippet contents info)
  244. "Transcode an EXPORT-SNIPPET object into Beamer code.
  245. CONTENTS is nil. INFO is a plist used as a communication
  246. channel."
  247. (let ((backend (org-export-snippet-backend export-snippet))
  248. (value (org-element-property :value export-snippet)))
  249. ;; Only "latex" and "beamer" snippets are retained.
  250. (cond ((eq backend 'latex) value)
  251. ;; Ignore "beamer" snippets specifying overlays.
  252. ((and (eq backend 'beamer)
  253. (or (org-export-get-previous-element export-snippet info)
  254. (not (string-match "\\`<.*>\\'" value))))
  255. value))))
  256. ;;;; Headline
  257. ;;
  258. ;; The main function to translate a headline is
  259. ;; `org-beamer-headline'.
  260. ;;
  261. ;; Depending on the level at which a headline is considered as
  262. ;; a frame (given by `org-beamer--frame-level'), the headline is
  263. ;; either a section (`org-beamer--format-section'), a frame
  264. ;; (`org-beamer--format-frame') or a block
  265. ;; (`org-beamer--format-block').
  266. ;;
  267. ;; `org-beamer-headline' also takes care of special environments
  268. ;; like "ignoreheading", "note", "noteNH", "appendix" and
  269. ;; "againframe".
  270. (defun org-beamer--get-label (headline info)
  271. "Return label for HEADLINE, as a string.
  272. INFO is a plist used as a communication channel.
  273. The value is either the label specified in \"BEAMER_opt\"
  274. property, or a fallback value built from headline's number. This
  275. function assumes HEADLINE will be treated as a frame."
  276. (let ((opt (org-element-property :BEAMER_OPT headline)))
  277. (if (and (stringp opt)
  278. (string-match "\\(?:^\\|,\\)label=\\(.*?\\)\\(?:$\\|,\\)" opt))
  279. (match-string 1 opt)
  280. (format "{sec:%s}" (org-export-get-reference headline info)))))
  281. (defun org-beamer--frame-level (headline info)
  282. "Return frame level in subtree containing HEADLINE.
  283. INFO is a plist used as a communication channel."
  284. (or
  285. ;; 1. Look for "frame" environment in parents, starting from the
  286. ;; farthest.
  287. (catch 'exit
  288. (dolist (parent (nreverse (org-element-lineage headline)))
  289. (let ((env (org-element-property :BEAMER_ENV parent)))
  290. (when (and env (member-ignore-case env '("frame" "fullframe")))
  291. (throw 'exit (org-export-get-relative-level parent info))))))
  292. ;; 2. Look for "frame" environment in HEADLINE.
  293. (let ((env (org-element-property :BEAMER_ENV headline)))
  294. (and env (member-ignore-case env '("frame" "fullframe"))
  295. (org-export-get-relative-level headline info)))
  296. ;; 3. Look for "frame" environment in sub-tree.
  297. (org-element-map headline 'headline
  298. (lambda (hl)
  299. (let ((env (org-element-property :BEAMER_ENV hl)))
  300. (when (and env (member-ignore-case env '("frame" "fullframe")))
  301. (org-export-get-relative-level hl info))))
  302. info 'first-match)
  303. ;; 4. No "frame" environment in tree: use default value.
  304. (plist-get info :headline-levels)))
  305. (defun org-beamer--format-section (headline contents info)
  306. "Format HEADLINE as a sectioning part.
  307. CONTENTS holds the contents of the headline. INFO is a plist
  308. used as a communication channel."
  309. (let ((latex-headline
  310. (org-export-with-backend
  311. ;; We create a temporary export back-end which behaves the
  312. ;; same as current one, but adds "\protect" in front of the
  313. ;; output of some objects.
  314. (org-export-create-backend
  315. :parent 'latex
  316. :transcoders
  317. (let ((protected-output
  318. (function
  319. (lambda (object contents info)
  320. (let ((code (org-export-with-backend
  321. 'beamer object contents info)))
  322. (if (org-string-nw-p code) (concat "\\protect" code)
  323. code))))))
  324. (mapcar #'(lambda (type) (cons type protected-output))
  325. '(bold footnote-reference italic strike-through timestamp
  326. underline))))
  327. headline
  328. contents
  329. info))
  330. (mode-specs (org-element-property :BEAMER_ACT headline)))
  331. (if (and mode-specs
  332. (string-match "\\`\\\\\\(.*?\\)\\(?:\\*\\|\\[.*\\]\\)?{"
  333. latex-headline))
  334. ;; Insert overlay specifications.
  335. (replace-match (concat (match-string 1 latex-headline)
  336. (format "<%s>" mode-specs))
  337. nil nil latex-headline 1)
  338. latex-headline)))
  339. (defun org-beamer--format-frame (headline contents info)
  340. "Format HEADLINE as a frame.
  341. CONTENTS holds the contents of the headline. INFO is a plist
  342. used as a communication channel."
  343. (let ((fragilep
  344. ;; FRAGILEP is non-nil when HEADLINE contains an element
  345. ;; among `org-beamer-verbatim-elements'.
  346. (org-element-map headline org-beamer-verbatim-elements 'identity
  347. info 'first-match)))
  348. (concat "\\begin{frame}"
  349. ;; Overlay specification, if any. When surrounded by
  350. ;; square brackets, consider it as a default
  351. ;; specification.
  352. (let ((action (org-element-property :BEAMER_ACT headline)))
  353. (cond
  354. ((not action) "")
  355. ((string-match "\\`\\[.*\\]\\'" action )
  356. (org-beamer--normalize-argument action 'defaction))
  357. (t (org-beamer--normalize-argument action 'action))))
  358. ;; Options, if any.
  359. (let* ((beamer-opt (org-element-property :BEAMER_OPT headline))
  360. (options
  361. ;; Collect options from default value and headline's
  362. ;; properties. Also add a label for links.
  363. (append
  364. (org-split-string
  365. (plist-get info :beamer-frame-default-options) ",")
  366. (and beamer-opt
  367. (org-split-string
  368. ;; Remove square brackets if user provided
  369. ;; them.
  370. (and (string-match "^\\[?\\(.*\\)\\]?$" beamer-opt)
  371. (match-string 1 beamer-opt))
  372. ","))
  373. ;; Provide an automatic label for the frame
  374. ;; unless the user specified one. Also refrain
  375. ;; from labeling `allowframebreaks' frames; this
  376. ;; is not allowed by beamer.
  377. (unless (and beamer-opt
  378. (or (string-match "\\(^\\|,\\)label=" beamer-opt)
  379. (string-match "allowframebreaks" beamer-opt)))
  380. (list
  381. (format "label=%s"
  382. (org-beamer--get-label headline info)))))))
  383. ;; Change options list into a string.
  384. (org-beamer--normalize-argument
  385. (mapconcat
  386. 'identity
  387. (if (or (not fragilep) (member "fragile" options)) options
  388. (cons "fragile" options))
  389. ",")
  390. 'option))
  391. ;; Title.
  392. (let ((env (org-element-property :BEAMER_ENV headline)))
  393. (format "{%s}"
  394. (if (and env (equal (downcase env) "fullframe")) ""
  395. (org-export-data
  396. (org-element-property :title headline) info))))
  397. "\n"
  398. ;; The following workaround is required in fragile frames
  399. ;; as Beamer will append "\par" to the beginning of the
  400. ;; contents. So we need to make sure the command is
  401. ;; separated from the contents by at least one space. If
  402. ;; it isn't, it will create "\parfirst-word" command and
  403. ;; remove the first word from the contents in the PDF
  404. ;; output.
  405. (if (not fragilep) contents
  406. (replace-regexp-in-string "\\`\n*" "\\& " (or contents "")))
  407. "\\end{frame}")))
  408. (defun org-beamer--format-block (headline contents info)
  409. "Format HEADLINE as a block.
  410. CONTENTS holds the contents of the headline. INFO is a plist
  411. used as a communication channel."
  412. (let* ((column-width (org-element-property :BEAMER_COL headline))
  413. ;; ENVIRONMENT defaults to "block" if none is specified and
  414. ;; there is no column specification. If there is a column
  415. ;; specified but still no explicit environment, ENVIRONMENT
  416. ;; is "column".
  417. (environment (let ((env (org-element-property :BEAMER_ENV headline)))
  418. (cond
  419. ;; "block" is the fallback environment.
  420. ((and (not env) (not column-width)) "block")
  421. ;; "column" only.
  422. ((not env) "column")
  423. ;; Use specified environment.
  424. (t env))))
  425. (raw-title (org-element-property :raw-value headline))
  426. (env-format
  427. (cond ((member environment '("column" "columns")) nil)
  428. ((assoc environment
  429. (append (plist-get info :beamer-environments-extra)
  430. org-beamer-environments-default)))
  431. (t (user-error "Wrong block type at a headline named \"%s\""
  432. raw-title))))
  433. (title (org-export-data (org-element-property :title headline) info))
  434. (raw-options (org-element-property :BEAMER_OPT headline))
  435. (options (if raw-options
  436. (org-beamer--normalize-argument raw-options 'option)
  437. ""))
  438. ;; Start a "columns" environment when explicitly requested or
  439. ;; when there is no previous headline or the previous
  440. ;; headline do not have a BEAMER_column property.
  441. (parent-env (org-element-property
  442. :BEAMER_ENV (org-export-get-parent-headline headline)))
  443. (start-columns-p
  444. (or (equal environment "columns")
  445. (and column-width
  446. (not (and parent-env
  447. (equal (downcase parent-env) "columns")))
  448. (or (org-export-first-sibling-p headline info)
  449. (not (org-element-property
  450. :BEAMER_COL
  451. (org-export-get-previous-element
  452. headline info)))))))
  453. ;; End the "columns" environment when explicitly requested or
  454. ;; when there is no next headline or the next headline do not
  455. ;; have a BEAMER_column property.
  456. (end-columns-p
  457. (or (equal environment "columns")
  458. (and column-width
  459. (not (and parent-env
  460. (equal (downcase parent-env) "columns")))
  461. (or (org-export-last-sibling-p headline info)
  462. (not (org-element-property
  463. :BEAMER_COL
  464. (org-export-get-next-element headline info))))))))
  465. (concat
  466. (when start-columns-p
  467. ;; Column can accept options only when the environment is
  468. ;; explicitly defined.
  469. (if (not (equal environment "columns")) "\\begin{columns}\n"
  470. (format "\\begin{columns}%s\n" options)))
  471. (when column-width
  472. (format "\\begin{column}%s{%s}\n"
  473. ;; One can specify placement for column only when
  474. ;; HEADLINE stands for a column on its own.
  475. (if (equal environment "column") options "")
  476. (format "%s\\columnwidth" column-width)))
  477. ;; Block's opening string.
  478. (when (nth 2 env-format)
  479. (concat
  480. (org-fill-template
  481. (nth 2 env-format)
  482. (nconc
  483. ;; If BEAMER_act property has its value enclosed in square
  484. ;; brackets, it is a default overlay specification and
  485. ;; overlay specification is empty. Otherwise, it is an
  486. ;; overlay specification and the default one is nil.
  487. (let ((action (org-element-property :BEAMER_ACT headline)))
  488. (cond
  489. ((not action) (list (cons "a" "") (cons "A" "") (cons "R" "")))
  490. ((string-match "\\`\\[.*\\]\\'" action)
  491. (list
  492. (cons "A" (org-beamer--normalize-argument action 'defaction))
  493. (cons "a" "")
  494. (cons "R" action)))
  495. (t
  496. (list (cons "a" (org-beamer--normalize-argument action 'action))
  497. (cons "A" "")
  498. (cons "R" action)))))
  499. (list (cons "o" options)
  500. (cons "O" (or raw-options ""))
  501. (cons "h" title)
  502. (cons "r" raw-title)
  503. (cons "H" (if (equal raw-title "") ""
  504. (format "{%s}" raw-title)))
  505. (cons "U" (if (equal raw-title "") ""
  506. (format "[%s]" raw-title))))))
  507. "\n"))
  508. contents
  509. ;; Block's closing string, if any.
  510. (and (nth 3 env-format) (concat (nth 3 env-format) "\n"))
  511. (when column-width "\\end{column}\n")
  512. (when end-columns-p "\\end{columns}"))))
  513. (defun org-beamer-headline (headline contents info)
  514. "Transcode HEADLINE element into Beamer code.
  515. CONTENTS is the contents of the headline. INFO is a plist used
  516. as a communication channel."
  517. (unless (org-element-property :footnote-section-p headline)
  518. (let ((level (org-export-get-relative-level headline info))
  519. (frame-level (org-beamer--frame-level headline info))
  520. (environment (let ((env (org-element-property :BEAMER_ENV headline)))
  521. (or (org-string-nw-p env) "block"))))
  522. (cond
  523. ;; Case 1: Resume frame specified by "BEAMER_ref" property.
  524. ((equal environment "againframe")
  525. (let ((ref (org-element-property :BEAMER_REF headline)))
  526. ;; Reference to frame being resumed is mandatory. Ignore
  527. ;; the whole headline if it isn't provided.
  528. (when (org-string-nw-p ref)
  529. (concat "\\againframe"
  530. ;; Overlay specification.
  531. (let ((overlay (org-element-property :BEAMER_ACT headline)))
  532. (when overlay
  533. (org-beamer--normalize-argument
  534. overlay
  535. (if (string-match "\\`\\[.*\\]\\'" overlay) 'defaction
  536. 'action))))
  537. ;; Options.
  538. (let ((options (org-element-property :BEAMER_OPT headline)))
  539. (when options
  540. (org-beamer--normalize-argument options 'option)))
  541. ;; Resolve reference provided by "BEAMER_ref"
  542. ;; property. This is done by building a minimal
  543. ;; fake link and calling the appropriate resolve
  544. ;; function, depending on the reference syntax.
  545. (let ((target
  546. (if (string-match "\\`\\(id:\\|#\\)" ref)
  547. (org-export-resolve-id-link
  548. `(link (:path ,(substring ref (match-end 0))))
  549. info)
  550. (org-export-resolve-fuzzy-link
  551. `(link (:path
  552. ;; Look for headlines only.
  553. ,(if (eq (string-to-char ref) ?*) ref
  554. (concat "*" ref))))
  555. info))))
  556. ;; Now use user-defined label provided in TARGET
  557. ;; headline, or fallback to standard one.
  558. (format "{%s}" (org-beamer--get-label target info)))))))
  559. ;; Case 2: Creation of an appendix is requested.
  560. ((equal environment "appendix")
  561. (concat "\\appendix"
  562. (org-element-property :BEAMER_ACT headline)
  563. "\n"
  564. (make-string (org-element-property :pre-blank headline) ?\n)
  565. contents))
  566. ;; Case 3: Ignore heading.
  567. ((equal environment "ignoreheading")
  568. (concat (make-string (org-element-property :pre-blank headline) ?\n)
  569. contents))
  570. ;; Case 4: HEADLINE is a note.
  571. ((member environment '("note" "noteNH"))
  572. (format "\\note{%s}"
  573. (concat (and (equal environment "note")
  574. (concat
  575. (org-export-data
  576. (org-element-property :title headline) info)
  577. "\n"))
  578. (org-trim contents))))
  579. ;; Case 5: HEADLINE is a frame.
  580. ((= level frame-level)
  581. (org-beamer--format-frame headline contents info))
  582. ;; Case 6: Regular section, extracted from
  583. ;; `org-latex-classes'.
  584. ((< level frame-level)
  585. (org-beamer--format-section headline contents info))
  586. ;; Case 7: Otherwise, HEADLINE is a block.
  587. (t (org-beamer--format-block headline contents info))))))
  588. ;;;; Item
  589. (defun org-beamer-item (item contents info)
  590. "Transcode an ITEM element into Beamer code.
  591. CONTENTS holds the contents of the item. INFO is a plist holding
  592. contextual information."
  593. (org-export-with-backend
  594. ;; Delegate item export to `latex'. However, we use `beamer'
  595. ;; transcoders for objects in the description tag.
  596. (org-export-create-backend
  597. :parent 'beamer
  598. :transcoders
  599. (list
  600. (cons
  601. 'item
  602. (lambda (item c i)
  603. (let ((action
  604. (let ((first (car (org-element-contents item))))
  605. (and (eq (org-element-type first) 'paragraph)
  606. (org-beamer--element-has-overlay-p first))))
  607. (output (org-latex-item item contents info)))
  608. (if (not (and action (string-match "\\\\item" output))) output
  609. ;; If the item starts with a paragraph and that paragraph
  610. ;; starts with an export snippet specifying an overlay,
  611. ;; append it to the \item command.
  612. (replace-match (concat "\\\\item" action) nil nil output)))))))
  613. item contents info))
  614. ;;;; Keyword
  615. (defun org-beamer-keyword (keyword contents info)
  616. "Transcode a KEYWORD element into Beamer code.
  617. CONTENTS is nil. INFO is a plist used as a communication
  618. channel."
  619. (let ((key (org-element-property :key keyword))
  620. (value (org-element-property :value keyword)))
  621. ;; Handle specifically BEAMER and TOC (headlines only) keywords.
  622. ;; Otherwise, fallback to `latex' back-end.
  623. (cond
  624. ((equal key "BEAMER") value)
  625. ((and (equal key "TOC") (string-match "\\<headlines\\>" value))
  626. (let ((depth (or (and (string-match "[0-9]+" value)
  627. (string-to-number (match-string 0 value)))
  628. (plist-get info :with-toc)))
  629. (options (and (string-match "\\[.*?\\]" value)
  630. (match-string 0 value))))
  631. (concat
  632. (when (wholenump depth) (format "\\setcounter{tocdepth}{%s}\n" depth))
  633. "\\tableofcontents" options)))
  634. (t (org-export-with-backend 'latex keyword contents info)))))
  635. ;;;; Link
  636. (defun org-beamer-link (link contents info)
  637. "Transcode a LINK object into Beamer code.
  638. CONTENTS is the description part of the link. INFO is a plist
  639. used as a communication channel."
  640. (let ((type (org-element-property :type link))
  641. (path (org-element-property :path link)))
  642. (cond
  643. ;; Link type is handled by a special function.
  644. ((org-export-custom-protocol-maybe link contents 'beamer))
  645. ;; Use \hyperlink command for all internal links.
  646. ((equal type "radio")
  647. (let ((destination (org-export-resolve-radio-link link info)))
  648. (if (not destination) contents
  649. (format "\\hyperlink%s{%s}{%s}"
  650. (or (org-beamer--element-has-overlay-p link) "")
  651. (org-export-get-reference destination info)
  652. contents))))
  653. ((and (member type '("custom-id" "fuzzy" "id"))
  654. (let ((destination (if (string= type "fuzzy")
  655. (org-export-resolve-fuzzy-link link info)
  656. (org-export-resolve-id-link link info))))
  657. (case (org-element-type destination)
  658. (headline
  659. (let ((label
  660. (format "sec-%s"
  661. (mapconcat
  662. 'number-to-string
  663. (org-export-get-headline-number
  664. destination info)
  665. "-"))))
  666. (if (and (plist-get info :section-numbers) (not contents))
  667. (format "\\ref{%s}" label)
  668. (format "\\hyperlink%s{%s}{%s}"
  669. (or (org-beamer--element-has-overlay-p link) "")
  670. label
  671. contents))))
  672. (target
  673. (let ((ref (org-export-get-reference destination info)))
  674. (if (not contents) (format "\\ref{%s}" ref)
  675. (format "\\hyperlink%s{%s}{%s}"
  676. (or (org-beamer--element-has-overlay-p link) "")
  677. ref
  678. contents))))))))
  679. ;; Otherwise, use `latex' back-end.
  680. (t (org-export-with-backend 'latex link contents info)))))
  681. ;;;; Plain List
  682. ;;
  683. ;; Plain lists support `:environment', `:overlay' and `:options'
  684. ;; attributes.
  685. (defun org-beamer-plain-list (plain-list contents info)
  686. "Transcode a PLAIN-LIST element into Beamer code.
  687. CONTENTS is the contents of the list. INFO is a plist holding
  688. contextual information."
  689. (let* ((type (org-element-property :type plain-list))
  690. (attributes (org-combine-plists
  691. (org-export-read-attribute :attr_latex plain-list)
  692. (org-export-read-attribute :attr_beamer plain-list)))
  693. (latex-type (let ((env (plist-get attributes :environment)))
  694. (cond (env)
  695. ((eq type 'ordered) "enumerate")
  696. ((eq type 'descriptive) "description")
  697. (t "itemize")))))
  698. (org-latex--wrap-label
  699. plain-list
  700. (format "\\begin{%s}%s%s\n%s\\end{%s}"
  701. latex-type
  702. ;; Default overlay specification, if any.
  703. (org-beamer--normalize-argument
  704. (or (plist-get attributes :overlay) "")
  705. 'defaction)
  706. ;; Second optional argument depends on the list type.
  707. (org-beamer--normalize-argument
  708. (or (plist-get attributes :options) "")
  709. 'option)
  710. ;; Eventually insert contents and close environment.
  711. contents
  712. latex-type)
  713. info)))
  714. ;;;; Radio Target
  715. (defun org-beamer-radio-target (radio-target text info)
  716. "Transcode a RADIO-TARGET object into Beamer code.
  717. TEXT is the text of the target. INFO is a plist holding
  718. contextual information."
  719. (format "\\hypertarget%s{%s}{%s}"
  720. (or (org-beamer--element-has-overlay-p radio-target) "")
  721. (org-export-get-reference radio-target info)
  722. text))
  723. ;;;; Target
  724. (defun org-beamer-target (target contents info)
  725. "Transcode a TARGET object into Beamer code.
  726. CONTENTS is nil. INFO is a plist holding contextual
  727. information."
  728. (format "\\label{%s}" (org-export-get-reference target info)))
  729. ;;;; Template
  730. ;;
  731. ;; Template used is similar to the one used in `latex' back-end,
  732. ;; excepted for the table of contents and Beamer themes.
  733. (defun org-beamer-template (contents info)
  734. "Return complete document string after Beamer conversion.
  735. CONTENTS is the transcoded contents string. INFO is a plist
  736. holding export options."
  737. (let ((title (org-export-data (plist-get info :title) info))
  738. (subtitle (org-export-data (plist-get info :subtitle) info)))
  739. (concat
  740. ;; 1. Time-stamp.
  741. (and (plist-get info :time-stamp-file)
  742. (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  743. ;; 2. Document class and packages.
  744. (let* ((class (plist-get info :latex-class))
  745. (class-options (plist-get info :latex-class-options))
  746. (header (nth 1 (assoc class org-latex-classes)))
  747. (document-class-string
  748. (and (stringp header)
  749. (if (not class-options) header
  750. (replace-regexp-in-string
  751. "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
  752. class-options header t nil 1)))))
  753. (if (not document-class-string)
  754. (user-error "Unknown LaTeX class `%s'" class)
  755. (org-latex-guess-babel-language
  756. (org-latex-guess-inputenc
  757. (org-element-normalize-string
  758. (org-splice-latex-header
  759. document-class-string
  760. org-latex-default-packages-alist
  761. org-latex-packages-alist nil
  762. (concat (org-element-normalize-string
  763. (plist-get info :latex-header))
  764. (org-element-normalize-string
  765. (plist-get info :latex-header-extra))))))
  766. info)))
  767. ;; 3. Insert themes.
  768. (let ((format-theme
  769. (function
  770. (lambda (prop command)
  771. (let ((theme (plist-get info prop)))
  772. (when theme
  773. (concat command
  774. (if (not (string-match "\\[.*\\]" theme))
  775. (format "{%s}\n" theme)
  776. (format "%s{%s}\n"
  777. (match-string 0 theme)
  778. (org-trim
  779. (replace-match "" nil nil theme)))))))))))
  780. (mapconcat (lambda (args) (apply format-theme args))
  781. '((:beamer-theme "\\usetheme")
  782. (:beamer-color-theme "\\usecolortheme")
  783. (:beamer-font-theme "\\usefonttheme")
  784. (:beamer-inner-theme "\\useinnertheme")
  785. (:beamer-outer-theme "\\useoutertheme"))
  786. ""))
  787. ;; 4. Possibly limit depth for headline numbering.
  788. (let ((sec-num (plist-get info :section-numbers)))
  789. (when (integerp sec-num)
  790. (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
  791. ;; 5. Author.
  792. (let ((author (and (plist-get info :with-author)
  793. (let ((auth (plist-get info :author)))
  794. (and auth (org-export-data auth info)))))
  795. (email (and (plist-get info :with-email)
  796. (org-export-data (plist-get info :email) info))))
  797. (cond ((and author email (not (string= "" email)))
  798. (format "\\author{%s\\thanks{%s}}\n" author email))
  799. ((or author email) (format "\\author{%s}\n" (or author email)))))
  800. ;; 6. Date.
  801. (let ((date (and (plist-get info :with-date) (org-export-get-date info))))
  802. (format "\\date{%s}\n" (org-export-data date info)))
  803. ;; 7. Title
  804. (format "\\title{%s}\n" title)
  805. (when (org-string-nw-p subtitle)
  806. (concat (format (plist-get info :beamer-subtitle-format) subtitle) "\n"))
  807. ;; 8. Beamer-header
  808. (let ((beamer-header (plist-get info :beamer-header)))
  809. (when beamer-header
  810. (format "%s\n" (plist-get info :beamer-header))))
  811. ;; 9. Hyperref options.
  812. (let ((template (plist-get info :latex-hyperref-template)))
  813. (and (stringp template)
  814. (format-spec template (org-latex--format-spec info))))
  815. ;; 10. Document start.
  816. "\\begin{document}\n\n"
  817. ;; 11. Title command.
  818. (org-element-normalize-string
  819. (cond ((not (plist-get info :with-title)) nil)
  820. ((string= "" title) nil)
  821. ((not (stringp org-latex-title-command)) nil)
  822. ((string-match "\\(?:[^%]\\|^\\)%s"
  823. org-latex-title-command)
  824. (format org-latex-title-command title))
  825. (t org-latex-title-command)))
  826. ;; 12. Table of contents.
  827. (let ((depth (plist-get info :with-toc)))
  828. (when depth
  829. (concat
  830. (format "\\begin{frame}%s{%s}\n"
  831. (org-beamer--normalize-argument
  832. (plist-get info :beamer-outline-frame-options) 'option)
  833. (plist-get info :beamer-outline-frame-title))
  834. (when (wholenump depth)
  835. (format "\\setcounter{tocdepth}{%d}\n" depth))
  836. "\\tableofcontents\n"
  837. "\\end{frame}\n\n")))
  838. ;; 13. Document's body.
  839. contents
  840. ;; 14. Creator.
  841. (if (plist-get info :with-creator)
  842. (concat (plist-get info :creator) "\n")
  843. "")
  844. ;; 15. Document end.
  845. "\\end{document}")))
  846. ;;; Minor Mode
  847. (defvar org-beamer-mode-map (make-sparse-keymap)
  848. "The keymap for `org-beamer-mode'.")
  849. (define-key org-beamer-mode-map "\C-c\C-b" 'org-beamer-select-environment)
  850. ;;;###autoload
  851. (define-minor-mode org-beamer-mode
  852. "Support for editing Beamer oriented Org mode files."
  853. nil " Bm" 'org-beamer-mode-map)
  854. (when (fboundp 'font-lock-add-keywords)
  855. (font-lock-add-keywords
  856. 'org-mode
  857. '((":\\(B_[a-z]+\\|BMCOL\\):" 1 'org-beamer-tag prepend))
  858. 'prepend))
  859. (defface org-beamer-tag '((t (:box (:line-width 1 :color grey40))))
  860. "The special face for beamer tags."
  861. :group 'org-export-beamer)
  862. (defun org-beamer-property-changed (property value)
  863. "Track the BEAMER_env property with tags.
  864. PROPERTY is the name of the modified property. VALUE is its new
  865. value."
  866. (cond
  867. ((equal property "BEAMER_env")
  868. (save-excursion
  869. (org-back-to-heading t)
  870. ;; Filter out Beamer-related tags and install environment tag.
  871. (let ((tags (org-remove-if (lambda (x) (string-match "^B_" x))
  872. (org-get-tags)))
  873. (env-tag (and (org-string-nw-p value) (concat "B_" value))))
  874. (org-set-tags-to (if env-tag (cons env-tag tags) tags))
  875. (when env-tag (org-toggle-tag env-tag 'on)))))
  876. ((equal property "BEAMER_col")
  877. (org-toggle-tag "BMCOL" (if (org-string-nw-p value) 'on 'off)))))
  878. (add-hook 'org-property-changed-functions 'org-beamer-property-changed)
  879. (defun org-beamer-allowed-property-values (property)
  880. "Supply allowed values for PROPERTY."
  881. (cond
  882. ((and (equal property "BEAMER_env")
  883. (not (org-entry-get nil (concat property "_ALL") 'inherit)))
  884. ;; If no allowed values for BEAMER_env have been defined,
  885. ;; supply all defined environments
  886. (mapcar 'car (append org-beamer-environments-special
  887. org-beamer-environments-extra
  888. org-beamer-environments-default)))
  889. ((and (equal property "BEAMER_col")
  890. (not (org-entry-get nil (concat property "_ALL") 'inherit)))
  891. ;; If no allowed values for BEAMER_col have been defined,
  892. ;; supply some
  893. (org-split-string org-beamer-column-widths " "))))
  894. (add-hook 'org-property-allowed-value-functions
  895. 'org-beamer-allowed-property-values)
  896. ;;; Commands
  897. ;;;###autoload
  898. (defun org-beamer-export-as-latex
  899. (&optional async subtreep visible-only body-only ext-plist)
  900. "Export current buffer as a Beamer buffer.
  901. If narrowing is active in the current buffer, only export its
  902. narrowed part.
  903. If a region is active, export that region.
  904. A non-nil optional argument ASYNC means the process should happen
  905. asynchronously. The resulting buffer should be accessible
  906. through the `org-export-stack' interface.
  907. When optional argument SUBTREEP is non-nil, export the sub-tree
  908. at point, extracting information from the headline properties
  909. first.
  910. When optional argument VISIBLE-ONLY is non-nil, don't export
  911. contents of hidden elements.
  912. When optional argument BODY-ONLY is non-nil, only write code
  913. between \"\\begin{document}\" and \"\\end{document}\".
  914. EXT-PLIST, when provided, is a property list with external
  915. parameters overriding Org default settings, but still inferior to
  916. file-local settings.
  917. Export is done in a buffer named \"*Org BEAMER Export*\", which
  918. will be displayed when `org-export-show-temporary-export-buffer'
  919. is non-nil."
  920. (interactive)
  921. (org-export-to-buffer 'beamer "*Org BEAMER Export*"
  922. async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
  923. ;;;###autoload
  924. (defun org-beamer-export-to-latex
  925. (&optional async subtreep visible-only body-only ext-plist)
  926. "Export current buffer as a Beamer presentation (tex).
  927. If narrowing is active in the current buffer, only export its
  928. narrowed part.
  929. If a region is active, export that region.
  930. A non-nil optional argument ASYNC means the process should happen
  931. asynchronously. The resulting file should be accessible through
  932. the `org-export-stack' interface.
  933. When optional argument SUBTREEP is non-nil, export the sub-tree
  934. at point, extracting information from the headline properties
  935. first.
  936. When optional argument VISIBLE-ONLY is non-nil, don't export
  937. contents of hidden elements.
  938. When optional argument BODY-ONLY is non-nil, only write code
  939. between \"\\begin{document}\" and \"\\end{document}\".
  940. EXT-PLIST, when provided, is a property list with external
  941. parameters overriding Org default settings, but still inferior to
  942. file-local settings.
  943. Return output file's name."
  944. (interactive)
  945. (let ((file (org-export-output-file-name ".tex" subtreep)))
  946. (org-export-to-file 'beamer file
  947. async subtreep visible-only body-only ext-plist)))
  948. ;;;###autoload
  949. (defun org-beamer-export-to-pdf
  950. (&optional async subtreep visible-only body-only ext-plist)
  951. "Export current buffer as a Beamer presentation (PDF).
  952. If narrowing is active in the current buffer, only export its
  953. narrowed part.
  954. If a region is active, export that region.
  955. A non-nil optional argument ASYNC means the process should happen
  956. asynchronously. The resulting file should be accessible through
  957. the `org-export-stack' interface.
  958. When optional argument SUBTREEP is non-nil, export the sub-tree
  959. at point, extracting information from the headline properties
  960. first.
  961. When optional argument VISIBLE-ONLY is non-nil, don't export
  962. contents of hidden elements.
  963. When optional argument BODY-ONLY is non-nil, only write code
  964. between \"\\begin{document}\" and \"\\end{document}\".
  965. EXT-PLIST, when provided, is a property list with external
  966. parameters overriding Org default settings, but still inferior to
  967. file-local settings.
  968. Return PDF file's name."
  969. (interactive)
  970. (let ((file (org-export-output-file-name ".tex" subtreep)))
  971. (org-export-to-file 'beamer file
  972. async subtreep visible-only body-only ext-plist
  973. (lambda (file) (org-latex-compile file)))))
  974. ;;;###autoload
  975. (defun org-beamer-select-environment ()
  976. "Select the environment to be used by beamer for this entry.
  977. While this uses (for convenience) a tag selection interface, the
  978. result of this command will be that the BEAMER_env *property* of
  979. the entry is set.
  980. In addition to this, the command will also set a tag as a visual
  981. aid, but the tag does not have any semantic meaning."
  982. (interactive)
  983. ;; Make sure `org-beamer-environments-special' has a higher
  984. ;; priority than `org-beamer-environments-extra'.
  985. (let* ((envs (append org-beamer-environments-special
  986. org-beamer-environments-extra
  987. org-beamer-environments-default))
  988. (org-tag-alist
  989. (append '((:startgroup))
  990. (mapcar (lambda (e) (cons (concat "B_" (car e))
  991. (string-to-char (nth 1 e))))
  992. envs)
  993. '((:endgroup))
  994. '(("BMCOL" . ?|))))
  995. (org-tag-persistent-alist nil)
  996. (org-use-fast-tag-selection t)
  997. (org-fast-tag-selection-single-key t))
  998. (org-set-tags)
  999. (let ((tags (or (ignore-errors (org-get-tags-string)) "")))
  1000. (cond
  1001. ;; For a column, automatically ask for its width.
  1002. ((eq org-last-tag-selection-key ?|)
  1003. (if (string-match ":BMCOL:" tags)
  1004. (org-set-property "BEAMER_col" (read-string "Column width: "))
  1005. (org-delete-property "BEAMER_col")))
  1006. ;; For an "againframe" section, automatically ask for reference
  1007. ;; to resumed frame and overlay specifications.
  1008. ((eq org-last-tag-selection-key ?A)
  1009. (if (equal (org-entry-get nil "BEAMER_env") "againframe")
  1010. (progn (org-entry-delete nil "BEAMER_env")
  1011. (org-entry-delete nil "BEAMER_ref")
  1012. (org-entry-delete nil "BEAMER_act"))
  1013. (org-entry-put nil "BEAMER_env" "againframe")
  1014. (org-set-property
  1015. "BEAMER_ref"
  1016. (read-string "Frame reference (*Title, #custom-id, id:...): "))
  1017. (org-set-property "BEAMER_act"
  1018. (read-string "Overlay specification: "))))
  1019. ((string-match (concat ":B_\\(" (mapconcat 'car envs "\\|") "\\):") tags)
  1020. (org-entry-put nil "BEAMER_env" (match-string 1 tags)))
  1021. (t (org-entry-delete nil "BEAMER_env"))))))
  1022. ;;;###autoload
  1023. (defun org-beamer-publish-to-latex (plist filename pub-dir)
  1024. "Publish an Org file to a Beamer presentation (LaTeX).
  1025. FILENAME is the filename of the Org file to be published. PLIST
  1026. is the property list for the given project. PUB-DIR is the
  1027. publishing directory.
  1028. Return output file name."
  1029. (org-publish-org-to 'beamer filename ".tex" plist pub-dir))
  1030. ;;;###autoload
  1031. (defun org-beamer-publish-to-pdf (plist filename pub-dir)
  1032. "Publish an Org file to a Beamer presentation (PDF, via LaTeX).
  1033. FILENAME is the filename of the Org file to be published. PLIST
  1034. is the property list for the given project. PUB-DIR is the
  1035. publishing directory.
  1036. Return output file name."
  1037. ;; Unlike to `org-beamer-publish-to-latex', PDF file is generated in
  1038. ;; working directory and then moved to publishing directory.
  1039. (org-publish-attachment
  1040. plist
  1041. (org-latex-compile
  1042. (org-publish-org-to
  1043. 'beamer filename ".tex" plist (file-name-directory filename)))
  1044. pub-dir))
  1045. (provide 'ox-beamer)
  1046. ;; Local variables:
  1047. ;; generated-autoload-file: "org-loaddefs.el"
  1048. ;; End:
  1049. ;;; ox-beamer.el ends here