ox-beamer.el 42 KB

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