ox-beamer.el 42 KB

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