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