ox-beamer.el 47 KB

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