Modifying epub files to include ‘sort by’ metadata

As most people know, books are usually organised by the surname of the (first) author, alphabetically. As some others will know, ebooks are not always great at this; iTunes sometimes thinks it should sort a book by first name instead of last name, and my Nook sorts by the last word of the first author’s name regardless of where their surname is. I’ve written about my tinkering with Calibre and ebooks before and this blog post is a short snippet that builds on that. As before, I’m using Calibre to perform the tweaks.

I’ve been trying to fix this problem by including something that looks like the following in the OPF file of my epub files:

<dc:creator opf:file-as="Beagle, Peter S." opf:role="aut">Peter S. Beagle</dc:creator>

The dc:creator tag is used by the epub specification to identify the contents of the tag as a creator of the work. The opf:role="aut" is there to identify http://www.honeytraveler.com/pharmacy/ Peter S. Beagle specifically as the author of the work. opf:file-as="Beagle, Peter S." is obviously there to make it clear what the sort criterion should be for this file.

There’s only one problem with including this line: it doesn’t always work. Sometimes it does, but often my Nook will complain of an unreadable file (even though Calibre will read it just fine). So, what’s up? I have been puzzling over this issue for ages, and today I finally cracked it.

At the start of your book, there will be a <package> tag, and then below that a <metadata> tag. In order for your epub to be able to use the opf:role and opf:file-as attributes, the <metadata> tag has to look like this (or at least include this part):

<metadata xmlns:opf="http://www.idpf.org/2007/opf">

Making sure that your <metadata> tag is correct solves the problem. Wahey!

Further notes on Markdown and WordPress

For a long while, my blog post on one of Amanda Palmer’s Kickstarter projects was my most popular blog post, thanks in no small part to AFP herself tweeting a link to it, providing a very nice uptick in my hits for the day! However, a different blog post recently overtook it — I am, as you’ve almost certainly worked out from this post’s title, talking about my previous blog post about using Markdown with WordPress, which I’m happy to see is proving to be useful to so many people.

However, things have changed in the way I use Markdown with WordPress since then. Michel Fortin has announced that his PHP Markdown Extra will no longer be updated as of 1 January 2014. He’s introduced PHP Markdown Lib 1.3 to replace it, partly because he no longer wants to maintain the WordPress elements. This is fair enough, but it introduces a fly to the ointment. One annoying thing about PHP Markdown Extra is that, if you have it installed on WordPress but then deactivate it or uninstall it, your blog no longer knows how to handle Markdown. This results in all of your blog posts displaying raw Markdown, rather than the HTML that they should show to visitors. Therefore, when a plugin is depreciated, it can be a real pain in the backside to get everything back to where it was.

As a result, as a WordPress user I have been casting around for a replacement for PHP Markdown Extra that won’t create the same problem if you need to deactivate it. I am here to tell you I believe I’ve found something that fits the bill perfectly.

An image showing the Markdown on Save Improved pane in the WordPress editor.

I’d like to recommend Markdown on Save Improved as a solid replacement for PHP Markdown Extra on WordPress. It addresses the concern I’ve outlined above very elegantly, by maintaining the database of Markdown separately to the database of blog posts. This means that if you write a blog post in Markdown and then uninstall it, the blog post will still display as HTML to the audience of your website — obviously a huge improvement over the ‘naked’ display that could occur with other Markdown plugins.1 Markdown on Save Improved is maintained by Matt Wiebe, who works for WordPress.com’s parent company Automattic — which presumably means he knows his stuff — and uses PHP Markdown Extra to parse Markdown, so it should produce identical output.

Markdown on Save Improved has one major drawback: when I installed it, it didn’t know which of my posts were Markdown and which were not, so I had to trawl through my database and hit ‘Update’ on each post. Whilst this isn’t a huge problem for someone like me who has a relatively small number of blog posts, someone who has more might find it a little clunky. Also, it assumes that you want to use Markdown every time you create a new blog post; perfect for me, but not great if you don’t want it to do that.2

What else has changed about my use of Markdown in the time since I wrote my original post? Whilst I’m still using the same beloved TextWrangler to edit my Markdown, I’m now using it in conjunction with the excellent Marked, which works with any text-editing app. The way it works is simple: you set your .md files to open in Marked, and then when you open them you see the rendered text displayed. Hit ⌘E and it’ll open the source in your editor of choice. Whenever you save the file in the editor, not only will Marked update the display, but it’ll indicate the paragraph of your latest edit so you can instantly focus on where your changes are appearing. It’s an incredibly elegant and useful app, and a snip at £2.49 on the Mac App Store.

So, in summary, go check out Markdown on Save and Marked. Both are incredibly useful tools that will make your Markdown even easier to write than it is at the moment.

