ox-beamer.el 43 KB

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