org-e-beamer.el 43 KB

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