ox-beamer.el 46 KB

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