ox-beamer.el 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. ;;; ox-beamer.el --- Beamer Back-End for Org Export Engine -*- lexical-binding: t; -*-
  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 'cl-lib)
  25. (require 'ox-latex)
  26. ;; Install a default set-up for Beamer export.
  27. (unless (assoc "beamer" org-latex-classes)
  28. (add-to-list 'org-latex-classes
  29. '("beamer"
  30. "\\documentclass[presentation]{beamer}"
  31. ("\\section{%s}" . "\\section*{%s}")
  32. ("\\subsection{%s}" . "\\subsection*{%s}")
  33. ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
  34. ;;; User-Configurable Variables
  35. (defgroup org-export-beamer nil
  36. "Options specific for using the beamer class in LaTeX export."
  37. :tag "Org Beamer"
  38. :group 'org-export
  39. :version "24.2")
  40. (defcustom org-beamer-frame-level 1
  41. "The level at which headlines become frames.
  42. Headlines at a lower level will be translated into a sectioning
  43. structure. At a higher level, they will be translated into
  44. blocks.
  45. If a headline with a \"BEAMER_env\" property set to \"frame\" is
  46. found within a tree, its level locally overrides this number.
  47. This variable has no effect on headlines with the \"BEAMER_env\"
  48. property set to either \"ignoreheading\", \"appendix\", or
  49. \"note\", which will respectively, be invisible, become an
  50. appendix or a note.
  51. This integer is relative to the minimal level of a headline
  52. within the parse tree, defined as 1."
  53. :group 'org-export-beamer
  54. :type 'integer)
  55. (defcustom org-beamer-frame-default-options ""
  56. "Default options string to use for frames.
  57. For example, it could be set to \"allowframebreaks\"."
  58. :group 'org-export-beamer
  59. :type '(string :tag "[options]"))
  60. (defcustom org-beamer-column-view-format
  61. "%45ITEM %10BEAMER_env(Env) %10BEAMER_act(Act) %4BEAMER_col(Col) %8BEAMER_opt(Opt)"
  62. "Column view format that should be used to fill the template."
  63. :group 'org-export-beamer
  64. :version "24.4"
  65. :package-version '(Org . "8.0")
  66. :type '(choice
  67. (const :tag "Do not insert Beamer column view format" nil)
  68. (string :tag "Beamer column view format")))
  69. (defcustom org-beamer-theme "default"
  70. "Default theme used in Beamer presentations."
  71. :group 'org-export-beamer
  72. :version "24.4"
  73. :package-version '(Org . "8.0")
  74. :type '(choice
  75. (const :tag "Do not insert a Beamer theme" nil)
  76. (string :tag "Beamer theme")))
  77. (defcustom org-beamer-environments-extra nil
  78. "Environments triggered by tags in Beamer export.
  79. Each entry has 4 elements:
  80. name Name of the environment
  81. key Selection key for `org-beamer-select-environment'
  82. open The opening template for the environment, with the following escapes
  83. %a the action/overlay specification
  84. %A the default action/overlay specification
  85. %R the raw BEAMER_act value
  86. %o the options argument, with square brackets
  87. %O the raw BEAMER_opt value
  88. %h the headline text
  89. %r the raw headline text (i.e. without any processing)
  90. %H if there is headline text, that raw text in {} braces
  91. %U if there is headline text, that raw text in [] brackets
  92. close The closing string of the environment."
  93. :group 'org-export-beamer
  94. :version "24.4"
  95. :package-version '(Org . "8.1")
  96. :type '(repeat
  97. (list
  98. (string :tag "Environment")
  99. (string :tag "Selection key")
  100. (string :tag "Begin")
  101. (string :tag "End"))))
  102. (defcustom org-beamer-outline-frame-title "Outline"
  103. "Default title of a frame containing an outline."
  104. :group 'org-export-beamer
  105. :type '(string :tag "Outline frame title"))
  106. (defcustom org-beamer-outline-frame-options ""
  107. "Outline frame options appended after \\begin{frame}.
  108. You might want to put e.g. \"allowframebreaks=0.9\" here."
  109. :group 'org-export-beamer
  110. :type '(string :tag "Outline frame options"))
  111. (defcustom org-beamer-subtitle-format "\\subtitle{%s}"
  112. "Format string used for transcoded subtitle.
  113. The format string should have at most one \"%s\"-expression,
  114. which is replaced with the subtitle."
  115. :group 'org-export-beamer
  116. :version "25.1"
  117. :package-version '(Org . "8.3")
  118. :type '(string :tag "Format string"))
  119. ;;; Internal Variables
  120. (defconst org-beamer-column-widths
  121. "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.0 :ETC"
  122. "The column widths that should be installed as allowed property values.")
  123. (defconst org-beamer-environments-special
  124. '(("againframe" "A")
  125. ("appendix" "x")
  126. ("column" "c")
  127. ("columns" "C")
  128. ("frame" "f")
  129. ("fullframe" "F")
  130. ("ignoreheading" "i")
  131. ("note" "n")
  132. ("noteNH" "N"))
  133. "Alist of environments treated in a special way by the back-end.
  134. Keys are environment names, as strings, values are bindings used
  135. in `org-beamer-select-environment'. Environments listed here,
  136. along with their binding, are hard coded and cannot be modified
  137. through `org-beamer-environments-extra' variable.")
  138. (defconst org-beamer-environments-default
  139. '(("block" "b" "\\begin{block}%a{%h}" "\\end{block}")
  140. ("alertblock" "a" "\\begin{alertblock}%a{%h}" "\\end{alertblock}")
  141. ("verse" "v" "\\begin{verse}%a %% %h" "\\end{verse}")
  142. ("quotation" "q" "\\begin{quotation}%a %% %h" "\\end{quotation}")
  143. ("quote" "Q" "\\begin{quote}%a %% %h" "\\end{quote}")
  144. ("structureenv" "s" "\\begin{structureenv}%a %% %h" "\\end{structureenv}")
  145. ("theorem" "t" "\\begin{theorem}%a%U" "\\end{theorem}")
  146. ("definition" "d" "\\begin{definition}%a%U" "\\end{definition}")
  147. ("example" "e" "\\begin{example}%a%U" "\\end{example}")
  148. ("exampleblock" "E" "\\begin{exampleblock}%a{%h}" "\\end{exampleblock}")
  149. ("proof" "p" "\\begin{proof}%a%U" "\\end{proof}")
  150. ("beamercolorbox" "o" "\\begin{beamercolorbox}%o{%h}" "\\end{beamercolorbox}"))
  151. "Environments triggered by properties in Beamer export.
  152. These are the defaults - for user definitions, see
  153. `org-beamer-environments-extra'.")
  154. (defconst org-beamer-verbatim-elements
  155. '(code example-block fixed-width inline-src-block src-block verbatim)
  156. "List of element or object types producing verbatim text.
  157. This is used internally to determine when a frame should have the
  158. \"fragile\" option.")
  159. ;;; Internal functions
  160. (defun org-beamer--normalize-argument (argument type)
  161. "Return ARGUMENT string with proper boundaries.
  162. TYPE is a symbol among the following:
  163. `action' Return ARGUMENT within angular brackets.
  164. `defaction' Return ARGUMENT within both square and angular brackets.
  165. `option' Return ARGUMENT within square brackets."
  166. (if (not (string-match "\\S-" argument)) ""
  167. (case type
  168. (action (if (string-match "\\`<.*>\\'" argument) argument
  169. (format "<%s>" argument)))
  170. (defaction (cond
  171. ((string-match "\\`\\[<.*>\\]\\'" argument) argument)
  172. ((string-match "\\`<.*>\\'" argument)
  173. (format "[%s]" argument))
  174. ((string-match "\\`\\[\\(.*\\)\\]\\'" argument)
  175. (format "[<%s>]" (match-string 1 argument)))
  176. (t (format "[<%s>]" argument))))
  177. (option (if (string-match "\\`\\[.*\\]\\'" argument) argument
  178. (format "[%s]" argument)))
  179. (otherwise argument))))
  180. (defun org-beamer--element-has-overlay-p (element)
  181. "Non-nil when ELEMENT has an overlay specified.
  182. An element has an overlay specification when it starts with an
  183. `beamer' export-snippet whose value is between angular brackets.
  184. Return overlay specification, as a string, or nil."
  185. (let ((first-object (car (org-element-contents element))))
  186. (when (eq (org-element-type first-object) 'export-snippet)
  187. (let ((value (org-element-property :value first-object)))
  188. (and (string-match "\\`<.*>\\'" value) value)))))
  189. ;;; Define Back-End
  190. (org-export-define-derived-backend 'beamer 'latex
  191. :export-block "BEAMER"
  192. :menu-entry
  193. '(?l 1
  194. ((?B "As LaTeX buffer (Beamer)" org-beamer-export-as-latex)
  195. (?b "As LaTeX file (Beamer)" org-beamer-export-to-latex)
  196. (?P "As PDF file (Beamer)" org-beamer-export-to-pdf)
  197. (?O "As PDF file and open (Beamer)"
  198. (lambda (a s v b)
  199. (if a (org-beamer-export-to-pdf t s v b)
  200. (org-open-file (org-beamer-export-to-pdf nil s v b)))))))
  201. :options-alist
  202. '((:headline-levels nil "H" org-beamer-frame-level)
  203. (:latex-class "LATEX_CLASS" nil "beamer" t)
  204. (:beamer-subtitle-format nil nil org-beamer-subtitle-format)
  205. (:beamer-column-view-format "COLUMNS" nil org-beamer-column-view-format)
  206. (:beamer-theme "BEAMER_THEME" nil org-beamer-theme)
  207. (:beamer-color-theme "BEAMER_COLOR_THEME" nil nil t)
  208. (:beamer-font-theme "BEAMER_FONT_THEME" nil nil t)
  209. (:beamer-inner-theme "BEAMER_INNER_THEME" nil nil t)
  210. (:beamer-outer-theme "BEAMER_OUTER_THEME" nil nil t)
  211. (:beamer-header "BEAMER_HEADER" nil nil newline)
  212. (:beamer-environments-extra nil nil org-beamer-environments-extra)
  213. (:beamer-frame-default-options nil nil org-beamer-frame-default-options)
  214. (:beamer-outline-frame-options nil nil org-beamer-outline-frame-options)
  215. (:beamer-outline-frame-title nil nil org-beamer-outline-frame-title))
  216. :translate-alist '((bold . org-beamer-bold)
  217. (export-block . org-beamer-export-block)
  218. (export-snippet . org-beamer-export-snippet)
  219. (headline . org-beamer-headline)
  220. (item . org-beamer-item)
  221. (keyword . org-beamer-keyword)
  222. (link . org-beamer-link)
  223. (plain-list . org-beamer-plain-list)
  224. (radio-target . org-beamer-radio-target)
  225. (target . org-beamer-target)
  226. (template . org-beamer-template)))
  227. ;;; Transcode Functions
  228. ;;;; Bold
  229. (defun org-beamer-bold (bold contents _info)
  230. "Transcode BLOCK object into Beamer code.
  231. CONTENTS is the text being bold. INFO is a plist used as
  232. a communication channel."
  233. (format "\\alert%s{%s}"
  234. (or (org-beamer--element-has-overlay-p bold) "")
  235. contents))
  236. ;;;; Export Block
  237. (defun org-beamer-export-block (export-block _contents _info)
  238. "Transcode an EXPORT-BLOCK element into Beamer code.
  239. CONTENTS is nil. INFO is a plist used as a communication
  240. channel."
  241. (when (member (org-element-property :type export-block) '("BEAMER" "LATEX"))
  242. (org-remove-indentation (org-element-property :value export-block))))
  243. ;;;; Export Snippet
  244. (defun org-beamer-export-snippet (export-snippet _contents info)
  245. "Transcode an EXPORT-SNIPPET object into Beamer code.
  246. CONTENTS is nil. INFO is a plist used as a communication
  247. channel."
  248. (let ((backend (org-export-snippet-backend export-snippet))
  249. (value (org-element-property :value export-snippet)))
  250. ;; Only "latex" and "beamer" snippets are retained.
  251. (cond ((eq backend 'latex) value)
  252. ;; Ignore "beamer" snippets specifying overlays.
  253. ((and (eq backend 'beamer)
  254. (or (org-export-get-previous-element export-snippet info)
  255. (not (string-match "\\`<.*>\\'" value))))
  256. value))))
  257. ;;;; Headline
  258. ;;
  259. ;; The main function to translate a headline is
  260. ;; `org-beamer-headline'.
  261. ;;
  262. ;; Depending on the level at which a headline is considered as
  263. ;; a frame (given by `org-beamer--frame-level'), the headline is
  264. ;; either a section (`org-beamer--format-section'), a frame
  265. ;; (`org-beamer--format-frame') or a block
  266. ;; (`org-beamer--format-block').
  267. ;;
  268. ;; `org-beamer-headline' also takes care of special environments
  269. ;; like "ignoreheading", "note", "noteNH", "appendix" and
  270. ;; "againframe".
  271. (defun org-beamer--get-label (headline info)
  272. "Return label for HEADLINE, as a string.
  273. INFO is a plist used as a communication channel.
  274. The value is either the label specified in \"BEAMER_opt\"
  275. property, the custom ID, if there is one and
  276. `:latex-prefer-user-labels' property has a non nil value, or
  277. a unique internal label. This function assumes HEADLINE will be
  278. treated as a frame."
  279. (cond
  280. ((let ((opt (org-element-property :BEAMER_OPT headline)))
  281. (and (stringp opt)
  282. (string-match "\\(?:^\\|,\\)label=\\(.*?\\)\\(?:$\\|,\\)" opt)
  283. (let ((label (match-string 1 opt)))
  284. (if (string-match-p "\\`{.*}\\'" label)
  285. (substring label 1 -1)
  286. label)))))
  287. ((and (plist-get info :latex-prefer-user-labels)
  288. (org-element-property :CUSTOM_ID headline)))
  289. (t (format "sec:%s" (org-export-get-reference headline info)))))
  290. (defun org-beamer--frame-level (headline info)
  291. "Return frame level in subtree containing HEADLINE.
  292. INFO is a plist used as a communication channel."
  293. (or
  294. ;; 1. Look for "frame" environment in parents, starting from the
  295. ;; farthest.
  296. (catch 'exit
  297. (dolist (parent (nreverse (org-element-lineage headline)))
  298. (let ((env (org-element-property :BEAMER_ENV parent)))
  299. (when (and env (member-ignore-case env '("frame" "fullframe")))
  300. (throw 'exit (org-export-get-relative-level parent info))))))
  301. ;; 2. Look for "frame" environment in HEADLINE.
  302. (let ((env (org-element-property :BEAMER_ENV headline)))
  303. (and env (member-ignore-case env '("frame" "fullframe"))
  304. (org-export-get-relative-level headline info)))
  305. ;; 3. Look for "frame" environment in sub-tree.
  306. (org-element-map headline 'headline
  307. (lambda (hl)
  308. (let ((env (org-element-property :BEAMER_ENV hl)))
  309. (when (and env (member-ignore-case env '("frame" "fullframe")))
  310. (org-export-get-relative-level hl info))))
  311. info 'first-match)
  312. ;; 4. No "frame" environment in tree: use default value.
  313. (plist-get info :headline-levels)))
  314. (defun org-beamer--format-section (headline contents info)
  315. "Format HEADLINE as a sectioning part.
  316. CONTENTS holds the contents of the headline. INFO is a plist
  317. used as a communication channel."
  318. (let ((latex-headline
  319. (org-export-with-backend
  320. ;; We create a temporary export back-end which behaves the
  321. ;; same as current one, but adds "\protect" in front of the
  322. ;; output of some objects.
  323. (org-export-create-backend
  324. :parent 'latex
  325. :transcoders
  326. (let ((protected-output
  327. (function
  328. (lambda (object contents info)
  329. (let ((code (org-export-with-backend
  330. 'beamer object contents info)))
  331. (if (org-string-nw-p code) (concat "\\protect" code)
  332. code))))))
  333. (mapcar #'(lambda (type) (cons type protected-output))
  334. '(bold footnote-reference italic strike-through timestamp
  335. underline))))
  336. headline
  337. contents
  338. info))
  339. (mode-specs (org-element-property :BEAMER_ACT headline)))
  340. (if (and mode-specs
  341. (string-match "\\`\\\\\\(.*?\\)\\(?:\\*\\|\\[.*\\]\\)?{"
  342. latex-headline))
  343. ;; Insert overlay specifications.
  344. (replace-match (concat (match-string 1 latex-headline)
  345. (format "<%s>" mode-specs))
  346. nil nil latex-headline 1)
  347. latex-headline)))
  348. (defun org-beamer--format-frame (headline contents info)
  349. "Format HEADLINE as a frame.
  350. CONTENTS holds the contents of the headline. INFO is a plist
  351. used as a communication channel."
  352. (let ((fragilep
  353. ;; FRAGILEP is non-nil when HEADLINE contains an element
  354. ;; among `org-beamer-verbatim-elements'.
  355. (org-element-map headline org-beamer-verbatim-elements 'identity
  356. info 'first-match)))
  357. (concat "\\begin{frame}"
  358. ;; Overlay specification, if any. When surrounded by
  359. ;; square brackets, consider it as a default
  360. ;; specification.
  361. (let ((action (org-element-property :BEAMER_ACT headline)))
  362. (cond
  363. ((not action) "")
  364. ((string-match "\\`\\[.*\\]\\'" action )
  365. (org-beamer--normalize-argument action 'defaction))
  366. (t (org-beamer--normalize-argument action 'action))))
  367. ;; Options, if any.
  368. (let* ((beamer-opt (org-element-property :BEAMER_OPT headline))
  369. (options
  370. ;; Collect options from default value and headline's
  371. ;; properties. Also add a label for links.
  372. (append
  373. (org-split-string
  374. (plist-get info :beamer-frame-default-options) ",")
  375. (and beamer-opt
  376. (org-split-string
  377. ;; Remove square brackets if user provided
  378. ;; them.
  379. (and (string-match "^\\[?\\(.*\\)\\]?$" beamer-opt)
  380. (match-string 1 beamer-opt))
  381. ","))
  382. ;; Provide an automatic label for the frame
  383. ;; unless the user specified one. Also refrain
  384. ;; from labeling `allowframebreaks' frames; this
  385. ;; is not allowed by beamer.
  386. (unless (and beamer-opt
  387. (or (string-match "\\(^\\|,\\)label=" beamer-opt)
  388. (string-match "allowframebreaks" beamer-opt)))
  389. (list
  390. (let ((label (org-beamer--get-label headline info)))
  391. ;; Labels containing colons need to be
  392. ;; wrapped within braces.
  393. (format (if (org-string-match-p ":" label)
  394. "label={%s}"
  395. "label=%s")
  396. label)))))))
  397. ;; Change options list into a string.
  398. (org-beamer--normalize-argument
  399. (mapconcat
  400. 'identity
  401. (if (or (not fragilep) (member "fragile" options)) options
  402. (cons "fragile" options))
  403. ",")
  404. 'option))
  405. ;; Title.
  406. (let ((env (org-element-property :BEAMER_ENV headline)))
  407. (format "{%s}"
  408. (if (and env (equal (downcase env) "fullframe")) ""
  409. (org-export-data
  410. (org-element-property :title headline) info))))
  411. "\n"
  412. ;; The following workaround is required in fragile frames
  413. ;; as Beamer will append "\par" to the beginning of the
  414. ;; contents. So we need to make sure the command is
  415. ;; separated from the contents by at least one space. If
  416. ;; it isn't, it will create "\parfirst-word" command and
  417. ;; remove the first word from the contents in the PDF
  418. ;; output.
  419. (if (not fragilep) contents
  420. (replace-regexp-in-string "\\`\n*" "\\& " (or contents "")))
  421. "\\end{frame}")))
  422. (defun org-beamer--format-block (headline contents info)
  423. "Format HEADLINE as a block.
  424. CONTENTS holds the contents of the headline. INFO is a plist
  425. used as a communication channel."
  426. (let* ((column-width (org-element-property :BEAMER_COL headline))
  427. ;; ENVIRONMENT defaults to "block" if none is specified and
  428. ;; there is no column specification. If there is a column
  429. ;; specified but still no explicit environment, ENVIRONMENT
  430. ;; is "column".
  431. (environment (let ((env (org-element-property :BEAMER_ENV headline)))
  432. (cond
  433. ;; "block" is the fallback environment.
  434. ((and (not env) (not column-width)) "block")
  435. ;; "column" only.
  436. ((not env) "column")
  437. ;; Use specified environment.
  438. (t env))))
  439. (raw-title (org-element-property :raw-value headline))
  440. (env-format
  441. (cond ((member environment '("column" "columns")) nil)
  442. ((assoc environment
  443. (append (plist-get info :beamer-environments-extra)
  444. org-beamer-environments-default)))
  445. (t (user-error "Wrong block type at a headline named \"%s\""
  446. raw-title))))
  447. (title (org-export-data (org-element-property :title headline) info))
  448. (raw-options (org-element-property :BEAMER_OPT headline))
  449. (options (if raw-options
  450. (org-beamer--normalize-argument raw-options 'option)
  451. ""))
  452. ;; Start a "columns" environment when explicitly requested or
  453. ;; when there is no previous headline or the previous
  454. ;; headline do not have a BEAMER_column property.
  455. (parent-env (org-element-property
  456. :BEAMER_ENV (org-export-get-parent-headline headline)))
  457. (start-columns-p
  458. (or (equal environment "columns")
  459. (and column-width
  460. (not (and parent-env
  461. (equal (downcase parent-env) "columns")))
  462. (or (org-export-first-sibling-p headline info)
  463. (not (org-element-property
  464. :BEAMER_COL
  465. (org-export-get-previous-element
  466. headline info)))))))
  467. ;; End the "columns" environment when explicitly requested or
  468. ;; when there is no next headline or the next headline do not
  469. ;; have a BEAMER_column property.
  470. (end-columns-p
  471. (or (equal environment "columns")
  472. (and column-width
  473. (not (and parent-env
  474. (equal (downcase parent-env) "columns")))
  475. (or (org-export-last-sibling-p headline info)
  476. (not (org-element-property
  477. :BEAMER_COL
  478. (org-export-get-next-element headline info))))))))
  479. (concat
  480. (when start-columns-p
  481. ;; Column can accept options only when the environment is
  482. ;; explicitly defined.
  483. (if (not (equal environment "columns")) "\\begin{columns}\n"
  484. (format "\\begin{columns}%s\n" options)))
  485. (when column-width
  486. (format "\\begin{column}%s{%s}\n"
  487. ;; One can specify placement for column only when
  488. ;; HEADLINE stands for a column on its own.
  489. (if (equal environment "column") options "")
  490. (format "%s\\columnwidth" column-width)))
  491. ;; Block's opening string.
  492. (when (nth 2 env-format)
  493. (concat
  494. (org-fill-template
  495. (nth 2 env-format)
  496. (nconc
  497. ;; If BEAMER_act property has its value enclosed in square
  498. ;; brackets, it is a default overlay specification and
  499. ;; overlay specification is empty. Otherwise, it is an
  500. ;; overlay specification and the default one is nil.
  501. (let ((action (org-element-property :BEAMER_ACT headline)))
  502. (cond
  503. ((not action) (list (cons "a" "") (cons "A" "") (cons "R" "")))
  504. ((string-match "\\`\\[.*\\]\\'" action)
  505. (list
  506. (cons "A" (org-beamer--normalize-argument action 'defaction))
  507. (cons "a" "")
  508. (cons "R" action)))
  509. (t
  510. (list (cons "a" (org-beamer--normalize-argument action 'action))
  511. (cons "A" "")
  512. (cons "R" action)))))
  513. (list (cons "o" options)
  514. (cons "O" (or raw-options ""))
  515. (cons "h" title)
  516. (cons "r" raw-title)
  517. (cons "H" (if (equal raw-title "") ""
  518. (format "{%s}" raw-title)))
  519. (cons "U" (if (equal raw-title "") ""
  520. (format "[%s]" raw-title))))))
  521. "\n"))
  522. contents
  523. ;; Block's closing string, if any.
  524. (and (nth 3 env-format) (concat (nth 3 env-format) "\n"))
  525. (when column-width "\\end{column}\n")
  526. (when end-columns-p "\\end{columns}"))))
  527. (defun org-beamer-headline (headline contents info)
  528. "Transcode HEADLINE element into Beamer code.
  529. CONTENTS is the contents of the headline. INFO is a plist used
  530. as a communication channel."
  531. (unless (org-element-property :footnote-section-p headline)
  532. (let ((level (org-export-get-relative-level headline info))
  533. (frame-level (org-beamer--frame-level headline info))
  534. (environment (let ((env (org-element-property :BEAMER_ENV headline)))
  535. (or (org-string-nw-p env) "block"))))
  536. (cond
  537. ;; Case 1: Resume frame specified by "BEAMER_ref" property.
  538. ((equal environment "againframe")
  539. (let ((ref (org-element-property :BEAMER_REF headline)))
  540. ;; Reference to frame being resumed is mandatory. Ignore
  541. ;; the whole headline if it isn't provided.
  542. (when (org-string-nw-p ref)
  543. (concat "\\againframe"
  544. ;; Overlay specification.
  545. (let ((overlay (org-element-property :BEAMER_ACT headline)))
  546. (when overlay
  547. (org-beamer--normalize-argument
  548. overlay
  549. (if (string-match "\\`\\[.*\\]\\'" overlay) 'defaction
  550. 'action))))
  551. ;; Options.
  552. (let ((options (org-element-property :BEAMER_OPT headline)))
  553. (when options
  554. (org-beamer--normalize-argument options 'option)))
  555. ;; Resolve reference provided by "BEAMER_ref"
  556. ;; property. This is done by building a minimal
  557. ;; fake link and calling the appropriate resolve
  558. ;; function, depending on the reference syntax.
  559. (let ((target
  560. (if (string-match "\\`\\(id:\\|#\\)" ref)
  561. (org-export-resolve-id-link
  562. `(link (:path ,(substring ref (match-end 0))))
  563. info)
  564. (org-export-resolve-fuzzy-link
  565. `(link (:path
  566. ;; Look for headlines only.
  567. ,(if (eq (string-to-char ref) ?*) ref
  568. (concat "*" ref))))
  569. info))))
  570. ;; Now use user-defined label provided in TARGET
  571. ;; headline, or fallback to standard one.
  572. (format "{%s}" (org-beamer--get-label target info)))))))
  573. ;; Case 2: Creation of an appendix is requested.
  574. ((equal environment "appendix")
  575. (concat "\\appendix"
  576. (org-element-property :BEAMER_ACT headline)
  577. "\n"
  578. (make-string (org-element-property :pre-blank headline) ?\n)
  579. contents))
  580. ;; Case 3: Ignore heading.
  581. ((equal environment "ignoreheading")
  582. (concat (make-string (org-element-property :pre-blank headline) ?\n)
  583. contents))
  584. ;; Case 4: HEADLINE is a note.
  585. ((member environment '("note" "noteNH"))
  586. (format "\\note{%s}"
  587. (concat (and (equal environment "note")
  588. (concat
  589. (org-export-data
  590. (org-element-property :title headline) info)
  591. "\n"))
  592. (org-trim contents))))
  593. ;; Case 5: HEADLINE is a frame.
  594. ((= level frame-level)
  595. (org-beamer--format-frame headline contents info))
  596. ;; Case 6: Regular section, extracted from
  597. ;; `org-latex-classes'.
  598. ((< level frame-level)
  599. (org-beamer--format-section headline contents info))
  600. ;; Case 7: Otherwise, HEADLINE is a block.
  601. (t (org-beamer--format-block headline contents info))))))
  602. ;;;; Item
  603. (defun org-beamer-item (item contents info)
  604. "Transcode an ITEM element into Beamer code.
  605. CONTENTS holds the contents of the item. INFO is a plist holding
  606. contextual information."
  607. (org-export-with-backend
  608. ;; Delegate item export to `latex'. However, we use `beamer'
  609. ;; transcoders for objects in the description tag.
  610. (org-export-create-backend
  611. :parent 'beamer
  612. :transcoders
  613. (list
  614. (cons
  615. 'item
  616. (lambda (item _c _i)
  617. (let ((action
  618. (let ((first (car (org-element-contents item))))
  619. (and (eq (org-element-type first) 'paragraph)
  620. (org-beamer--element-has-overlay-p first))))
  621. (output (org-latex-item item contents info)))
  622. (if (not (and action (string-match "\\\\item" output))) output
  623. ;; If the item starts with a paragraph and that paragraph
  624. ;; starts with an export snippet specifying an overlay,
  625. ;; append it to the \item command.
  626. (replace-match (concat "\\\\item" action) nil nil output)))))))
  627. item contents info))
  628. ;;;; Keyword
  629. (defun org-beamer-keyword (keyword contents info)
  630. "Transcode a KEYWORD element into Beamer code.
  631. CONTENTS is nil. INFO is a plist used as a communication
  632. channel."
  633. (let ((key (org-element-property :key keyword))
  634. (value (org-element-property :value keyword)))
  635. ;; Handle specifically BEAMER and TOC (headlines only) keywords.
  636. ;; Otherwise, fallback to `latex' back-end.
  637. (cond
  638. ((equal key "BEAMER") value)
  639. ((and (equal key "TOC") (string-match "\\<headlines\\>" value))
  640. (let ((depth (or (and (string-match "[0-9]+" value)
  641. (string-to-number (match-string 0 value)))
  642. (plist-get info :with-toc)))
  643. (options (and (string-match "\\[.*?\\]" value)
  644. (match-string 0 value))))
  645. (concat
  646. (when (wholenump depth) (format "\\setcounter{tocdepth}{%s}\n" depth))
  647. "\\tableofcontents" options)))
  648. (t (org-export-with-backend 'latex keyword contents info)))))
  649. ;;;; Link
  650. (defun org-beamer-link (link contents info)
  651. "Transcode a LINK object into Beamer code.
  652. CONTENTS is the description part of the link. INFO is a plist
  653. used as a communication channel."
  654. (let ((type (org-element-property :type 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 (cl-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