ox-beamer.el 47 KB

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