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