ox-beamer.el 43 KB

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