ox-beamer.el 43 KB

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