org-beamer.el 23 KB

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