Sunday, April 10, 2011

fixing the formatting

So I finally got to the bottom (more or less) of the weird formatting problem. As far as I know, it only turned up in Broken Ones (although I ended up reformatting The River and the Roses, just to be safe). Some em-dashes, for no apparent reason, were different from the rest, and as such, unreadable to most ereaders. They would instead show up as 3/4 signs. Just figuring that out took me a while. Then fixing it was a real pain, because I'd copy the bad em-dash and try to do a Find/Replace, only to have Word inform me that there were no such symbols to be found in the document. And I'd be staring at a page with four of them. Argh.

So for the benefit of those who are reading and thinking, how do I avoid this happening to me? I'm going to tell you the best way I've worked out to format a clean copy, free of bizarro em-dashes or other glitches.

First off, read the Smashwords Guide on how to get rid of things like text boxes and inconsistent indents--I never do these even in first drafts so they are not a problem for me. And let me say, if you use tab to indent your paragraphs, it's time to break that habit. The Smashwords Guide gives excellent instructions on the proper way to indent, and I won't go into that here.

The following instructions are based on Guido Henkel's guide to formatting, although I have made several alterations to deal with my em-dash issue and also some other problems I ran into with it. Also, his guide is long and can be intimidating to get through, although I recommend reading it if you want a more thorough explanation of why you're doing each step than you're going to get here.

Download JEdit and Calibre. These are both free programs and you'll need them to make your clean, glitch-free formatted ebook. There are other similar programs out there--if you're confident using them, do so. I know virtually nothing about them and can't adapt my instructions--I can only tell you how I did my formatting, and I used those two programs.

Before you start these steps, go into your word processing document and make sure you have all curly quotation marks. You may choose to do Find/Replace on each type, to be sure: there are “double” quotation marks and ‘single’ quotation marks. Make sure all of these are curly. You also need to Find/Replace all typed out ellipses to a symbol representing ellipses. That is, you probably have three periods in a row, like this: ... but what you need is a single ellipses symbol, like this …  . They look pretty much the same, right? But if you use the arrow keys to go over them, in the first instance you have three separate characters, and in the second, just one. You can copy and paste from this page into your Find/Replace boxes, if you like.

Okay, now that those preliminary steps are out of the way, we're ready for the process that will kill glitches in your formatting. Take a deep breath. There's some code coming up, and it can look scary. It's okay, though--you're just copying and pasting, and finding and replacing. You can do this.

Steps to Clean Formatting

