Ebook Design

A Linux User’s Guide to Formatting Ebooks (Part IV)

Yes, folks, it’s IV time. ROMAN NUMERALS. You know what that means: THE SUPER BOWL.

Oh wait, I mean it’s time to format our ebooks in vim!

After working your way through Part I, Part II, and Part III, you should now have a UTF-8 plain text version of your complete manuscript. It should contain all the special characters you want to use, plus <em>tags</em> around any text in italics.

Now crack open vim. Most Linux installs come with a base package (vim-tiny) with limited functionality. This may be enough to suit your needs, or you may prefer to install the vim-full package (called vim-common on some distributions). If you prefer a GUI, gVim works a treat–including on Windows, if you want to replicate this process on The Beast of Operating Systems. (–> see that? What we call authorial bias. With free sprinkles in every bite!)

Here’s what vim for my novel The United States of Air looks like, fully marked up:

VimFinalMarkup

At this point, I am assuming you are a vim user. If you already are, this process is going to be sweet. If you’re a Linux user and want to learn vim, type `vimtutor` at the command line, and you’re off to the races. If all this looks really scary and time-consuming, then guess what? It’s probably not for you.

So. How do we get from the text file open in front of you, to what I’m showing you above?

Simple. Follow these steps:

1. Replace all the special characters with HTML entity codes

2. wrap all paragraphs with <p> tags

3. Slap on some CSS at the top of your file

You’re done!

Replace all the special characters with HTML entity codes

We’re going to use vim’s regular expression search & replace syntax to do this. Cut and paste the third column of the following lines into vim (being sure you’re in command mode, not insert mode):

&    &amp;            :%s/&/\&amp;/g

(It is important to do this step first, otherwise you will be replacing ampersands in HTML entity codes. Not good!)

Now let’s do them smart quotes:

“    &ldquo;        :%s/“/\&ldquo;/g

”    &rdquo;        :%s/”/\&rdquo;/g

‘    &lsquo;        :%s/‘/\&lsquo;/g

’    &rsquo;        :%s/’/\&rsquo;/g

Note: if you want to use inch or feet hash marks, (e.g. Detective Billy Blubber stood 5′ 11″), don’t use regular quotes. Do this instead:

5&prime; 11&Prime;

&prime; is the inch mark

&Prime; is the foot mark

Also important:

°    &deg;            :%s/°/\&deg;/g

…  &hellip;         :%s/…/\&hellip;/g

—   &mdash;        :%s//\&mdash;/g

™   &trade;        :%s/™/\&trade;/g

®    &reg;            :%s/®/\&reg;/g

Finally, let’s fix any accented characters you’ve been using:

à    &agrave;        :%s/à/\&agrave;/g

á    &aacute;        :%s/á/\&aacute;/g

â    &acirc;          :%s/â/\&&acirc;/g

è    &egrave;        :%s/è/\&egrave;/g

é    &eacute;        :%s/é/\&eacute;/g

ê    &ecirc;        :%s/ê/\&ecirc;/g

ì    &igrave;        :%s/ì/\&igrave;/g

í    &iacute;        :%s/í/\&iacute;/g

ñ    &ntilde;        :%s/ñ/\&ntilde;/g

ò    &ograve;        :%s/ò/\&ograve;/g

ó    &oacute;        :%s/ó/\&oacute;/g

ø    &oslash;        :%s/ø/\&oslash;/g

ï    &iuml;            :%s/ï/\&iuml;/g

How long did that take you? Fifteen minutes? Less?

wrap all paragraphs with <p> tags

Now we’re going mark up all your paragraphs with HTML <p> tags. Since each of your paragraphs is (or should be) one long line, we’re going to tell vim to simply consider every line a paragraph:

:%s/^.*$/<p>&<\/p>/g

Now we need to make sure we leave no empty <p></p> tags where vim finds blank lines (or blank lines with a few spaces), as these will cause your HTML not to validate, which can in turn cause your finished epub files to fail epubcheck.

So we’re going to put an official HTML blank space inside every blank paragraph:

:%s/<p><\/p>/<p>\&nbsp;<\/p>/g

You’ll find this handy when formatting your copyright and title page, for instance.

Now it’s time to finish this puppy off. We’re going to add the HTML headers, slap in some CSS, and sprinkle CSS goodness throughout, to link that CSS to the relevant text.

Of which more in Part V

Written by: J.M. Porup

Novelist J.M. Porup is An American Dissident in Exile. Read More

Recommended

Leave a Comment