ox-beamer.el 43 KB

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