org-e-beamer.el 43 KB

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