A screenshot of this blog post and what it looks like in Marked.


  1. It’s also, I think, a huge improvement over WP-Markdown, which converts your Markdown to HTML when you save a blog entry and then converts that HTML back into Markdown when you come back; there are a couple of threads on that plugin’s support board that complain about this process badly mangling their Markdown and making it much harder to work with. 
  2. There is an alternative plugin called Markdown on Save, coded by Mark Jaquith, which is the plugin that Improved is based upon. This means you turn the option on for each blog post, rather than having to turn it off for each one. It’s prettier, but it contains a bug which causes footnotes to break on any WordPress page which displays more than one blog post (such as the front page or any category’s page). That’s why I’m not using it. 

Worldcon and the cheapest way to support it

Worldcon is the shorthand for the World Science Fiction Convention and is held annually on behalf of the World Science Fiction Society, or WSFS. The convention has a long history, having run 70 times (at the time of writing) since 1939, and thousands of people from across the world attend and discuss science fiction every year. However, not everyone who is a member attends the convention; some people buy supporting http://www.mindanews.com/buy-accutane/ memberships, and that’s what I’m discussing here.

There are several reasons to support Worldcon. The first reason is simple: because you want to. Worldcons need money to be successful, and a supporting membership helps in that regard. If you are slightly less altruistic (or, like me, you simply can’t afford to support every cause of which you approve) here are a couple of tangible benefits to supporting Worldcon, and then I’ll let you in on the secret to supporting it in the cheapest way.

The Hugo Awards

The Hugo Awards are the premier award in the field of science fiction and fantasy. Works are nominated every year by the members of that year’s Worldcon, the previous year’s Worldcon, and the next year’s Worldcon.1 As a result, if you’re interested in having your voice heard being a member of a Worldcon is good, as you can influence which works make it onto the Hugo Award ballot.

In addition, members of a Worldcon get to vote in the Hugo Awards that are awarded at that convention. This not only means that you get to have a say in what is recognised by the award, but it means you get something called the Hugo Voter Packet, which consists of electronic versions of almost every nominated work.2 This is a lot of material for what you pay; a supporting membership costs $60 this year, and the packet is comfortably worth more than that.

Site Selection

The advertisement for the Helsinki in 2015 Worldcon bid.

Even if supporting membership is a good deal normally, we want to try to minimise the cost of acquiring one. So, onto the real business of the article — how does one support Worldcon for as little money as possible? The secret is to vote in site selection. Worldcon sites are voted on two years ahead of the convention, and everyone who votes in site selection becomes a supporting member of the Worldcon that is elected. This isn’t just people who vote for the bid that wins; it’s all fans who vote. Since the voting fee tends to be $40, this is the cheapest way to become a supporting member of the Worldcon, every year.

Thus, your next course of action is clear. Go and join LoneStarCon 3, paying the $60 to become a supporting member, and then pay the $40 on the Site Selection page to vote for a bid. (You should definitely vote for Helsinki in 2015, by the way….)

So go forth, and exercise your right to vote! Not only is it supporting Worldcon, it’s getting your supporting membership in the cheapest possible way. You’re two for two!


  1. So, the works that appear on the ballot at LoneStarCon 3 were nominated by members of that convention, Chicon 7 and Loncon 3. This is a new thing that’s only come in recently: before this year, it was only members of the current and previous years’ conventions, so Loncon 3 members would not have been eligible to nominate. 
  2. The nominees for Best Dramatic Presentation usually don’t appear in the packet, and some novels don’t appear in formats other than PDF. 

Setting a cover image on an ePub ebook

As some of you may already know, I recently received a Barnes & Noble Nook for Christmas. This has been a great gift and I’m thoroughly enjoying using it to read a lot more literature, but there’s a problem that has been recurring: some publishers don’t properly set the cover art on an e-book, meaning the cover doesn’t show up on my Nook. Since, for me, everything really should be perfect (it’s a disease, trust me), I have been attempting to rectify this problem with my ebooks and I’ve finally come upon the solution. It’s fairly simple to do, as long as you’re a little comfortable with editing in HTML.

The first thing to do if you’re having trouble is to download Calibre and install it. Calibre is a fairly clunky piece of open-source software but it’s very full-featured and allows for ebooks to be edited. Once you’ve installed Calibre, run it and drag the problematic ebook into the library. Now, there are two ways to proceed.

One way (and arguably the easy way) is to click ‘Edit Metadata’, set the correct cover image and then convert the file into an epub; Calibre will embed the correct cover image into the new file. However, this method doesn’t sit well with me and so I’m going to outline how I do it below.

Right-click on the ebook and click ‘Tweak Book’, then click ‘Explode Book’. Look for a file that ends in ‘.opf’ (this will probably be in a folder called OEBPS) and open this file in your favourite text editor.1 There will be, somewhere in this file, a line that says <manifest>. You want to find the ID of the cover within this tag. It’ll probably be something like

