
Reading eBooks with Emacs

Peter Prevos |
1705 words | 9 minutes
Share this content
The first step in the Emacs Writing Studio workflow is ingestion (reading, listening and watching) new content. Reading ebooks with Emacs is straightforward as it provides functionality to read several popular types of electronic documents, such as PDF and ePub. The software can also browse the web with an unobtrusive plain text browser.
Emacs Writing Studio
A comprehensive guide for writers seeking to streamline their workflow using Emacs. The book covers everything from organising ideas and writing distraction-free to publishing in multiple formats. It’s perfect for both beginners and experienced Emacs users, offering practical tips and a tailored configuration to enhance your writing process.
The source files of the book and EWS configuration are also freely available on GitHub.
Reading Documents
Emacs is excels at working with plain text in almost every imaginable format. However, it needs assistance from external software to display other document types, such as PDF or office formats. The diagram below shows the various external software packages necessary to render pages from the supported file formats. When you start the Emacs Writing Studio configuration, you will receive a warning if any of the required packages is unavailable on your system.

ePub files
An ePub file (Electronic Publication) is a widely used open standard format for digital books, magazines, and other written content. The content can adapt to different screen sizes, making it ideal for e-readers, tablets, and other devices.
An ePub file is a website in a box. The content and the layout are stored in a ZIP file. You can see the raw content of an ePub file with an archiving utility. You need to install the unzip
package to view the content.
The nov
package by Vasilij Schneidermann lets you read ePub books inside Emacs. The code after the :init
line associates files with the .epub
extension to this package.
;; Read ePub files
(use-package nov
:init
(add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode)))
You can now open ebooks like any other Emacs file. Use the arrow and page-up
/ page-down
keys to navigate each chapter. Several keyboard shortcuts are available to navigate the book:
t
: go Table of contentsn
andp
or[
and]
: Next or previous chapterq
: Quit the ebook reader?
: Help file with list of other keyboard shortcuts
To increase or decrease the text, use the C-x C-+
and C-c C--
shortcuts. To reset the length of the lines, press g
to re-render the document.
The ebooks are opened as a read-only file. You can copy and paste text into your bibliographic notes. Opening the file as an archive with the a
key shows the document's structure. From here, you can also copy images from the book with the C
keyboard shortcut. For more information about using files in Emacs, read manage files with Emacs.
PDF files
The Portable Document Format (PDF) is a versatile format developed by Adobe in the early 1990s. This format presents documents consistently, regardless of the software, hardware, or operating system used to view them. This format is codified in an international standard and has become the de facto standard for electronic literature.
The layout of PDF documents is fixed, in contrast with other electronic formats, which can adjust to the screen size. A PDF file is usually designed for printing and, as such, follows a traditional physical layout and typography.
Emacs can display PDF files out of the box with the DocView major mode. However, you will need some external software for DocView to work. GhostScript or MUPDF convert PDF files to images and provides them to DocView. This approach works because Emacs has built-in functionality to display and manipulate images.
This conversion means that DocView can be sluggish with large documents and will warn you. The large-file-warning-threshold
variable sets the threshold for these warnings, which is 10 Mb by default. This value is a bit low for modern systems and in Emacs Writing Studio, this threshold is 50 Mb.
Use the arrow and page-up
/ page-down
keys to turn pages. Several keyboard shortcuts are available to navigate the file:
P
: Zoom to the full pageW
: Fit document width to windowH
: Fit height to window+
/-
: Zoom in and outM-g g
: Jump to pageM-<
/M->
: Jump to first page or last pagek
: Kill (close) the file?
: Help file
To enable searching in PDF and other supported document formats, you must have the pdftotext
software installed, which is part of the poppler
package, a PDF utility named after a Futurama episode.
You can search within the document with doc-view-search
(bound to C-s
), which starts a search, creates a list of all matching pages and shows how many pages that contain the search query were found. After completing the search, you can jump to the next page containing a match with an additional C-s
. DocView does not highlight the searched term, but pressing C-t
(doc-view-show-tooltip
) shows the search results for this page in a tooltip.
Poppler also allows you to view a PDF file as a plain text file with the C-c t
shortcut (doc-view-open-text
). This option makes it easier to search and copy relevant text. Return to the graphical view of the text by pressing C-c C-c
twice.
We need some configuration to optimise how DocView displays pages. This code enhances the resolution of the page images to 300 DPI.
If you use Emacs 29.1 or higher and have the MuPDF
software available, then DocView will convert PDF pages to SVG files instead of PNG files, which provides a crisper image and better for zooming in closely.
Lastly, this configuration also moves the threshold for warning against opening large files to 50Mb ($50 \times 2^{20}$ bytes).
;; Doc-View
(use-package doc-view
:custom
(doc-view-resolution 300)
(doc-view-mupdf-use-svg t)
(large-file-warning-threshold (* 50 (expt 2 20))))
This article on the Emacs Notes website also provides a detailed explanation of how to configure and use DocView and enhances the dropdown menu functionality.
DjVu Books
The DjVu format is designed primarily to store scanned documents. DocView can read DjVu files when DjVuLibre is available on your system.
Office Suite Documents
The built-in DocView package can read Microsoft Office and LibreOffice files (text documents and presentations), but you first need to install the LibreOffice software.
When opening an office document, Emacs invokes LibreOffice to convert the file to a PDF, from where the abovementioned functionality is available.
There is currently a confirmed bug in Org mode (version 9.6.6) that overrides the associations between LibreOffice and Doc View mode. The code below is a workaround to reinstate the desired behaviour and associates the various file extensions with Doc View. The bug is slotted to be resolved in version 9.7.
;; Reading LibreOffice files
(use-package ox-odt
:ensure nil
;; Correct settings
:config
(add-to-list 'auto-mode-alist '("\\.\\(?:OD[CFIGPST]\\|od[cfigpst]\\)\\'" . doc-view-mode-maybe)))
Reading websites
Emacs has a built-in web browser called eww
(The Emacs Web Wowser). This package provides a simple, no-frills experience focusing on readability by displaying a website as a plain text file. It can display images but does not render any CSS for formatting or JavaScript.
A wowser is somebody with strong moral views for temperance and abstinence. So perhaps the plain text approach to browsing is a moral stance on the current World Wide Web and its security and privacy issues.
You can open a URL or search the web with the command M-x eww
. If the input doesn't look like a URL or domain name, Emacs searches the web with the DuckDuckGo search engine.
Use the arrow and page-up / page-down keys to navigate the page. Several keyboard shortcuts are available to navigate the webpage:
<
,>
: Beginning and end of the pageR
: Readable format (only display the main text)M-I
: Toggle imagesH
: Browsing history&
: Open the page in the external browserG
: New search or websiteq
: Quit the window?
: Help file with list of other keyboard shortcuts
When opening a link to a website from inside Emacs, it will open the default browser on your operating system instead of eww
. If you prefer to use eww
as the default, add this to your configuration file: (setq-default browse-url-browser-function 'eww-browse-url)
.
Many blogs and podcasts use RSS feeds to notify their readers of new content. The Elfeed package lets you follow your favourite web content using these feeds.
Reading eBooks with Emacs
This chapter focused on how to read documents in non-text formats. Reading these formats requires external software, in sumarry, to read all these formats you need to install:
- Ghostscript (
gs
) or MuPDF (mutool
): Reading PDF files - Poppler (
pdftotext
): Converting PDF files to text - LibreOffice (
soffice
): Reading and exporting to office documents unzip
: Reading ePub ebooks- DjVuLibre (
ddjvu
): Reading DjVu ebooks
The Emacs Writing Studio configuration issues a warning when any of these packages is unavailable. Emacs will work normally, but some functionality might be unavailable.
Emacs can also publish documents in most of these formats, starting with an Org mode file and export this to the desired format. Emacs Writing Studio discusses:
- Publishing Articles and Books with Org Mode Export (PDF, office formats and ePub)
- Create websites with Emacs and Hugo
Emacs Writing Studio
If you like to support my work, then please purchase the Emacs Writing Studio book.
Emacs Writing Studio
A comprehensive guide for writers seeking to streamline their workflow using Emacs. The book covers everything from organising ideas and writing distraction-free to publishing in multiple formats. It’s perfect for both beginners and experienced Emacs users, offering practical tips and a tailored configuration to enhance your writing process.
You can find the source files for the book and the latest configuration files on GitHub:
Emacs is a malleable system, and everybody has personal preferences on how to undertake a task and configure Emacs. Any article on how to use Emacs is thus opinionated. If you have a different way of doing things, please complete the contact form to send me an email or contact me on social media.
The next article discusses how to read RSS feeds to follow your favourite blogs and podcasts.
Share this content