ox-beamer.el 47 KB

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