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:
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
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):
& & :%s/&/\&/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:
“ “ :%s/“/\“/g
” ” :%s/”/\”/g
‘ ‘ :%s/‘/\‘/g
’ ’ :%s/’/\’/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:
′ is the inch mark
″ is the foot mark
° ° :%s/°/\°/g
… … :%s/…/\…/g
— — :%s//\—/g
™ ™ :%s/™/\™/g
® ® :%s/®/\®/g
Finally, let’s fix any accented characters you’ve been using:
à à :%s/à/\à/g
á á :%s/á/\á/g
â â :%s/â/\&â/g
è è :%s/è/\è/g
é é :%s/é/\é/g
ê ê :%s/ê/\ê/g
ì ì :%s/ì/\ì/g
í í :%s/í/\í/g
ñ ñ :%s/ñ/\ñ/g
ò ò :%s/ò/\ò/g
ó ó :%s/ó/\ó/g
ø ø :%s/ø/\ø/g
ï ï :%s/ï/\ï/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:
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:
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…
BookTrack: A Soundtrack for Ebooks?October 1st, 2014
Smashwords Style Guide for LibreOffice / OpenOfficeAugust 2nd, 2014
A Linux User’s Guide to Formatting Ebooks (Part V)July 5th, 2014
A Linux User’s Guide to Formatting Ebooks (Part IV)July 3rd, 2014