My DIY solution for reading EPUB books

Nader K. Rad, 2021-02-21

I've tried every EPUB reader I could find, and I don't like any of them. What I expect is

So, I came up with a solution, and I'm happy with it. So, I'm going to explain it because you may like it as well, or you may be able to think of something that is ten times better than this and you may want to let me know about it!

First, I convert the book to a temporary HTML file:

I've used $@ instead of $1 because some file names have spaces in them.

First, I tried to keep the embedded styles of books and add my own style to them, but then I decided to remove the whole original style and only add my own:

It's not perfect because some ebooks are so badly formatted that, for example, use a paragraph with a special class to format code instead of using the code tag. I use a monospace font globally, so something like that is not a big deal, but generally, I have to cop with the other issues similar to this.

Initially, I had my own style in the SED command above, but then I moved it to a separate file to keep it clean. That file's content is read as follows, and that's the $style variable in the previous command.

I've used the TR command to remove the new lines from the CSS file, because I couldn't get the SED command to work when the replacement string had new lines.

In case you're wondering, this is the CSS file:

So, at this point, the temporary file is ready, and all I have to do is open it in a browser window. I didn't want to use Lynx because of the images in books, and my qutebrowser hasn't been working for a while for some unknown reason, and surf doesn't like me very much, so I've created a profile in Firefox that doesn't have any buttons, address bar, status bar, and so on; just a simple window. I open the ebook in that:

And voilĂ ! There's a simple, relatively well-formatted ebook in a clean window that doesn't have any extra elements. I've changed the default EPUB viewer to this application, and I'm very happy with it. This is the whole script:

This solution is not perfect for multiple reasons:

Overall, I prefer this to every EPUB reader I've tried.

Proxied content from gemini://nader.pm/my-diy-solution-for-reading-epub-books/ (external content)

Gemini request details:

Original URL
gemini://nader.pm/my-diy-solution-for-reading-epub-books/
Status code
Success
Meta
text/gemini;lang=en
Proxied by
kineto
Reisub Server

Be advised that no attempt was made to verify the remote SSL certificate.