ox-beamer.el 43 KB

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