ox-beamer.el 47 KB

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