ox-beamer.el 43 KB

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