<item id="cover_image" href="cover.jpg" media-type="image/jpeg">

and so the ID is cover_image in this case. Now go up to the <metadata> tag and insert a piece of text before the end:

<meta name="cover" content="cover_image"/>

This will let the ePub file know where the cover image is contained, and should therefore show up properly on your Nook. It’s important to note that it has to be in this order: if content comes before name, it will not display correctly. This is because of a bug in the Nook’s implementation of the EPUB specification.


  1. I use TextWrangler on my Macs and Notepad++ on my PCs; your mileage will vary. 

Using Markdown with WordPress

Since writing this article, Michel Fortin has announced that he is going to stop including WordPress plugin functionality in Markdown Extra. Click here to read a more recent article that explains how to cope with this news.

I’ve noticed that I’ve been getting hits for Markdown-related searches on Google, ever since I wrote a blog post about the browser extension called Footnotify. When I saw Footnotify I instantly knew I wanted to have that functionality on my own website, and so I started searching for a WordPress plugin that provided footnotes. Eventually, I decided that it would be worth using Markdown to achieve this effect, after seeing the footnotes on Daring Fireball, and set about getting this arranged.

The first step was finding a way to install Markdown on WordPress1. I searched on the website for an extension to do this, but couldn’t find an ‘official’ one, so I searched on Markdown-Discuss (the mailing list set up by John Gruber) to see whether I was mistaken. It turned out I was, although the plugin that I’d recommend isn’t listed on the WordPress website: since WordPress is based in PHP, and since Michel Fortin has written Markdown Extra for PHP, one can just download PHP Markdown Extra from his website and upload it to WordPress as a plugin.

A screenshot of an FTP client displaying the file path of PHP Markdown Extra in my WordPress configuration.

The process is easy. Once the zip file has downloaded, simply unzip it. You’ll be presented with a folder containing three files: two in .text format (one of the accepted file extensions for plaintext files that contain Markdown syntax) and one PHP file. I renamed the folder to php-markdown-extra and then uploaded it to my WordPress installation (the filepath is wordpress/wp-content/plugins). WordPress then sees this as a plugin, and so you’re ready to roll!

But what should you use to edit your Markdown text? Initially, I tried a Mac app for Markdown called Valletta, which didn’t impress me. One of the key features of Markdown that I adore is its ability to turn -- into — and turn 'typewriter quotation marks' into ‘typographic quotation marks’. Valletta doesn’t implement this part of Markdown, so I don’t recommend it. However, the beauty of Markdown is that it’s just plain text with specific syntax, and so you can feel free to use the plaintext editor of your choice. Personally, I flit between Textwrangler, on the Mac and Notepad++, on Windows. Both apps can be configured to highlight Markdown syntax2, and I’m actually using TextWrangler to write this post.

A screenshot of this article, being rendered by Elements, the iOS plain text editor.

Although I don’t use a specific app on my computers, I have http://www.mindanews.com/buy-inderal/ found a rather good app on my iPhone. An iOS app by the name of Elements, it started life as a simple plaintext editor that supported Dropbox as a filesystem, but has since gained the ability to preview Markdown-formatted text and also copy the HTML generated as a result, for use in other apps.3 Elements is really good in a variety of ways: Dropbox sync is chief amongst them, but the ability to choose what file extension you give to Markdown files is also a very nice touch. It allows you to choose which folder on your Dropbox you want to synchronise4, too. Find it on the App Store here (£2.99/$4.99).

Lastly, let’s return to Footnotify. Markdown Extra allows for easy footnote creation, and Footnotify complements this brilliantly — I use both the Chrome extension and the JavaScript that provides the overlays on this blog. It will work whether you’re using Markdown on your blog directly or generating footnotes on your own. If you like what it’s doing for your browsing experience on my blog, you should definitely download it and give it a try with your own website!

I am glad that I got the desire to try Markdown because I feel it really has enhanced my writing. For me, the main benefits are the syntax, which makes certain tasks (bullet points, linking, footnotes) much easier. For the reader, the better formatted text brings something to the design of the website, whereas the footnotes mean that my frequent desire to wander off the topic is nowhere near as aggravating as it might be. I’d definitely recommend Markdown to anyone who writes online, even if it’s relatively infrequently.


  1. If you’re using WordPress.com, installing plugins is not possible and so this won’t apply to you — sorry! However, you can still use a Markdown app to export HTML and paste it into WordPress, so keep reading. 
  2. Notepad++ may need you to roll a user-defined language definition, but there are such things available online. There’s even this handy article on how to generate HTML from Markdown
  3. I mostly use this feature when posting to my LiveJournal, but if you’re running a WordPress.com blog then it will also be very useful! 
  4. I have all my text files in a folder called PlainText, named after the free editor that also syncs with Dropbox. I recommend that one, if you’re just looking for an editor without Markdown editing. Find it on the App Store here (free).