org-e-beamer.el 46 KB

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