Up until now we've been able to do everything with some simple command line tools & scripts along with a plain text editor. However, for the birth of a book we do need to tap into a bit more complexity. For this you'll need a free application called Calibre. Installation & setup instructions for each OS can be found on the website.
Calibre is a library application which allows you to store, read, and create ebooks. It also provides a simple way to convert text files into the format required for book creation.
When creating a book you should do all of your content editing in the plain text files. Once book creation begins you will end up with two different versions (plain text & ebook) of the book to edit should you want to change anything.
This tutorial will assume that you have the following types of text content in your book:
Book creation begins by creating a duplicate of the plain text files. The copies will be the ones you will use to create the book. Next open the files in your plain text editor and turn off word wrap so you'll have to scroll less. Then indent (using the tab key) every line which contains an excerpt or quote. Finally, use the search & replace function of your editor to replace the tabs with ">" (without the quotes).
You'll also want to add a "#" (without the quotes) in front of each of your headings/chapters in your text file. You can add additional #s to denote subheadings (e.g. #Part 1 & ##Chapter 1).
When you've completed both steps save the files.
Why tabs and what the heck is that > thing? Well its easy to select multiple lines (as often occurs in extended excerpts) and use the tab key to indent them all at once. Otherwise you would need to manually add the > to each line. That > is actually a bit of code for a text markup language called [Markdown](https://daringfireball.net/projects/markdown/). This simple > will tell the Calibre application to treat this text a certain way when we are converting the plain text into our book.
Now, use the book creation script to combine all of your plain text files for your book into one Markdown file (ending in .md).
Then, open a new file in your plain text editor and paste this text into it:
/*original text*/
.mytext {
display: block;
margin: 1em 0;
text-align: justify;
font-family: sans-serif;
font-size: 0.9rem;
}
/*Blockquotes*/
.excerpt {
font-style: italic;
font-weight: bold;
text-align: justify;
margin: 0 2rem;
font-family: sans-serif;
font-size: 0.9rem;
}
/*Quotes and Quote Authors*/
.pq {
font-style: italic;
text-align: justify;
page-break-after: avoid;
margin: 0 2rem;
font-family: sans-serif;
font-size: 0.9rem;
}
.pqa {
text-align: right;
font-style: italic;
font-family: serif;
font-weight: normal;
page-break-before: avoid;
font-size: 1.1rem;
}
/*Cut paragraph*/
.qcut {
margin: -0.7rem 0 -0.2rem 0;
text-align: center;
}
/*Headings*/
/*H1*/
.calibre1 {
font-family: "Liberation Serif", serif;
font-size: 1.7rem;
font-weight: bold;
text-align: center;
}
/*H2*/
.monoh2 {
text-align: center;
font-family: "Liberation Mono", monospace;
font-size: 1.3rem
}
/*Optional bullet formatting*/
.bullet {
margin: 0 2rem;
text-align: left;
}
.jbullet {
margin: 0 2rem;
text-align: justify;
}
/*Poetry*/
.poem {
margin: 0 2rem;
font-style: italic;
text-align: justify;
font-family: serif;
font-size: 0.9rem;
}
/*Credits*/
.thanks {
text-align: center;
font-style: italic;
font-family: "Liberation Serif", serif;
}
.thanked {
margin: 0.5rem;
font-size: 1.4rem;
text-align: center;
font-style: italic;
font-family: "Liberation Serif", serif;
}
.thanksnote {
text-align: justify;
font-style: italic;
font-family: "Liberation Serif", serif;
}
/*Text titlepage*/
.titletext {
padding-top: 40%;
}
/*Chapter headings in TOC*/
.level2 {
font-style: italic;
padding-left: 0.3rem;
}
/*auto-added*/
.calibre {
display: block;
font-size: 10px;
padding-left: 0;
padding-right: 0;
margin: 0 5pt
}
.softbreak {
display: block;
page-break-before: avoid;
text-align: center;
margin: 0.5em 0 1em
}
.whitespace {
display: block;
text-align: center;
margin: 0
}
.calibre2 {
font-style: italic
}
.calibre3 {
font-size: 1.3rem;
}
Save that file as "myStylesheet.css". This is the code which determines how your text is displayed in the book.
Next, open another new plain text file and paste this text into it:
@page {
margin-bottom: 5pt;
margin-top: 5pt
}
@font-face {
src: url(LiberationMono-Regular.ttf);
font-family: "Liberation Mono";
font-weight: normal;
font-style: normal;
font-stretch: normal;
}
@font-face {
src: url(LiberationSerif-Regular.ttf);
font-family: "Liberation Serif";
font-weight: normal;
font-style: normal;
font-stretch: normal;
}
@font-face {
src: url(LiberationSans-Regular.ttf);
font-family: "Liberation Sans";
font-weight: normal;
font-style: normal;
font-stretch: normal;
}
Save this file as "myPageStyles.css". This is the code which determines how the page looks as well as what fonts are to be used in your book.
Then, open Calibre and add the Markdown file to your library as a new book. Select your newly added book and click the Convert Book button.
First, in the Metadata section you will want to add your book's cover. You'll want your cover image to be at least 600x800 (and stick with that ratio if you go larger). I like to have a high resolution version of the cover so I make mine 1920x2560 and it will be scaled down automatically in the book.
Now, click on Look & Feel and then the Styling tab. Add the full path to myStylesheet.css in the Extra CSS field.
Next, click on Search & Replace. Add the following Search/Replace definitions (in this order):
Search | Replace |
^([.][.][.])\n | </p><p class="qcut">...</p><p> |
<p>(?=(.*</p>\n)*<blockquote>) | <p class="mytext"> |
<blockquote>(?=\n.*\n[-][-].*</p>\n</blockquote>) | <blockquote class="pq"> |
[-][-](?=.*</p>\n</blockquote>) | </p><p class="pqa">-- |
<blockquote> | <blockquote class="excerpt"> |
\[Source\]\nhttp | <a href="http |
(?<=http.*)</p> | ">[Source]</a></p> |
If you've used my scripts and style to create your book this set of definitions should get most of your book formatted well automatically. The more you stray from my style the more customization required but it is a skill that is easy to pick up and build upon so don't feel obligated to be exactly like PP.
Next, go to TXT input and change Paragraph style to "block" and Formatting style to "markdown". Then go to EPUB output and check "Insert inline Table of Contents". Click OK and your book will begin it's birth.
Once the conversion job is complete, right click on the book, choose Edit Book and you'll be presented with a file list, an editor window, and a live preview of what the text of your book will look like.
The first step will be to replace the existing styles with our custom ones. Right click on the existing page_styles.css and choose the Replace with file option. Do the same for the stylesheet.css file.
To set up your table of contents click Tools, then Table of Contents and then Edit. Because you used #s in front of your headings you may find that all your desired content is already there. If not you can click the Generate ToC from all headings button and it should then autopopulate the list. You can also add & remove things manually if necessary.
Once you've set up the ToC click OK and then you're ready to generate an updated inline ToC. Click Tools, then Table of Contents, then Insert.
Now, save your book.
From there it's really just nothing more than reading through the book & correcting any formatting errors that still exist after (or were introduced by) the Search/Replace step.
Don't be intimidated by the code if you've never worked with HTML or CSS before. It's very easy to pick up when you have some content to play around with and a live preview to see exactly what you changed.
Some helpful info:
<tag>Text</tag>
<tag class="mytext">Text</tag>
Example: <ol>
<li>Dog</li>
<li>Cat</li>
<li>Goat</li>
</ol>
This is just scratching the surface though. There are numerous HTML & CSS tutorials online which can get you up to speed if you'd like something a bit more structured. Given the commonality of both you should also be able to easily find answers to any specific question you have with a quick internet search.
When you think you're completely done run a check on your book to find things the editor believes are errors. To do so click Tools and then Check Book. Its output will provide a link to each error and a description of the problem along with some options to attempt to fix things automatically if you desire.
Complete that last bit and well that should be it. You've now got yourself a book in epub format. Publish it wherever & however you like. Different places will have different methods for doing so. Archive.org is a well-known website which allows you to upload your own work to a category called Community Texts. When you upload an .epub file to Archive.org it will convert it into a number of other formats automatically, including .pdf. It then will use that pdf to allow reading of the text directly on the Archive.org website. It's a pretty neat feature which can make it easier for readers to check out your work without actually downloading it.