Fix pragprog ebook fonts for source code listings

Pragmatic programmers are pioneers of the ebook technology and have offered their books in both PDF and DRM free EPUB format for a long time.

Now I can carry all my ebooks with me on my Sony PRS-505 ebook reader and read whatever I like while on commute. The eInk display is easy on eyes. Using an iPhone or iPad with their high glare displays for reading books is a joke compared to eInk!

There is one shortcoming regarding books containing lots of source code though. Pragprogs use the default monospaced font. And the default monospaced font on Sony is unfortunately the owful Courier New - very wide and very ugly. So people at Sony are as clueless regarding typography as their counterparts at Apple. On PRS-505 some source code is cut off on the right side and what remains is very hard to read - so it is impossible to learn from this source code listings.

Original version with Courier new

It is easy to fix though.

An EPUB file is simply a zip archive with

  • the book text in html format
  • some additional meta data like table of contents in XML files
  • CSS

all standardized by International Digital Publishing Forum.

So we are going to:

  1. unpack the EPUB archive
  2. adjust the style sheet
  3. pack the archive again
  4. and transfer the newly created file to the reader

In addition we are going to install nicer additional fonts on the reader. Inconsolata and DejaVuSans are free fonts and perfect for displaying source code listings. The condensed version of DejaVuSans allows for even more characters per line.

Just grab my Rakefile and stylesheet on github, adjust as needed and enjoy!

Here is the result - very nice source code listing, isn’t it?

Improved page using inconsolata font


blog comments powered by Disqus