1 ;;; ox-extra.el --- Convenience functions for org export
3 ;; Copyright (C) 2014 Aaron Ecay
5 ;; Author: Aaron Ecay <aaronecay@gmail.com>
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ;; This file contains some convenience functions for org export, which
23 ;; are not part of org's core. Call `ox-extras-activate' passing a
24 ;; list of symbols naming extras, which will be installed globally in
27 ;; Currently available extras:
29 ;; - `latex-header-blocks' -- allow the use of latex blocks, the
30 ;; contents of which which will be interpreted as #+latex_header lines
31 ;; for export. These blocks should be tagged with #+header: :header
33 ;; #+header: :header yes
39 ;; - add a function to org-mode-hook that looks for a ox-extras local
40 ;; variable and activates the specified extras buffer-locally
41 ;; - allow specification of desired extras to be activated via
47 (eval-when-compile (require 'cl
))
49 (defun org-latex-header-blocks-filter (backend)
50 (when (org-export-derived-backend-p backend
'latex
)
52 (org-element-map (org-element-parse-buffer 'greater-element nil
) 'export-block
54 (when (and (string= (org-element-property :type block
) "LATEX")
55 (string= (org-export-read-attribute
56 :header block
:header
)
58 (list (org-element-property :begin block
)
59 (org-element-property :end block
)
60 (org-element-property :post-affiliated block
)))))))
62 (goto-char (nth 2 pos
))
64 (beg end
&rest ignore
)
65 (org-edit-src-find-region-and-lang)
66 (let ((contents-lines (split-string
67 (buffer-substring-no-properties beg end
)
69 (delete-region (nth 0 pos
) (nth 1 pos
))
70 (dolist (line contents-lines
)
71 (insert (concat "#+latex_header: "
72 (replace-regexp-in-string "\\` *" "" line
)
74 ;; go in reverse, to avoid wrecking the numeric positions
75 ;; earlier in the file
76 (reverse positions
)))))
79 '((latex-header-blocks org-latex-header-blocks-filter org-export-before-parsing-hook
))
80 "A list of org export extras that can be enabled.
82 Should be a list of items of the form (NAME FN HOOK). NAME is a
83 symbol, which can be passed to `ox-extras-activate'. FN is a
84 function which will be added to HOOK.")
86 (defun ox-extras-activate (extras)
87 "Activate certain org export extras.
89 EXTRAS should be a list of extras (defined in `ox-extras') which
91 (dolist (extra extras
)
92 (let* ((lst (assq extra ox-extras
))
96 (add-hook hook fn
)))))
98 (defun ox-extras-deactivate (extras)
99 "Deactivate certain org export extras.
101 This function is the opposite of `ox-extras-activate'. EXTRAS
102 should be a list of extras (defined in `ox-extras') which should
104 (dolist (extra extras
)
105 (let* ((lst (assq extra ox-extras
))
109 (remove-hook hook fn
)))))
112 ;;; ox-extra.el ends here