ox-beamer.el 46 KB

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