org-e-beamer.el 43 KB

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