source: rtems-tools/doc/asciidoc/examples/website/publishing-ebooks-with-asciidoc.txt @ f91e023

4.104.115
Last change on this file since f91e023 was f91e023, checked in by Chris Johns <chrisj@…>, on 02/17/14 at 07:04:46

Add the documentation.

  • Property mode set to 100644
File size: 13.6 KB
Line 
1Publishing eBooks with AsciiDoc
2===============================
3// Web page meta data.
4:keywords:    AsciiDoc, EPUB tools, EPUB, PDF, ebooks
5:description: How to create EPUB and PDF ebooks using AsciiDoc.
6
7ifdef::blogpost[]
8// Use the same article for both a blog post and on the AsciiDoc
9// website.
10:blogpost-title: Publishing eBooks with AsciiDoc
11:blogpost-status: published
12:blogpost-doctype: article
13:blogpost-posttype: post
14:blogpost-categories: AsciiDoc,eBook,EPUB,DocBook
15
16*Published*: 2010-08-23 +
17*Updated*: 2010-05-08
18endif::blogpost[]
19
20It's easy to write and publish books in
21http://en.wikipedia.org/wiki/EPUB[EPUB] and PDF formats using
22http://www.methods.co.nz/asciidoc/[AsciiDoc].
23ifdef::blogpost[]
24This article was originally published on the
25http://www.methods.co.nz/asciidoc/publishing-ebooks-with-asciidoc.html[AsciiDoc
26website].
27endif::blogpost[]
28
29Here are three examples: The first is a <<X1,minimal example>>
30introducing the AsciiDoc format, the second <<X2,The Brothers
31Karamazov>> is a rather long multi-part book and the third <<X3,The
32Adventures of Sherlock Holmes>> includes a front cover image and
33customized page styling.
34
35ifdef::blogpost[]
36// Wordpress processing instruction.
37pass::[<!--more-->]
38endif::blogpost[]
39
40The examples presented below were created on a PC running Xubuntu
41Linux 10.04 but should be applicable to any UNIX-based operating
42system.
43
44NOTE: A number of 'asciidoc' and 'a2x' features used in this article
45require newer versions of AsciiDoc -- version 8.6.5 or better is
46recommended. The version of
47http://wiki.docbook.org/topic/DocBookXslStylesheets[DocBook XSL
48Stylesheets] used was 1.76.1.
49
50TIP: If you are experiencing 'xsltproc' errors when you run 'a2x' take
51a look at Francis Shanahan's
52http://francisshanahan.com/index.php/2011/fixing-epub-problem-docbook-xsl-asciidoc-a2x/[Fixing
53the ePub problem with Docbook-XSL/A2X/Asciidoc] blog post.
54
55
56[[X1]]
57Minimal Book
58------------
59This didactic example contains a title and two chapters.  The AsciiDoc
60source is a plain text file named `minimal-book.txt`:
61
62---------------------------------------------------------------------
63= The Book Title
64
65== The first chapter
66Nec vitae mus fringilla eu vel pede sed pellentesque. Nascetur fugiat
67nobis. Eu felis id mauris sollicitudin ut. Sem volutpat feugiat.
68Ornare convallis urna vitae.
69
70Nec mauris sed aliquam nam mauris dolor lorem imperdiet.
71
72== The second chapter
73Ut suspendisse nulla. Auctor felis facilisis. Rutrum vivamus nec
74lectus porttitor dui dapibus eu ridiculus tempor sodales et. Sit a
75cras. Id tellus cubilia erat.
76
77Quisque nullam et. Blandit dui tempor. Posuere in elit diam egestas
78sem vivamus vel ac.
79---------------------------------------------------------------------
80
81To generate the EPUB formatted book file `minimal-book.epub` run
82AsciiDoc's 'a2x' toolchain wrapper command from the command-line:
83
84  a2x -fepub -dbook minimal-book.txt
85
86The `-f` option specifies the output format, the `-d` option specifies
87the document type (book, article or manpage).  The optional
88`--epubcheck` option tells 'a2x' to validate the EPUB file using
89http://code.google.com/p/epubcheck/[epubcheck]. To generate a PDF
90version (`minimal-book.pdf`) with 'dblatex' run:
91
92  a2x -fpdf -dbook minimal-book.txt
93
94The distributed example PDFs were built using FOP -- if you prefer
95http://xmlgraphics.apache.org/fop/[FOP] over
96http://dblatex.sourceforge.net/[dblatex] use:
97
98  a2x -fpdf -dbook --fop minimal-book.txt
99
100You can also generate an HTML formatted book, either using DocBook XSL
101Stylesheets:
102
103  a2x -fxhtml -dbook minimal-book.txt
104
105or directly using the 'asciidoc' command:
106
107  asciidoc -dbook minimal-book.txt
108
109[NOTE]
110======
111The http://www.methods.co.nz/asciidoc/a2x.1.html[a2x toolchain
112wrapper] uses the following programs (most will be available
113prepackaged for your Linux distribution):
114
115- http://xmlsoft.org/XSLT/[xsltproc]
116- http://docbook.sourceforge.net/projects/xsl/[DocBook XSL
117  Stylesheets]
118- http://dblatex.sourceforge.net/[dblatex] (PDF file generator)
119- http://xmlgraphics.apache.org/fop/[FOP] (alternative PDF file
120  generator)
121- http://code.google.com/p/epubcheck/[epubcheck] (optional EPUB file
122  validator)
123======
124
125
126[[X2]]
127The Brothers Karamazov
128----------------------
129'The Brothers Karamazov' is an example of a multi-part book. To
130generate the AsciiDoc source I downloaded the
131http://www.gutenberg.org[Project Gutenberg] plain text source and
132edited it manually (this took around 15 minutes). To generate the
133`brothers-karamazov.epub` EPUB file run this command:
134
135  a2x brothers-karamazov.txt
136
137:examples-url: http://www.methods.co.nz/misc/examples/books/
138
139[frame="topbot",options="header",caption=""]
140.Brothers Karamazov source files and eBooks
141|====================================================================
142|EPUB |PDF |AsciiDoc source |Project Gutenburg text
143|{examples-url}brothers-karamazov.epub[brothers-karamazov.epub]
144
145|{examples-url}brothers-karamazov.pdf[brothers-karamazov.pdf]
146
147|{examples-url}brothers-karamazov.zip[brothers-karamazov.zip]
148
149|http://www.gutenberg.org/etext/28054
150
151|====================================================================
152
153Here's the start of the AsciiDoc source file showing the AsciiDoc
154specific meta-data:
155
156---------------------------------------------------------------------
157//
158// Text from Project Gutenburg http://www.gutenberg.org/etext/28054
159//
160// Formatted for AsciiDoc by Stuart Rackham.
161//
162// a2x default options.
163//    a2x: -f epub -d book --epubcheck
164// Suppress revision history in dblatex outputs.
165//    a2x: --dblatex-opts "-P latex.output.revhistory=0"
166// Suppress book part, chapter and section numbering in DocBook XSL outputs.
167//    a2x: --xsltproc-opts
168//    a2x: "--stringparam part.autolabel 0
169//    a2x: --stringparam chapter.autolabel 0
170//    a2x: --stringparam section.autolabel.max.depth 0"
171//
172
173= The Brothers Karamazov
174:author: Fyodor Dostoyevsky
175:encoding: iso-8859-1
176:plaintext:
177
178..........................................................................
179Translated from the Russian of Fyodor Dostoyevsky by Constance Garnett
180The Lowell Press New York
181
182 :
183 :
184
185***START OF THE PROJECT GUTENBERG EBOOK THE BROTHERS KARAMAZOV***
186..........................................................................
187
188
189= PART I
190
191== The History Of A Family
192
193=== Fyodor Pavlovitch Karamazov
194
195Alexey Fyodorovitch Karamazov was the third son of Fyodor Pavlovitch
196...
197---------------------------------------------------------------------
198
199- The book, book part and chapter titles have been edited to conform
200  to http://www.methods.co.nz/asciidoc/userguide.html#X17[AsciiDoc
201  title conventions].
202
203- Book part titles must be level zero titles:
204
205  = Book title (level 0)
206  = Part one title (level 0)
207  == Chapter 1 title (level 1)
208    :
209
210- Sub-chapter levels can be accommodated with `===`, `====` and
211  `=====` title prefixes.
212
213- In this example the 'Project Gutenberg' front matter was put in the
214  untitled preface inside an AsciiDoc literal block.
215
216- The comment lines starting with `// a2x:` contain 'a2x' command
217  options for this document (it's easier to put them in the document
218  once than type them every time on the command-line).
219
220- A number of 'xsltproc' options are passed to 'a2x' to suppress book
221  part, chapter and section numbering.
222
223- Setting the AsciiDoc 'plaintext' attribute suppresses most of
224  http://www.methods.co.nz/asciidoc/userguide.html#_text_formatting[AsciiDoc's
225  text formatting] and substitution conventions, this allows large
226  amounts of text to be imported with little or no manual editing.
227
228  * Once you have defined the AsciiDoc 'plaintext' attribute the only
229    requisite manual editing will be to format the titles and rectify
230    the odd paragraph being interpreted as some other AsciiDoc block
231    element.
232  * In the combined 49 thousand lines of imported 'Sherlock Holmes'
233    and 'Brothers Karamazov' text I only encountered two
234    misinterpreted list items, neither affected the rendered output or
235    necessitated editing.
236  * You can selectively enable and disable the 'plaintext' attribute
237    throughout your document using AsciiDoc
238    http://www.methods.co.nz/asciidoc/userguide.html#X18[attribute
239    entries].
240
241
242[[X3]]
243The Adventures of Sherlock Holmes
244---------------------------------
245This book includes a front cover image and a customized page design.
246To generate the `adventures-of-sherlock-holmes.epub` EPUB file run
247this command:
248
249  a2x adventures-of-sherlock-holmes.txt
250
251[frame="topbot",options="header",caption=""]
252.Sherlock Holmes source files and eBooks
253|====================================================================
254|EPUB |PDF |AsciiDoc source |Project Gutenburg text
255|{examples-url}adventures-of-sherlock-holmes.epub[adventures-of-sherlock-holmes.epub]
256
257|{examples-url}adventures-of-sherlock-holmes.pdf[adventures-of-sherlock-holmes.pdf]
258
259|{examples-url}adventures-of-sherlock-holmes.zip[adventures-of-sherlock-holmes.zip]
260
261|http://www.gutenberg.org/etext/1661
262
263|====================================================================
264
265Here's a screenshot of the first page of the first chapter (rendered
266by the http://www.epubread.com/en/[Firefox EPUBReader addon]):
267
268image::images/epub.png[]
269
270The {examples-url}adventures-of-sherlock-holmes.zip[AsciiDoc source
271Zip file] contains the following files:
272
273`adventures-of-sherlock-holmes.txt`::
274  The AsciiDoc source (derived from the
275  http://www.gutenberg.org/etext/1661[Project Gutenberg plain text
276  source]).
277
278`adventures-of-sherlock-holmes.jpg`::
279  The front cover image.
280
281`adventures-of-sherlock-holmes-docinfo.xml`::
282  A http://www.methods.co.nz/asciidoc/userguide.html#X87[docinfo] file
283  containing DocBook markup for the front cover image and the Project
284  Gutenberg frontmatter.  DocBook XSL Stylesheets identifies the book
285  cover image by the `role="cover"` attribute in the DocBook
286  `mediaobject` element.
287
288`adventures-of-sherlock-holmes.css`::
289  CSS rules for styling the page layout. The design is based on the
290  http://epubzengarden.com[ePub Zen Garden] 'Gbs' style. Because this
291  file is not named `docbook-xsl.css` the name must be specified
292  explicitly using the 'a2x' `--stylesheet` option.
293
294`underline.png`::
295  A title underline image that is used by the CSS stylesheet. This
296  resource has to be explicitly passed to 'a2x' because 'a2x' only
297  searches HTML files for resources.
298
299Here's the start of the AsciiDoc source file showing the AsciiDoc
300specific meta-data:
301
302---------------------------------------------------------------------
303//
304// Text from Project Gutenburg http://www.gutenberg.org/etext/1661
305//
306// Formatted for AsciiDoc by Stuart Rackham.
307//
308// a2x default options.
309//    a2x: -f epub -d book -a docinfo --epubcheck
310//    a2x: --stylesheet adventures-of-sherlock-holmes.css
311// Suppress revision history in dblatex outputs.
312//    a2x: --dblatex-opts "-P latex.output.revhistory=0"
313// Suppress book part, chapter and section numbering in DocBook XSL outputs.
314//    a2x: --xsltproc-opts
315//    a2x: "--stringparam part.autolabel 0
316//    a2x: --stringparam chapter.autolabel 0
317//    a2x: --stringparam section.autolabel.max.depth 0"
318// Additional resources.
319//    a2x: --resource underline.png
320//
321
322= The Adventures of Sherlock Holmes
323:author: Sir Arthur Conan Doyle
324:encoding: iso-8859-1
325:plaintext:
326
327== A Scandal in Bohemia
328
329To Sherlock Holmes she is always THE woman. I have seldom heard
330...
331---------------------------------------------------------------------
332
333The manual editing of imported plain text involves formatting the
334title and chapter names as
335http://www.methods.co.nz/asciidoc/userguide.html#X17[AsciiDoc titles]
336(in this example we've used the 'single line' title format). Sherlock
337Holmes only has two title levels:
338
339---------------------------------------------------------------------
340= The Adventures of Sherlock Holmes
341== A Scandal in Bohemia
342== The Red-Headed League
343== A Case of Identity
344== The Boscombe Valley Mystery
345== The Five Orange Pips
346== The Man with the Twisted Lip
347== The Adventure of the Blue Carbuncle
348== The Adventure of the Speckled Band
349== The Adventure of the Engineer's Thumb
350== The Adventure of the Noble Bachelor
351== The Adventure of the Beryl Coronet
352== The Adventure of the Copper Beeches
353== Colophon
354---------------------------------------------------------------------
355
356
357Styling your books
358------------------
359You can customize the appearance of a document with CSS.  CSS file.
360Either create your own or copy and edit the existing default
361`docbook-xsl.css` file (located in the AsciiDoc `stylesheets`
362configuration directory) then place it in the same directory as your
363AsciiDoc source file. Use the 'a2x' `--stylesheet` option if you want
364to use a different stylesheet file.  Take a look at the
365`adventures-of-sherlock-holmes.css` CSS file.
366
367There are some great examples of EPUB book styles at
368http://epubzengarden.com/[ePub Zen Garden].
369
370
371Including embedded fonts
372------------------------
373See http://www.methods.co.nz/asciidoc/faq.html#X5[this FAQ].
374
375
376Reading EPUB documents
377----------------------
378My current favorite software epub reader is the
379http://www.epubread.com/en/[Firefox EPUBReader addon]. EPUBReader
380honors the book's CSS styling rules and renders the page as the author
381intended (many EPUB readers only process a sub-set of CSS styling
382rules).
383
384Browsers are a natural fit for EPUB (EPUB is just a bunch of zipped
385XHTML files) -- I'd love to see browsers support EPUB natively.
386
387As of writing this article most eBook readers (with the notable
388exception of Amazon's Kindle) support the EPUB format.
389
390
391Non-fiction Books and Manuals
392-----------------------------
393AsciiDoc supports a rich set of markup conventions and can generate
394reference works and technical manuals complete with tables,
395illustrations, indexes, bibliographies and appendices. All the
396examples on the http:///www.methods.co.nz/asciidoc/[AsciiDoc web site]
397can be formatted as EPUB eBooks.
398
Note: See TracBrowser for help on using the repository browser.