Writing a Book in Markdown

28th February 2013 | Tags:

I’m writ­ing my first book at the moment. Lately I’ve been doing all my writ­ing in Mark­down, but ulti­mately i’ll need an alter­na­tive for­mat. For word pro­cess­ing, such as it is, I tend to use Open Office — so really I wanted to be able to write in Mark­down, but con­vert to Open Office (or indeed, any of a vari­ety of for­mats). For one thing, it’s nice to get an idea of the num­ber of pages, which my Markown edi­tor just can’t do. Also, I pre­fer to work with sep­a­rate files for each chap­ter — but I’m not entirely sure what order the chap­ters will end up in. So, what I really wanted was a quick way to do two things — con­cate­nate all my chap­ters, and then con­vert the lot to Open Office format.

My solu­tion to this is in two parts.

First, a shell script to con­cate­nate the files. It’s impor­tant it’s fairly easy to rearrange chap­ters, so the for­mat of this was crucial.

Sec­ond, the con­ver­sion. For this I turned to Pan­doc, a small command-​line util­ity which sup­ports a huge raft of for­mats includ­ing Open Office, Mark­down, Microsoft Word, HTML, ePub, LaTeX and so on.

So with­out fur­ther ado, here’s my shell script. Easy to reor­gan­ise, and does every­thing I need in minutes.

cat a_chapter_about_rabbits.md \
a_chapter_about_giraffes.md \
all_about_ocelots.md \
lets_talk_about_elephants.md \
wrapping_up.md \
> concatenated.md

pandoc concatenated.md -o book.odt
rm concatenated.md

Now, when I add a new chap­ter I sim­ply need to pop the file­name in the appro­pri­ate place, I can see the chap­ter list­ing clearly, and rear­rang­ing is a basic cut & paste job. Simple!

(Note: the book’s not really about ocelots.)

Comments

No comments yet.

Links and images are allowed, but please note that rel="nofollow" will be automactically appended to any links.