In your Word doc:
1. Find/Replace: In Find box, type Ctr + i and in Replace box, put <i>^&</i>  . Replace all. (This preserves any italics you've got in your document for later--if you don't do this step, you'll lose all italic formatting.)
2. Ctr + A   Ctr + C   (Selects your whole document and copies it.)
3. Open Notepad (NOT WordPad), then Ctr + P  (Pastes your whole document in Notepad, killing all weird hidden Word formatting that is destined to mess you up later. Also known as the "Nuclear Option" in the Smashwords Guide.)

Now working in Notepad.
4. Find/Replace all em-dashes with --
Select an em-dash from your document and copy it, paste it in the Find box, then manually type the two hyphens in the Replace box. These will be replaced with real em-dashes later in JEdit, in such a way as to prevent weird 3/4 characters and the like from turning up. You might want to scroll through your document and make sure you don't spot any lingering em-dashes; but chances are, you got them. Also, while you're scrolling, look for empty box characters--just little squares. These are nasty symbols that cause glitches. If you find one, highlight it and copy it. Determine what it was supposed to be (in my case, an em-dash), and do a Find pasting in the box, Replace for what it was supposed to be.
5. Ctr + A    Ctr + C     Open JEdit, then   Ctr + P

Now working in JEdit.
6. F/R    ^(.+)$   with   <p>$1</p>    (This will put <p> and </p> symbols around each line)
7. F/R     with   &hellip;   (Copy that code from this page, including the semicolon.  DO NOT do this until you have replaced all three-dot ellipses with a single ellipses symbol--otherwise very weird stuff happens.)
8. F/R   --    with   &mdash; 
9. F/R  curly right    with  &ldquo;  and left    with &rdquo;
10. F/R curly right    and left    single quotes with  &lsquo;  and  &rsquo;
11. Save with an .html file extension. You will have to manually type .html after the file name.
12. Copy and paste the following at the top of the file, before any text:

 <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
    <style type="text/css">
      html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, pre, table, th, td, tr { margin: 0; padding: 0em; }
  text-indent: 1.5em;
  margin-bottom: 0.2em;
  text-indent: 0.1em;
  font-weight: bold;
  font-size: 1.5em; 
  page-break-before: always;
  margin-top: 5em;
  margin-bottom: 2em;
 text-indent: 0em;
 font-weight: bold;
 font-size: 1.2em;
 margin-top: 1em;
 margin-bottom: 1em;
 text-align: center;
  text-indent: 0em;
  text-align: center;
  font-size: 1.2em;
  font-weight: bold;
 margin-top: 1em;
 margin-bottom: 1em;
13. Put </body> at the end, after all text.
14. F/R  <p>Chapter    with    <p class="chapter">Chapter    (Unless you have not named your chapters, "Chapter 1" etc.--in that case you probably can't use Find/Replace and will have to go through and manually replace the <p> in front of your chapter heading with <p class="chapter"> . <p class="chapter"> still should have the word chapter in it, even if you don't use the word in your chapter headings--in the code, it refers to a style.)
15. Put <p class="chapter"> in place of <p> in front of any chapter-like heading. You may want to do this for About the Author, for instance. Note that this heading style is not centered, though, so it's probably not the best choice for your title page.
16. F/R <p>section break symbols</p> with <p class="centered"><span class="centered">section break symbols</span></p>   (Except replace the phrase "section break symbols" with whatever you use as section break symbols, such as *** or ~~~, so it would look like <p>***</p> and <p class="centered"><span class="centered">***</p></span>)
Note that you must have both the p class="centered" and the span class="center" and corresponding closing code </p> and </span> to properly center text. Guido explains this if you want to know why.
17. Through your computer's start menu, open Documents and double-click the .html document you're working on to check how it looks as a webpage. It will automatically open as a new tab on the web, also long as your browser is capable of making tabs.
18. Apply heading formatting wherever else it needs to go, like the title page.
I've created additional p class="centered" + span class="centered" formats with different names (eg. p class="centeredsmall" + span class="centeredsmall") in order to have some additional options for centered text in various sizes, etc. Copy the original ones, paste after the originals, and change the names. You must make sure both the p style and the span style have identical codes and don't contradict each other. To mess with sizes, simply alter the number by font-size, for instance. I like to mess around with this, saving and then reloading the webpage that corresponds to the file, to see how it looks.

Once you're satisfied with all of that, you have your basic .html document. You can use this to upload to Amazon. ALWAYS look at the preview they offer, and be sure you like what you see.

In order to use this document on Smashwords and B&N:

Highlight the entire webpage of your document and copy it (Ctr + C). Paste that into a Word document. Make sure your Word document doesn't have any weird spacing or other default formatting that will annoy Smashwords. Use their guide if you aren't sure.
Save in .doc format. That's what you upload to Smashwords.

This is why you need Calibre.
1. Open Calibre.
There is a row of buttons at the top--we'll be using several of these.
2. Open your .html document in Calibre by clicking "Add Books."
3. Select your .html document in the book list, and click on "Edit Metadata."
Fill in the information (Title, Author, ISBN if you have one, etc.) and upload your cover.
4. Making sure your book is still selected, click on "Convert Books."
In the upper right hand corner, there's a drop down menu of format options.
You can convert to MOBI here if you want, and upload that to Amazon instead of the .html, and it will be faster--also, if Amazon throws up an error when you try to upload your .html, doing this can fix that.
For B&N, convert to EPUB.
5. Click on "Save to Disk" and select a folder in your documents you'll have no trouble finding later. Calibre will create a new folder within the one selected, most likely titled after your author name. Your book document is in there.
6. On B&N when you upload your book, browse into that author folder and choose the EPUB file of your book, and upload that.
Their preview will even show your cover, as long as you chose one when you were doing metadata. It's very cool.

You're done. I'll let you know if I run into any more problems, but it's my conviction that going through these steps will give you a properly formatted, glitch-free eBook.

If you have more complicated formatting, such as images to include, PLEASE read Guido Henkel's guide. I in no way have his expertise--I'm merely posting what I figured out after hours of trial and error, AND with his help. I emailed him twice with questions, which he graciously answered. So I owe almost all my formatting to him, and the rest to Smashwords.


  1. Wow, thanks for this in-depth advice. Nice to get such a resource from someone who's going through it all herself. Your novella covers look great, too :)

  2. You're welcome, Charlotte! And thanks for the compliment! :) It's nice to know when someone is enjoying one of my books.

  3. Brilliant advice. I have had many problems formatting for Kindle. Everything seemed fine, and suddenly the format has changed. Smashwords was a breeze. I am formatting again to upload to Kindle so this info came at the right time for me. Thank you :-)

  4. That's great to hear, Ellen! I'm so glad I could be helpful to you. :)

  5. Oh wow, thanks for the great info!

    Looks like those years of learning web developing (hobby) will finally pay off!

  6. Okay, I am here, finally. I love the covers of your books. Great designs.

  7. Hi Krisz! Thank you so much for following! And thanks for the compliment!

  8. Hi Kevin! Sorry, your comment got dumped in the spam folder, and it took a while for me to notice. I'm going to have to check that more often...

    I'm glad the post is helpful!