emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* ePub and Org mode
@ 2011-02-19  9:25 Alan L Tyree
  2011-02-19 10:54 ` Bastien
  2011-02-19 21:46 ` Christian Moe
  0 siblings, 2 replies; 9+ messages in thread
From: Alan L Tyree @ 2011-02-19  9:25 UTC (permalink / raw)
  To: emacs-orgmode

Greetings from Down Under,
I am constructing an ePub formatted book. It came to me in plain text and I have formatted in org-mode.

It is easy to export to XHTML, the first step in ePub construction, but I would like every chapter to be a separate file. It is easy enough to do this with a macro or a simple function (even though I am no elisp guru). Is there an export function that does this? I didn't see it in the docs and I don't see anything about it doing a Google search.

What would really be nice, is a single command to create the ePub file.

Any help appreciated.

Cheers,
Alan

-- 
Alan L Tyree <alantyree@gmail.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ePub and Org mode
  2011-02-19  9:25 ePub and Org mode Alan L Tyree
@ 2011-02-19 10:54 ` Bastien
  2011-02-19 19:14   ` Alan L Tyree
  2011-02-19 21:46 ` Christian Moe
  1 sibling, 1 reply; 9+ messages in thread
From: Bastien @ 2011-02-19 10:54 UTC (permalink / raw)
  To: Alan L Tyree; +Cc: emacs-orgmode

Hi Alan,

Alan L Tyree <alantyree@gmail.com> writes:

> It is easy to export to XHTML, the first step in ePub construction, but I
> would like every chapter to be a separate file. It is easy enough to do
> this with a macro or a simple function (even though I am no elisp
> guru). 

Please share your functions!

> Is there an export function that does this?

Nope.

> What would really be nice, is a single command to create the ePub
> file.

Agreed.

Let us know how your manual workarounds work and it might give us ideas
on how to implement this as a single command.

-- 
 Bastien

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ePub and Org mode
  2011-02-19 10:54 ` Bastien
@ 2011-02-19 19:14   ` Alan L Tyree
  0 siblings, 0 replies; 9+ messages in thread
From: Alan L Tyree @ 2011-02-19 19:14 UTC (permalink / raw)
  To: emacs-orgmode

On Sat, 19 Feb 2011 11:54:38 +0100
Bastien <bastien.guerry@wikimedia.fr> wrote:

> Hi Alan,
> 
> Alan L Tyree <alantyree@gmail.com> writes:
> 
> > It is easy to export to XHTML, the first step in ePub construction,
> > but I would like every chapter to be a separate file. It is easy
> > enough to do this with a macro or a simple function (even though I
> > am no elisp guru). 
> 
> Please share your functions!

I'll be happy to --- once I have written them! I was hoping that the
answer would be 'yes' to the question below.

Thanks for the quick response,
Alan

> 
> > Is there an export function that does this?
> 
> Nope.
> 
> > What would really be nice, is a single command to create the ePub
> > file.
> 
> Agreed.
> 
> Let us know how your manual workarounds work and it might give us
> ideas on how to implement this as a single command.
> 
> -- 
>  Bastien


-- 
Alan L Tyree                    http://www2.austlii.edu.au/~alan
Tel:  04 2748 6206

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ePub and Org mode
  2011-02-19  9:25 ePub and Org mode Alan L Tyree
  2011-02-19 10:54 ` Bastien
@ 2011-02-19 21:46 ` Christian Moe
  2011-02-19 22:15   ` Alan L Tyree
  2011-02-20  7:53   ` Achim Gratz
  1 sibling, 2 replies; 9+ messages in thread
From: Christian Moe @ 2011-02-19 21:46 UTC (permalink / raw)
  To: Alan L Tyree; +Cc: emacs-orgmode

Hi,

I agree exporting 'chapters' in a single Org document to separate html 
files would be a nice option to have.

Pending someone writing an export function for this, you could

- post-process the HTML with one of the scripts out there for 
splitting up web pages, like htsplit available on CPAN;

- or go the Org -> DocBook -> `chunked' HTML route?

But just out of curiosity, why would you like this for the purpose of 
making an ePub book? Are you using a tool that requires it? (Unlike, 
e.g., Calibre, which takes a single HTML file as input, with TOC built 
from e.g. H2 as chapter headings.)

