ox-beamer.el 43 KB

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