ox-beamer.el 47 KB

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