Yours,
Christian


On 2/19/11 10:25 AM, Alan L Tyree wrote:
> Greetings from Down Under,
> I am constructing an ePub formatted book. It came to me in plain text and I have formatted in org-mode.
>
> It is easy to export to XHTML, the first step in ePub construction, but I would like every chapter to be a separate file. It is easy enough to do this with a macro or a simple function (even though I am no elisp guru). Is there an export function that does this? I didn't see it in the docs and I don't see anything about it doing a Google search.
>
> What would really be nice, is a single command to create the ePub file.
>
> Any help appreciated.
>
> Cheers,
> Alan
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ePub and Org mode
  2011-02-19 21:46 ` Christian Moe
@ 2011-02-19 22:15   ` Alan L Tyree
  2011-02-20  7:53   ` Achim Gratz
  1 sibling, 0 replies; 9+ messages in thread
From: Alan L Tyree @ 2011-02-19 22:15 UTC (permalink / raw)
  To: emacs-orgmode

On Sat, 19 Feb 2011 22:46:02 +0100
Christian Moe <mail@christianmoe.com> wrote:

> Hi,
> 
> I agree exporting 'chapters' in a single Org document to separate
> html files would be a nice option to have.
> 
> Pending someone writing an export function for this, you could
> 
> - post-process the HTML with one of the scripts out there for 
> splitting up web pages, like htsplit available on CPAN;
> 
> - or go the Org -> DocBook -> `chunked' HTML route?

Good idea. In fact, I just did a simple keyboard macro to go through
the file and export subtrees. Only 12 chapters, so not much of a call
for anything more difficult.

> 
> But just out of curiosity, why would you like this for the purpose of 
> making an ePub book? Are you using a tool that requires it? (Unlike, 
> e.g., Calibre, which takes a single HTML file as input, with TOC
> built from e.g. H2 as chapter headings.)

Fair question. Using something like Calibre is what I would normally
do. I have also used Sigil to build ePub books from a single html file.
It is good since you can add some final editing touches.

I got started on it because I was having a look at pandoc which purports
to build ePub directly. But it doesn't split the files.

Anyway, the (dumb) answer is that I was just fooling around looking at
the internals of ePub structure. Trying to avoid real work :-).

Alan

> 
> Yours,
> Christian
> 
> 
> On 2/19/11 10:25 AM, Alan L Tyree wrote:
> > Greetings from Down Under,
> > I am constructing an ePub formatted book. It came to me in plain
> > text and I have formatted in org-mode.
> >
> > It is easy to export to XHTML, the first step in ePub construction,
> > but I would like every chapter to be a separate file. It is easy
> > enough to do this with a macro or a simple function (even though I
> > am no elisp guru). Is there an export function that does this? I
> > didn't see it in the docs and I don't see anything about it doing a
> > Google search.
> >
> > What would really be nice, is a single command to create the ePub
> > file.
> >
> > Any help appreciated.
> >
> > Cheers,
> > Alan
> >
> 


-- 
Alan L Tyree                    http://www2.austlii.edu.au/~alan
Tel:  04 2748 6206

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ePub and Org mode
  2011-02-19 21:46 ` Christian Moe
  2011-02-19 22:15   ` Alan L Tyree
@ 2011-02-20  7:53   ` Achim Gratz
  2011-02-20  8:17     ` Eric Schulte
  2011-02-20  9:54     ` Alan Tyree
  1 sibling, 2 replies; 9+ messages in thread
From: Achim Gratz @ 2011-02-20  7:53 UTC (permalink / raw)
  To: emacs-orgmode

Christian Moe <mail@christianmoe.com> writes:
> I agree exporting 'chapters' in a single Org document to separate html
> files would be a nice option to have.
>
> Pending someone writing an export function for this, you could
[...]

That sort of already exists, I've been using that to some good
effect... from the documentation:

--8<---------------cut here---------------start------------->8---
   When exporting only a single subtree by selecting it with `C-c @'
