org-e-beamer.el 43 KB

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