Creating an e-book. Part 1.

As explained in Ok, E-Books post, this topic became of an interest just recently. I have never created an e-book so you will not see me saying that I’m usually doing it this way or that way or other crap like this. No, cards on the table. I’m just as curious as you are about e-books; I read quite a few online articles and even bought an e-book about how to create an e-book…

Following that book I was able to turn one of my procedure document from work into a fully working e-book. I uploaded it to Amazon’s Kindle Direct Publishing and it din’t complain at all. At KDP I reached the step where I could download a sample book file to see how it will look like. So, it works. fine In these series of posts, I’m just trying to put down the steps needed to create a simple e-book in .epub format. You’ll be free to further enhance it as much as your design and HTML skills are.

Just so this is clear from the beginning, an e-book is just a transformed XHTML, CSS and XML files. Because few people may not know what XHTML is, I quickly wrote HTML vs XHTML post yesterday. Regarding XML, I will show you later what it is for and how to create it.

Before we start, I’d like to tell those few basic HTML tags that we will use. I want you to understand  them, not just using them blindly.

  • Headings are defined with the <h1> to <h6> tags, with <h1> being the biggest heading and <h6> the smallest. Headings are really-really important because they will define your book’s Table of Contents. We will not use <h1> for Book Title mainly because we don’t need Book Title in the Table of Contents; we will use <h2> for Chapter Titles and <h3> for Chapter Subtitles.
  • A paragraph is defined using <p> tag only. We’ll see later how we can have differently formatted paragraphs using CSS.
  • We will also use <div> tag for other HTML elements, specifically when we will want to define specific blocks or divisions of text.
  • We will also use CSS a lot to format different blocks of text and images.

With that said, let’s get started.

  1. First and foremost, you need to write something. An article, a novel, something. Or take any document that you can test with. Format doesn’t matter now, it can be a text file, word file, anything.
  2. Again, we’ll use XHTML Strict so our html file will be well formatted. Initial code is nothing fancy, just basic html code. Copy below code to a notepad file and save it as mybook.html in a new folder [leave notepad file open]. Below is what I have so far in my file. Note that I added “My Book’s Title” as a page title, see line 7.

    [code language=”html” highlight=”7″]
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

    <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>My Book’s Title</title>
    </head>

    <body>

    </body>
    </html>
    [/code]

  3. Suppose you have your manuscript by hand. To start with, copy the contents of one chapter only and paste it exactly inside the <body> tag. Save the file.

    [code language=”html”]
    <body>
    Paste your first Chapter here.
    </body>
    [/code]

  4. Go to the folder where you have mybook.html file and double click it so that it opens in your default browser.
  5. For testing purposes, I used www.lipsum.com website to generate 3 paragraphs of dummy text. I placed this text inside the <body> tag and saved the file. If I run mybook.html now, my browser will show nothing except clear text; no breaks, no new lines, nothing.
    This is because we need to tell our browser where to start a new line, a new paragraph, where to put a heading and so on. This is done using tags described in the beginning.
  6. Next, we’ll add your chapter’s title and paragraphs. Going back to your notepad file, right where your chapter title begins, add <h2> tag. Where your chapter title ends, add </h2>. Backslash key is to tell the browser that here we are closing the previously opened tag, <h2> in our case.
    Now, if you have chapter subtitles, do something similar. Right before your chapter subtitle starts, add <h3> tag. Where your chapter subtitle ends, add </h3>.
    Similarly, where your paragraph starts, add <p> tag. Where your paragraph ends, close the tag with </p>. Do the same for all other paragraphs you have. Save the file and run it again in your browser. Looks nicer, isn’t it? Here’s what I have:As you can see, there seems to be a default space between chapter title, subtitle and the paragraphs. Also, everything is left centered and there are no other formatted elements. This is what we will work on in the next post.

HTML vs XHTML

Ever wondered what HTML and XHTML is about? Long and official story can be found at W3Schools. Short story, below.

Simply put, XHTML is the same as HTML but stricter. There are rules in place that one must follow. You are no longer allowed to leave tags unclosed or place them wherever you want. And guess what, the only beneficiary from following these rules, is you, the web developer. Because your site will then be supported by most of the browsers out there; definitely more than your badly formatted HTML is today.

