org-beamer.el 22 KB

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