org-e-beamer.el 43 KB

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