before calling an export command, the subtree can overrule some of the
file's export settings with properties `EXPORT_FILE_NAME',
`EXPORT_TITLE', `EXPORT_TEXT', `EXPORT_AUTHOR', `EXPORT_DATE', and
`EXPORT_OPTIONS'.
--8<---------------cut here---------------end--------------->8---

The only thing missing is a function to export all (not excluded)
subtrees one by one and honor the properties slapped onto each subtree.


Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptation for Waldorf microQ V2.22R2:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Re: ePub and Org mode
  2011-02-20  7:53   ` Achim Gratz
@ 2011-02-20  8:17     ` Eric Schulte
  2011-02-21  1:34       ` Richard Lawrence
  2011-02-20  9:54     ` Alan Tyree
  1 sibling, 1 reply; 9+ messages in thread
From: Eric Schulte @ 2011-02-20  8:17 UTC (permalink / raw)
  To: Achim Gratz; +Cc: emacs-orgmode

Achim Gratz <Stromeko@nexgo.de> writes:

> Christian Moe <mail@christianmoe.com> writes:
>> I agree exporting 'chapters' in a single Org document to separate html
>> files would be a nice option to have.
>>
>> Pending someone writing an export function for this, you could
> [...]
>
> That sort of already exists, I've been using that to some good
> effect... from the documentation:
>
>    When exporting only a single subtree by selecting it with `C-c @'
> before calling an export command, the subtree can overrule some of the
> file's export settings with properties `EXPORT_FILE_NAME',
> `EXPORT_TITLE', `EXPORT_TEXT', `EXPORT_AUTHOR', `EXPORT_DATE', and
> `EXPORT_OPTIONS'.
>
> The only thing missing is a function to export all (not excluded)
> subtrees one by one and honor the properties slapped onto each subtree.
>

`org-map-entries' should satisfy this need. -- Eric

,----
| org-map-entries is a Lisp function in `org.el'.
| 
| (org-map-entries FUNC &optional MATCH SCOPE &rest SKIP)
| 
| Call FUNC at each headline selected by MATCH in SCOPE.
| 
| FUNC is a function or a lisp form.  The function will be called without
| arguments, with the cursor positioned at the beginning of the headline.
| The return values of all calls to the function will be collected and
| returned as a list.
| 
| The call to FUNC will be wrapped into a save-excursion form, so FUNC
| does not need to preserve point.  After evaluation, the cursor will be
| moved to the end of the line (presumably of the headline of the
| processed entry) and search continues from there.  Under some
| circumstances, this may not produce the wanted results.  For example,
| if you have removed (e.g. archived) the current (sub)tree it could
| mean that the next entry will be skipped entirely.  In such cases, you
| can specify the position from where search should continue by making
| FUNC set the variable `org-map-continue-from' to the desired buffer
| position.
| 
| MATCH is a tags/property/todo match as it is used in the agenda tags view.
| Only headlines that are matched by this query will be considered during
| the iteration.  When MATCH is nil or t, all headlines will be
| visited by the iteration.
| 
| SCOPE determines the scope of this command.  It can be any of:
| 
| nil     The current buffer, respecting the restriction if any
| tree    The subtree started with the entry at point
| file    The current buffer, without restriction
| file-with-archives
|         The current buffer, and any archives associated with it
| agenda  All agenda files
| agenda-with-archives
|         All agenda files with any archive files associated with them
| (file1 file2 ...)
|         If this is a list, all files in the list will be scanned
| 
| The remaining args are treated as settings for the skipping facilities of
| the scanner.  The following items can be given here:
| 
|   archive    skip trees with the archive tag.
|   comment    skip trees with the COMMENT keyword
|   function or Emacs Lisp form:
|              will be used as value for `org-agenda-skip-function', so whenever
|              the function returns t, FUNC will not be called for that
|              entry and search will continue from the point where the
|              function leaves it.
| 
| If your function needs to retrieve the tags including inherited tags
| at the *current* entry, you can use the value of the variable
| `org-scanner-tags' which will be much faster than getting the value
| with `org-get-tags-at'.  If your function gets properties with
| `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
| to t around the call to `org-entry-properties' to get the same speedup.
| Note that if your function moves around to retrieve tags and properties at
| a *different* entry, you cannot use these techniques.
`----

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Re: ePub and Org mode
  2011-02-20  7:53   ` Achim Gratz
  2011-02-20  8:17     ` Eric Schulte
@ 2011-02-20  9:54     ` Alan Tyree
  1 sibling, 0 replies; 9+ messages in thread