Quoting W3Schools, the most important differences from HTML are listed below.
Please visit W3Schools post to see examples of good vs bad code.

Document Structure

  • XHTML DOCTYPE is mandatory
  • The xmlns attribute in <html> is mandatory
  • <html>, <head>, <title>, and <body> are mandatory

XHTML Elements

  • XHTML elements must be properly nested
  • XHTML elements must always be closed
  • XHTML elements must be in lowercase
  • XHTML documents must have one root element

XHTML Attributes

  • Attribute names must be in lower case
  • Attribute values must be quoted
  • Attribute minimization is forbidden

How to convert from HTML to XHTML

  1. Add an XHTML <!DOCTYPE> to the first line of every page
  2. Add an xmlns attribute to the html element of every page
  3. Change all element names to lowercase
  4. Close all empty elements
  5. Change all attribute names to lowercase
  6. Quote all attribute values

Moreover, these guys also developed a website where you can validate your page to be XHTML (and not only) compliant. They will also tell you exactly what you did wrong and how to correct. And don’t worry, it’s free! It only costs your willingness to do it the right way.

Ok, e-books

Let’s start with some bullshit talk to tell you how this topic started. Feel free to skip it if you’re not curious.
Personally, I’m not the kind of person who reads books not related to IT; think I can count all books I read throughout my lifetime and there are no more than 10, but this is not something to be proud of. Anyway, since all my books are IT related and I mainly read them in front of a computer, after having some sleep issues last year, I decided I need to read something else before going to bed. Well, before falling asleep… So, I bought a Kindle e-book reader, yey!

Next issue, what a hell to read?! My wife only reads crime novels, so she couldn’t help in this matter. Although I thought about reading what she reads, mainly to see if she’ll prepare me something to eat from a crime book we’re good though, just had our 9th wedding anniversary!
I remember that when I was a kid I read something from Jules Verne, in Russian, and I liked it… Searching the web for some e-books I found a very nice webstore (www.bestseller.md) from Moldova that offers lots of free e-books. I downloaded a few and started reading in bed. That’s what I started with, Jules verne. It was so boring, I started falling asleep within minutes; mission accomplished!
After few chapters things started to get interesting in the book so I was reading more and more each day. I finished the book and I was proud of my fantastic achievement, lol.

I started the second book, also from Jules Verne, downloaded from same website (thanks, guys!). Here things started moving from reading side to IT side… mainly because first book I read had a nice handy feature that let me know how many minutes I have from current chapter or book. The second one, didn’t. It only said how much I have till end of the book. Well, well, well… why, what’s wrong?! I started digging… and this means I was no longer reading before going to bed, instead I was web-ing over this issue. Apparently, this second .mobi file was not formatted properly, specifically its chapters. Hmm…

Reading more and more about e-books, and how they’re created and published, seemed interestingly so I started testing how this works. I found no real step by step guide on how to do it. Lot’s of general articles covering this on a high level with steps to follow, blah, blah and in the end asking you to buy their e-books where they explain everything step by step. Well, gracias, what can I say.

Then I stumbled upon one publisher’s website with some info online (posted way back in 2013) and the rest of it in the e-book sold on Amazon (updated in January 2018). It was cheap, so I bought it. Of course, my eagle eyes immediately found many typos and errors in the book, that I emailed author about but… anyway, let’s get back to the point. Overall, that book is enough to get you started. Since I’m an IT guy, it was easy for me to understand everything, especially HTML and CSS things. Reading that book, I understood that this is what an e-book is all about – HTML, CSS and some XML. In fact, did you know that if you take an .epub file and change the extension to .zip, you will have an archive with everything in it (css file, html file, table of contents etc.)!? When I found out about it, I felt just like I did last decade – holy cow! This was when Microsoft first introduced their new XML based files (docx, xlsx etc.), and someone showed in a training that if you rename .docx to .zip, you get a nice structured zip file. technology, I love it!
Enough talking, let’s get started. Head of over to my next post, Creating an e-book. Part 1.

Getting back online

After many years, giving this blog a rebirth.

I lost my backup files and only found very few posts and those mainly about ConfigMgr 2012. Will post them below anyway; better few than nothing.

Next planned articles will be about e-books and plain html maybe, we shall see Smile Stay tuned!

Also need to create/update “About” page. Things have happened, so to speak… jobs changed, places changed etc.