[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Exporting to multiple files
From: |
Richard Lawrence |
Subject: |
Re: [O] Exporting to multiple files |
Date: |
Thu, 13 Mar 2014 10:38:37 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) |
Hi Marcin,
Marcin Borkowski <address@hidden> writes:
>
> I'd like to export an Org-mode file to /multiple/ HTML files. For
> instance, I might want to convert all first and second level headings
> to files, and third-level headings to <h1>, fourth-level ones to <h2>
> inside these files etc. Is that possible? I looked into the docs, but
> didn't find anything like this.
I once wrote a function that does something like this. (I haven't used
it since the pre-8.0 days, though, so it probably needs updating.) It
creates individual PDFs from the subtrees under a headline, then
concatenates them into one PDF using an external program (pdftk).
Naming is done based on the EXPORT_FILE_NAME property as usual. Maybe
you can use it as a skeleton:
#+BEGIN_SRC elisp
;; utilities for exporting the subtrees of a tree as individual PDFS
;; and as a single, concatenated PDF
(defun org-export-individual-pdfs-and-concat ()
(interactive)
(setq export-files nil
pdf-files nil
; point must be in main tree to be exported (not a subtree)
concat-pdf-name (get-property-or-fail (point) "CONCATENATED_PDF_NAME"))
(progn
(org-map-entries
(lambda ()
(setq org-map-continue-from (outline-next-heading))
(org-mark-subtree)
; org-map-entries positions point at the beginning of each subtree
(if org-map-continue-from ; non-nil if outline-next-heading found a
heading
(let ((org-trust-scanner-tags t))
(push (get-property-or-fail (point) "EXPORT_FILE_NAME")
export-files)))
(mapcar 'message (org-get-tags))
(org-export-as-pdf nil)) ; TODO: why doesn't this respect noexport tag?
nil 'tree)
(concat-pdfs (nreverse (mapcar 'tex-name-to-pdf-name export-files))
concat-pdf-name)))
(defun get-property-or-fail (pom property)
(or
; probably some opportunity for optimization here...see function
; documentation for org-map-entries
(org-entry-get pom property)
(error (format "Entry at %s does not define property %s"
(org-heading-components) property))))
(defun tex-name-to-pdf-name (filename)
(concat (file-name-sans-extension filename) ".pdf"))
(defun concat-pdfs (in-files out-file)
(shell-command
(format "pdftk %s cat output %s"
(mapconcat (lambda (s) s) in-files " ") ; join pdf names with spaces
out-file)))
#+END_SRC
Another option that occurs to me -- though it may not serve your needs
-- is to export your Org file to texinfo format. I believe the texinfo
compiler can then generate separate separate HTML files for the
different sections in your .texi file. Might be worth a try.
--
Best,
Richard