ox-beamer.el 43 KB

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