From: Alan Tyree @ 2011-02-20  9:54 UTC (permalink / raw)
  To: Achim Gratz; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 2324 bytes --]

On Sun, Feb 20, 2011 at 6:53 PM, Achim Gratz <Stromeko@nexgo.de> wrote:

> Christian Moe <mail@christianmoe.com> writes:
> > I agree exporting 'chapters' in a single Org document to separate html
> > files would be a nice option to have.
> >
> > Pending someone writing an export function for this, you could
> [...]
>
> That sort of already exists, I've been using that to some good
> effect... from the documentation:
>
> --8<---------------cut here---------------start------------->8---
>   When exporting only a single subtree by selecting it with `C-c @'
> before calling an export command, the subtree can overrule some of the
> file's export settings with properties `EXPORT_FILE_NAME',
> `EXPORT_TITLE', `EXPORT_TEXT', `EXPORT_AUTHOR', `EXPORT_DATE', and
> `EXPORT_OPTIONS'.
> --8<---------------cut here---------------end--------------->8---
>
> The only thing missing is a function to export all (not excluded)
> subtrees one by one and honor the properties slapped onto each subtree.
>
> True. I also use the subtree export function often. I is easy to define a
keyboard macro to deal with the problem. If I had to do it more than once,
I'm sure that it is not too hard to write an elisp function to do it.

I think that Christian is proably right: for ePub generation, there are
other tools that do the job. Two ways that are easy:

org -> html -> tidy -m -asxhtml -> (calibre || sigil)

I have had trouble getting the calibre ePub to validate, but it is more
straightforward than Sigil. On the other hand, Sigil is easier to use to add
editing to the basic text and always seems to pass the validation tests.

To get proper validation, I have found that the "tidy" step is necessary.
Not sure why - tidy always replaces lots of characters, but I haven't had
the time to work out what is going on.

Cheers,
Alan


>
> Achim.
> --
> +<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+
>
> SD adaptation for Waldorf microQ V2.22R2:
> http://Synth.Stromeko.net/Downloads.html#WaldorfSDada
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
>


-- 
Alan L Tyree                    http://www2.austlii.edu.au/~alan
Tel:  04 2748 6206

[-- Attachment #1.2: Type: text/html, Size: 3354 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ePub and Org mode
  2011-02-20  8:17     ` Eric Schulte
@ 2011-02-21  1:34       ` Richard Lawrence
  0 siblings, 0 replies; 9+ messages in thread
From: Richard Lawrence @ 2011-02-21  1:34 UTC (permalink / raw)
  To: emacs-orgmode

"Eric Schulte" <schulte.eric@gmail.com> writes:

>> The only thing missing is a function to export all (not excluded)
>> subtrees one by one and honor the properties slapped onto each subtree.
>>
>
> `org-map-entries' should satisfy this need. -- Eric

I have been doing something similar with LaTeX export.  Here is my
(pretty hacky) code; it should be easy to adapt to HTML export.  It
does the following:

1) export each subtree of the current tree as a separate PDF (there's
some validation here, to make sure each of these trees has properties
that I need to produce the output I want)

2) concatenates the resulting PDFs into a single PDF for printing (this
requires the pdftk package)

Good luck!

Richard

;;;;
(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
       (let ((org-trust-scanner-tags t))
	 (push (get-property-or-fail (point) "EXPORT_FILE_NAME") export-files))
       (org-export-as-pdf nil))
     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))) 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-02-21  1:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-19  9:25 ePub and Org mode Alan L Tyree
2011-02-19 10:54 ` Bastien
2011-02-19 19:14   ` Alan L Tyree
2011-02-19 21:46 ` Christian Moe
2011-02-19 22:15   ` Alan L Tyree
2011-02-20  7:53   ` Achim Gratz
2011-02-20  8:17     ` Eric Schulte
2011-02-21  1:34       ` Richard Lawrence
2011-02-20  9:54     ` Alan Tyree

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).