Rustonomicon as EPUB
I decided to start contributing to Redox OS. While searching for resources to study, I came across the Rustonomicon. Having dismissed it in the past — "I certainly won't be writing unsafe Rust any time soon" — I now felt the time has come.
There was only one problem: I don't enjoy reading on my computer screen. Like,
at all. But I do enjoy1 reading on my dated e-reader. As it turns out, you
can make mdBook builds spit out .epub files!
Here is how you do it.
Install requirements
- Install
mdbookandmdbook-pandoc$ cargo install mdbook $ cargo install mdbook-pandoc --locked - Install
pandocthrough your package manager:$ pacman -S pandoc-cli # I use arch btw
Build the EPUB file
-
Clone the Rustonomicon source
$ git clone https://github.com/rust-lang/nomicon.git -
Put custom CSS rules into a new
epub.cssfileOn my dated e-reader, long lines in code blocks were cut off. These CSS rules make code blocks wrap long lines instead.
pre.sourceCode > code.sourceCode { white-space: pre-wrap !important; } pre.sourceCode > code.sourceCode > span { display: block !important; white-space: pre-wrap !important; max-width: 100% !important; overflow: visible !important; word-wrap: break-word !important; word-break: break-all !important; }Turns out
.epubfiles are just "special" ZIP archives2. So a simple$ unzip book/pandoc/epub/rustonomicon.epub -d /tmp/rustonomicon-epubwill let you start digging into its contents — like when you want to find existing CSS rules to overwrite them with your own ones.
-
Add an EPUB profile to
book.toml[output.pandoc.profile.epub] to = "epub" output-file = "rustonomicon.epub" css = ["epub.css"] -
Build the book
$ mdbook build
Huzzah! Now you have a book/pandoc/epub/rustonomicon.epub file that you can
copy to your dated e-reader.
:wq
-
"Enjoy" may be too strong of a word. Physical books all the way, but since not everything gets printed, I learned to love my e-reader. ↩