org-beamer.el 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. ;;; org-beamer.el --- Beamer-specific LaTeX export for org-mode
  2. ;;
  3. ;; Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
  4. ;;
  5. ;; Version: 6.33trans
  6. ;; Author: Carsten Dominik <carsten.dominik AT gmail DOT com>
  7. ;; Maintainer: Carsten Dominik <carsten.dominik AT gmail DOT com>
  8. ;; Keywords: org, wp, tex
  9. ;; This file is part of GNU Emacs.
  10. ;; GNU Emacs is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  20. ;;; Commentary:
  21. ;;
  22. ;; This library implement the special treatment needed by using the
  23. ;; beamer class during LaTeX export.
  24. (require 'org)
  25. (require 'org-exp)
  26. (defvar org-export-latex-header)
  27. (defvar org-export-latex-options-plist)
  28. (defvar org-export-opt-plist)
  29. (defgroup org-beamer nil
  30. "Options specific for using the beamer class in LaTeX export."
  31. :tag "Org Beamer"
  32. :group 'org-export-latex)
  33. (defcustom org-beamer-use-parts nil
  34. ""
  35. :group 'org-beamer
  36. :type 'boolean)
  37. (defcustom org-beamer-frame-level 1
  38. "The level that should be interpreted as a frame.
  39. The levels above this one will be translated into a sectioning structure.
  40. Setting this to 2 will allow sections, 3 will allow subsections as well.
  41. You can se this to 4 as well, if you at the same time set
  42. `org-beamer-use-parts' to make the top levels `\part'."
  43. :group 'org-beamer
  44. :type '(choice
  45. (const :tag "Frames need a BEAMER_env property" nil)
  46. (integer :tag "Specific level makes a frame")))
  47. (defcustom org-beamer-column-view-format
  48. "%45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)"
  49. "Default column view format that should be used to fill the template."
  50. :group 'org-beamer
  51. :type '(string :tag "Beamer column view format"))
  52. (defcustom org-beamer-themes
  53. "\\usetheme{default}\\usecolortheme{default}"
  54. "Default string to be used for extra heading stuff in beamer presentations.
  55. When a beamer template is filled, this will be the default for
  56. BEAMER_HEADER_EXTRA, which will be inserted just before \\begin{document}."
  57. :group 'org-beamer
  58. :type '(string :tag "Beamer column view format"))
  59. (defconst org-beamer-column-widths
  60. "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.0 :ETC"
  61. "The column widths that should be installed as allowed property values.")
  62. (defconst org-beamer-transitions
  63. "\transblindsvertical \transblindshorizontal \transboxin \transboxout \transdissolve \transduration \transglitter \transsplithorizontalin \transsplithorizontalout \transsplitverticalin \transsplitverticalout \transwipe :ETC"
  64. "Transitions available for beamer.
  65. These are just a completion help.")
  66. (defconst org-beamer-environments-default
  67. '(("frame" "f" "dummy- special handling hard coded" "dummy")
  68. ("columns" "C" "\\begin{columns}%o %% %h%x" "\\end{columns}")
  69. ("column" "c" "\\begin{column}%o{%h\\textwidth}%x" "\\end{column}")
  70. ("block" "b" "\\begin{block}%a{%h}%x" "\\end{block}")
  71. ("alertblock" "a" "\\begin{alertblock}%a{%h}%x" "\\end{alertblock}")
  72. ("verse" "v" "\\begin{verse}%a %% %h%x" "\\end{verse}")
  73. ("quotation" "q" "\\begin{quotation}%a %% %h%x" "\\end{quotation}")
  74. ("quote" "Q" "\\begin{quote}%a %% %h%x" "\\end{quote}")
  75. ("structureenv" "s" "\\begin{structureenv}%a %% %h%x" "\\end{structureenv}")
  76. ("theorem" "t" "\\begin{theorem}%a%U%x" "\\end{theorem}")
  77. ("definition" "d" "\\begin{definition}%a%U%x" "\\end{definition}")
  78. ("example" "e" "\\begin{example}%a%U%x" "\\end{example}")
  79. ("proof" "p" "\\begin{proof}%a%U%x" "\\end{proof}")
  80. ("beamercolorbox" "o" "\\begin{beamercolorbox}%o{%h}%x" "\\end{beamercolorbox}")
  81. ("normal" "h" "%h" "") ; Emit the heading as normal text
  82. ("note" "n" "\\note%o%a{%h" "}")
  83. ("noteNH" "N" "\\note%o%a{" "}") ; note, ignore heading
  84. ("ignoreheading" "i" "%%%% %h" ""))
  85. "Environments triggered by properties in Beamer export.
  86. These are the defaults - for user definitions, see
  87. `org-beamer-environments-extra'.
  88. \"normal\" is a special fake environment, which emite the heading as
  89. normal text. It is needed when an environment should be surrounded
  90. by normal text. Since beamer export converts nodes into environments,
  91. you need to have a node to end the environment.
  92. For example
  93. ** a frame
  94. some text
  95. *** Blocktitle :B_block:
  96. inside the block
  97. *** After the block :B_normal:
  98. continuing here
  99. ** next frame")
  100. (defcustom org-beamer-environments-extra nil
  101. "Environments triggered by tags in Beamer export.
  102. Each entry has 4 elements:
  103. name Name of the environment
  104. key Selection key for `org-beamer-set-environment-tag'
  105. open The opening template for the environment, with the following excapes
  106. %a the action/overlay specification
  107. %A the default action/overlay specification
  108. %o the options argument of the template
  109. %h the headline text
  110. %H if there is headline text, that text in {} braces
  111. %U if there is headline text, that text in [] brackets
  112. close The closing string of the environment."
  113. :group 'org-beamer
  114. :type '(repeat
  115. (list
  116. (string :tag "Environment")
  117. (string :tag "Selection key")
  118. (string :tag "Begin")
  119. (string :tag "End"))))
  120. (defvar org-beamer-frame-level-now nil)
  121. (defvar org-beamer-header-extra nil)
  122. (defvar org-beamer-export-is-beamer-p nil)
  123. (defvar org-beamer-inside-frame-at-level nil)
  124. (defvar org-beamer-columns-open nil)
  125. (defvar org-beamer-column-open nil)
  126. (defun org-beamer-cleanup-column-width (width)
  127. "Make sure the width is not empty, and that it has a unit."
  128. (setq width (org-trim (or width "")))
  129. (unless (string-match "\\S-" width) (setq width "0.5"))
  130. (if (string-match "\\`[.0-9]+\\'" width)
  131. (setq width (concat width "\\textwidth")))
  132. width)
  133. (defun org-beamer-open-column (&optional width opt)
  134. (org-beamer-close-column-maybe)
  135. (setq org-beamer-column-open t)
  136. (setq width (org-beamer-cleanup-column-width width))
  137. (insert (format "\\begin{column}%s{%s}\n" (or opt "") width)))
  138. (defun org-beamer-close-column-maybe ()
  139. (when org-beamer-column-open
  140. (setq org-beamer-column-open nil)
  141. (insert "\\end{column}\n")))
  142. (defun org-beamer-open-columns-maybe (&optional opts)
  143. (unless org-beamer-columns-open
  144. (setq org-beamer-columns-open t)
  145. (insert (format "\\begin{columns}%s\n" (or opts "")))))
  146. (defun org-beamer-close-columns-maybe ()
  147. (org-beamer-close-column-maybe)
  148. (when org-beamer-columns-open
  149. (setq org-beamer-columns-open nil)
  150. (insert "\\end{columns}\n")))
  151. (defun org-beamer-set-environment-tag ()
  152. "Set an environment tag, to determine the beamer environment to be used.
  153. This makes use of the fast tag selection interface."
  154. (interactive)
  155. (let* ((envs (append org-beamer-environments-extra
  156. org-beamer-environments-default))
  157. (org-tag-alist
  158. (append '((:startgroup))
  159. (mapcar (lambda (e) (cons (concat "B_" (car e))
  160. (string-to-char (nth 1 e))))
  161. envs)
  162. '((:endgroup))
  163. '(("BMCOL" . ?|))))
  164. (org-fast-tag-selection-single-key t))
  165. (org-set-tags)
  166. (let ((tags (or (ignore-errors (org-get-tags-string)) "")))
  167. (cond
  168. ((equal org-last-tag-selection-key ?|)
  169. (if (string-match ":BMCOL:" tags)
  170. (org-set-property "BEAMER_col" (read-string "Column width: "))
  171. (org-delete-property "BEAMER_col")))
  172. ((string-match (concat ":B_\\("
  173. (mapconcat 'car envs "\\|")
  174. "\\):")
  175. tags)
  176. (org-entry-put nil "BEAMER_env" (match-string 1 tags)))
  177. (t (org-entry-delete nil "BEAMER_env"))))))
  178. (defun org-beamer-sectioning (level text)
  179. "Return the sectioning entry for the current headline.
  180. LEVEL is the reduced level of the headline.
  181. TEXT is the text of the headline, everything except the leading stars.
  182. The return value is a cons cell. The car is the headline text, usually
  183. just TEXT, but possibly modified if options have been extracted from the
  184. text. The cdr is the sectioning entry, similar to what is given
  185. in org-export-latex-classes."
  186. (let* ((frame-level (or org-beamer-frame-level-now org-beamer-frame-level))
  187. (default
  188. (if org-beamer-use-parts
  189. '((1 . ("\\part{%s}" . "\\part*{%s}"))
  190. (2 . ("\\section{%s}" . "\\section*{%s}"))
  191. (3 . ("\\subsection{%s}" . "\\subsection*{%s}")))
  192. '((1 . ("\\section{%s}" . "\\section*{%s}"))
  193. (2 . ("\\subsection{%s}" . "\\subsection*{%s}")))))
  194. (envs (append org-beamer-environments-extra
  195. org-beamer-environments-default))
  196. (props (org-get-text-property-any 0 'org-props text))
  197. (in "") (out "") option action defaction environment extra
  198. columns-option column-option
  199. env have-text ass tmp)
  200. (if (= frame-level 0) (setq frame-level nil))
  201. (when (and org-beamer-inside-frame-at-level
  202. (<= level org-beamer-inside-frame-at-level))
  203. (setq org-beamer-inside-frame-at-level nil))
  204. (when (setq tmp (org-beamer-assoc-not-empty "BEAMER_col" props))
  205. (if (and (string-match "\\`[0-9.]+\\'" tmp)
  206. (or (= (string-to-number tmp) 1.0)
  207. (= (string-to-number tmp) 0.0)))
  208. ;; column width 1 means cloase columns, go back to full width
  209. (org-beamer-close-columns-maybe)
  210. (when (setq ass (assoc "BEAMER_envargs" props))
  211. (let (case-fold-search)
  212. (when (string-match "C\\(\\[[^][]*\\]\\)" (cdr ass))
  213. (setq columns-option (match-string 1 (cdr ass)))
  214. (setcdr ass (replace-match "" t t (cdr ass))))
  215. (when (string-match "c\\(\\[[^][]*\\]\\)" (cdr ass))
  216. (setq column-option (match-string 1 (cdr ass)))
  217. (setcdr ass (replace-match "" t t (cdr ass))))))
  218. (org-beamer-open-columns-maybe columns-option)
  219. (org-beamer-open-column tmp column-option)))
  220. (cond
  221. ((or (equal (cdr (assoc "BEAMER_env" props)) "frame")
  222. (and frame-level (= level frame-level)))
  223. ;; A frame
  224. (org-beamer-get-special props)
  225. (setq in (org-fill-template
  226. "\\begin{frame}%a%A%o%T%S%x"
  227. (list (cons "a" (or action ""))
  228. (cons "A" (or defaction ""))
  229. (cons "o" (or option ""))
  230. (cons "x" (if extra (concat "\n" extra) ""))
  231. (cons "h" "%s")
  232. (cons "T" (if (string-match "\\S-" text)
  233. "\n\\frametitle{%s}" ""))
  234. (cons "S" (if (string-match "\\\\\\\\" text)
  235. "\n\\framesubtitle{%s}" ""))))
  236. out (copy-sequence "\\end{frame}"))
  237. (org-add-props out
  238. '(org-insert-hook org-beamer-close-columns-maybe))
  239. (setq org-beamer-inside-frame-at-level level)
  240. (cons text (list in out in out)))
  241. ((and (setq env (cdr (assoc "BEAMER_env" props)))
  242. (setq ass (assoc env envs)))
  243. ;; A beamer environment selected by the BEAMER_env property
  244. (if (string-match "[ \t]+:[ \t]*$" text)
  245. (setq text (replace-match "" t t text)))
  246. (if (member env '("note" "noteNH"))
  247. ;; There should be no labels in a note, so we remove the targets
  248. ;; FIXME???
  249. (remove-text-properties 0 (length text) '(target nil) text))
  250. (org-beamer-get-special props)
  251. (setq text (org-trim text))
  252. (setq have-text (string-match "\\S-" text))
  253. (setq in (org-fill-template
  254. (nth 2 ass)
  255. (list (cons "a" (or action ""))
  256. (cons "A" (or defaction ""))
  257. (cons "o" (or option ""))
  258. (cons "x" (if extra (concat "\n" extra) ""))
  259. (cons "h" "%s")
  260. (cons "H" (if have-text (concat "{" text "}") ""))
  261. (cons "U" (if have-text (concat "[" text "]") ""))))
  262. out (nth 3 ass))
  263. (cond
  264. ((equal out "\\end{columns}")
  265. (setq org-beamer-columns-open t)
  266. (setq out (org-add-props (copy-sequence out)
  267. '(org-insert-hook
  268. (lambda ()
  269. (org-beamer-close-column-maybe)
  270. (setq org-beamer-columns-open nil))))))
  271. ((equal out "\\end{column}")
  272. (org-beamer-open-columns-maybe)))
  273. (cons text (list in out in out)))
  274. ((and (not org-beamer-inside-frame-at-level)
  275. (or (not frame-level)
  276. (< level frame-level))
  277. (assoc level default))
  278. ;; Normal sectioning
  279. (cons text (cdr (assoc level default))))
  280. (t nil))))
  281. (defvar extra)
  282. (defvar option)
  283. (defvar action)
  284. (defvar defaction)
  285. (defvar environment)
  286. (defun org-beamer-get-special (props)
  287. "Extract an option, action, and default action string from text.
  288. The variables option, action, defaction, extra are all scoped into
  289. this function dynamically."
  290. (let (tmp)
  291. (setq environment (org-beamer-assoc-not-empty "BEAMER_env" props))
  292. (setq extra (org-beamer-assoc-not-empty "BEAMER_extra" props))
  293. (when extra
  294. (setq extra (replace-regexp-in-string "\\\\n" "\n" extra)))
  295. (setq tmp (org-beamer-assoc-not-empty "BEAMER_envargs" props))
  296. (when tmp
  297. (setq tmp (copy-sequence tmp))
  298. (if (string-match "\\[<[^][<>]*>\\]" tmp)
  299. (setq defaction (match-string 0 tmp)
  300. tmp (replace-match "" t t tmp)))
  301. (if (string-match "\\[[^][]*\\]" tmp)
  302. (setq option (match-string 0 tmp)
  303. tmp (replace-match "" t t tmp)))
  304. (if (string-match "<[^<>]*>" tmp)
  305. (setq action (match-string 0 tmp)
  306. tmp (replace-match "" t t tmp))))))
  307. (defun org-beamer-assoc-not-empty (elt list)
  308. (let ((tmp (cdr (assoc elt list))))
  309. (and tmp (string-match "\\S-" tmp) tmp)))
  310. (defvar org-beamer-mode-map (make-sparse-keymap)
  311. "The keymap for `org-beamer-mode'.")
  312. (define-key org-beamer-mode-map "\C-c\C-b" 'org-beamer-set-environment-tag)
  313. (define-minor-mode org-beamer-mode
  314. "Special support for editing Org-mode files made to export to beamer."
  315. nil " Bm" nil)
  316. (font-lock-add-keywords
  317. 'org-mode
  318. '((":\\(B_[a-z]+\\|BMCOL\\):" 1 'org-beamer-tag prepend))
  319. 'prepent)
  320. (defun org-beamer-place-default-actions-for-lists ()
  321. "Find default overlay specifications in items, and move them.
  322. The need to be after the begin statement of the environment."
  323. (when org-beamer-export-is-beamer-p
  324. (let (dovl)
  325. (goto-char (point-min))
  326. (while (re-search-forward
  327. "^[ \t]*\\\\begin{\\(itemize\\|enumerate\\|desctiption\\)}[ \t\n]*\\\\item\\>\\( ?\\(<[^<>\n]*>\\|\\[[^][\n*]\\]\\)\\)?[ \t]*\\S-" nil t)
  328. (if (setq dovl (cdr (assoc "BEAMER_dovl"
  329. (get-text-property (match-end 0)
  330. 'org-props))))
  331. (save-excursion
  332. (goto-char (1+ (match-end 1)))
  333. (insert dovl)))))))
  334. (defun org-beamer-amend-header ()
  335. (when (and org-beamer-export-is-beamer-p
  336. org-beamer-header-extra)
  337. (goto-char (point-min))
  338. (when (re-search-forward "^[ \t]*\\\\begin{document}" nil t)
  339. (goto-char (match-beginning 0))
  340. (insert org-beamer-header-extra)
  341. (or (bolp) (insert "\n")))))
  342. (defcustom org-beamer-fragile-re "^[ \t]*\\\\begin{verbatim}"
  343. "If this regexp matches in a frame, the frame is marked as fragile."
  344. :group 'org-beamer
  345. :type 'regexp)
  346. (defface org-beamer-tag '((t (:box (:line-width 1 :color grey40))))
  347. "The special face for beamer tags."
  348. :group 'org-beamer)
  349. ;; Functions to initialize and post-process
  350. ;; These fuctions will be hooked into various places in the export process
  351. (defun org-beamer-initialize-open-trackers ()
  352. "Reset variables that track if certain environments are open during export."
  353. (setq org-beamer-columns-open nil)
  354. (setq org-beamer-column-open nil)
  355. (setq org-beamer-inside-frame-at-level nil)
  356. (setq org-beamer-export-is-beamer-p nil))
  357. (defun org-beamer-after-initial-vars ()
  358. "Find special setings for beamer and store them.
  359. The effect is that these values will be accessible during export."
  360. ;; First verify that we are exporting using the beamer class
  361. (setq org-beamer-export-is-beamer-p
  362. (string-match "\\\\documentclass\\(\\[[^][]*?\\]\\)?{beamer}"
  363. org-export-latex-header))
  364. (when org-beamer-export-is-beamer-p
  365. ;; Find the frame level
  366. (setq org-beamer-frame-level-now
  367. (or (and (org-region-active-p)
  368. (save-excursion
  369. (goto-char (region-beginning))
  370. (and (looking-at org-complex-heading-regexp)
  371. (org-entry-get nil "BEAMER_FRAME_LEVEL" 'selective))))
  372. (save-excursion
  373. (save-restriction
  374. (widen)
  375. (goto-char (point-min))
  376. (and (re-search-forward
  377. "^#\\+BEAMER_FRAME_LEVEL:[ \t]*\\(.*?\\)[ \t]*$" nil t)
  378. (match-string 1))))
  379. (plist-get org-export-latex-options-plist :beamer-frame-level)
  380. org-beamer-frame-level))
  381. ;; Normalize the value so that the functions can trust the value
  382. (cond
  383. ((not org-beamer-frame-level-now)
  384. (setq org-beamer-frame-level-now nil))
  385. ((stringp org-beamer-frame-level-now)
  386. (setq org-beamer-frame-level-now
  387. (string-to-number org-beamer-frame-level-now))))
  388. ;; Find the header additons, most likely theme commands
  389. (setq org-beamer-header-extra
  390. (or (and (org-region-active-p)
  391. (save-excursion
  392. (goto-char (region-beginning))
  393. (and (looking-at org-complex-heading-regexp)
  394. (org-entry-get nil "BEAMER_HEADER_EXTRA"
  395. 'selective))))
  396. (save-excursion
  397. (save-restriction
  398. (widen)
  399. (let ((txt ""))
  400. (goto-char (point-min))
  401. (while (re-search-forward
  402. "^#\\+BEAMER_HEADER_EXTRA:[ \t]*\\(.*?\\)[ \t]*$"
  403. nil t)
  404. (setq txt (concat txt "\n" (match-string 1))))
  405. (if (> (length txt) 0) (substring txt 1)))))
  406. (plist-get org-export-latex-options-plist
  407. :beamer-header-extra)))
  408. (let ((inhibit-read-only t)
  409. (case-fold-search nil)
  410. props)
  411. (org-unmodified
  412. (remove-text-properties (point-min) (point-max) '(org-props nil))
  413. (org-map-entries
  414. '(progn
  415. (setq props (org-entry-properties nil 'standard))
  416. (if (and (not (assoc "BEAMER_env" props))
  417. (looking-at ".*?:B_\\(note\\(NH\\)?\\):"))
  418. (push (cons "BEAMER_env" (match-string 1)) props))
  419. (put-text-property (point-at-bol) (point-at-eol) 'org-props props)))
  420. (setq org-export-latex-options-plist
  421. (plist-put org-export-latex-options-plist :tags nil))))))
  422. (defun org-beamer-auto-fragile-frames ()
  423. "Mark any frames containing verbatim environments as fragile.
  424. This funcion will run in the final LaTeX document."
  425. (when org-beamer-export-is-beamer-p
  426. (let (opts)
  427. (goto-char (point-min))
  428. ;; Find something that might be fragile
  429. (while (re-search-forward org-beamer-fragile-re nil t)
  430. (save-excursion
  431. ;; Are we inside a frame here?
  432. (when (and (re-search-backward "^[ \t]*\\\\\\(begin\\|end\\){frame}"
  433. nil t)
  434. (equal (match-string 1) "begin"))
  435. ;; yes, inside a frame, make sure "fragile" is one of the options
  436. (goto-char (match-end 0))
  437. (if (not (looking-at "\\[.*?\\]"))
  438. (insert "[fragile]")
  439. (setq opts (substring (match-string 0) 1 -1))
  440. (delete-region (match-beginning 0) (match-end 0))
  441. (setq opts (org-split-string opts ","))
  442. (add-to-list 'opts "fragile")
  443. (insert "[" (mapconcat 'identity opts ",") "]"))))))))
  444. (defun org-beamer-fix-toc ()
  445. "Fix the table of contents by removing the vspace line."
  446. (when org-beamer-export-is-beamer-p
  447. (save-excursion
  448. (goto-char (point-min))
  449. (when (re-search-forward "\\\\setcounter{tocdepth.*\n\\\\tableofcontents.*\n\\(\\\\vspace\\*.*\\)" nil t)
  450. (delete-region (match-beginning 1) (match-end 1))))))
  451. (defun org-beamer-property-changed (property value)
  452. "Track the BEAMER_env property with tags."
  453. (cond
  454. ((equal property "BEAMER_env")
  455. (save-excursion
  456. (org-back-to-heading t)
  457. (let ((tags (org-get-tags)))
  458. (setq tags (delq nil (mapcar (lambda (x)
  459. (if (string-match "^B_" x) nil x))
  460. tags)))
  461. (org-set-tags-to tags))
  462. (when (and value (stringp value) (string-match "\\S-" value))
  463. (org-toggle-tag (concat "B_" value) 'on))))
  464. ((equal property "BEAMER_col")
  465. (org-toggle-tag "BMCOL" (if (and value (string-match "\\S-" value))
  466. 'on 'off)))))
  467. (defun org-beamer-select-beamer-code ()
  468. "Take code marked for BEAMER and turn it into marked for LaTeX."
  469. (when org-beamer-export-is-beamer-p
  470. (goto-char (point-min))
  471. (while (re-search-forward
  472. "^\\([ \]*#\\+\\(begin_\\|end_\\)?\\)\\(beamer\\)\\>" nil t)
  473. (replace-match "\\1latex"))))
  474. ;; OK, hook all these functions into appropriate places
  475. (add-hook 'org-export-first-hook
  476. 'org-beamer-initialize-open-trackers)
  477. (add-hook 'org-property-changed-functions
  478. 'org-beamer-property-changed)
  479. (add-hook 'org-export-latex-after-initial-vars-hook
  480. 'org-beamer-after-initial-vars)
  481. (add-hook 'org-export-latex-final-hook
  482. 'org-beamer-place-default-actions-for-lists)
  483. (add-hook 'org-export-latex-final-hook
  484. 'org-beamer-auto-fragile-frames)
  485. (add-hook 'org-export-latex-final-hook
  486. 'org-beamer-fix-toc)
  487. (add-hook 'org-export-latex-final-hook
  488. 'org-beamer-amend-header)
  489. (add-hook 'org-export-preprocess-before-selecting-backend-code-hook
  490. 'org-beamer-select-beamer-code)
  491. (defun org-beamer-settings-template (kind)
  492. "Insert a settings template, to make sure users do this right."
  493. (interactive (progn
  494. (message "Current [s]ubtree or [g]lobal?")
  495. (if (equal (read-char-exclusive) ?g)
  496. (list 'global)
  497. (list 'subtree))))
  498. (if (eq kind 'subtree)
  499. (progn
  500. (org-back-to-heading t)
  501. (org-reveal)
  502. (org-entry-put nil "LaTeX_CLASS" "beamer")
  503. (org-entry-put nil "LaTeX_CLASS_OPTIONS" "[presentation]")
  504. (org-entry-put nil "EXPORT_FILE_NAME" "presentation.pdf")
  505. (org-entry-put nil "BEAMER_FRAME_LEVEL" (number-to-string
  506. org-beamer-frame-level))
  507. (org-entry-put nil "BEAMER_HEADER_EXTRA" org-beamer-themes)
  508. (org-entry-put nil "COLUMNS" org-beamer-column-view-format)
  509. (org-entry-put nil "BEAMER_col_ALL" "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC"))
  510. (insert "#+LaTeX_CLASS: beamer\n")
  511. (insert "#+LaTeX_CLASS_OPTIONS: [presentation]\n")
  512. (insert (format "#+BEAMER_FRAME_LEVEL: %d\n" org-beamer-frame-level) "\n")
  513. (insert "#+BEAMER_HEADER_EXTRA: " org-beamer-themes "\n")
  514. (insert "#+COLUMNS: " org-beamer-column-view-format "\n")
  515. (insert "#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC\n")))
  516. (defun org-beamer-allowed-property-values (property)
  517. "Supply allowed values for BEAMER properties."
  518. (cond
  519. ((and (equal property "BEAMER_env")
  520. (not (org-entry-get nil (concat property "_ALL") 'inherit)))
  521. ;; If no allowed values for BEAMER_env have been defined,
  522. ;; supply all defined environments
  523. (mapcar 'car (append org-beamer-environments-extra
  524. org-beamer-environments-default)))
  525. ((and (equal property "BEAMER_col")
  526. (not (org-entry-get nil (concat property "_ALL") 'inherit)))
  527. ;; If no allowed values for BEAMER_col have been defined,
  528. ;; supply some
  529. '("0.1" "0.2" "0.3" "0.4" "0.5" "0.6" "0.7" "0.8" "0.9" "" ":ETC"))
  530. (t nil)))
  531. (add-hook 'org-property-allowed-value-functions
  532. 'org-beamer-allowed-property-values)
  533. (provide 'org-beamer)
  534. ;; arch-tag: 68bac91a-a946-43a3-8173-a9269306f67c
  535. ;;; org-beamer.el ends here