Mastering bitcoin is a modern masterpiece. It describes, in easy to understand terms, how Blockchain and Bitcoin work from a fundamental level as well as a very detailed technical level. When you have a moment, purchase the book and support the very worthy author, Andres Antonopolous. However, in the spirit of open-ness, O’Reilly (the publisher) has released the source code for the book on Github. In this article I’ll show you how to generate your own English language PDF version from the public, open-source source files.
Let’s get started…
Docker and ASCIIDoctor
Docker is a deployment system that allows you to easily install software in “containers”, which are essentially micro-sized virtual machines that have all of the configuration needed to “just start running” your applications. We’ll use Docker to run our conversation application so you don’t need to do much in the way of installation. If you don’t have Docker installed already, you’ll want to do that before we get started.
Once you have docker installed, we can move onto the next step.
Downloading the Book Source Code
The “Mastering Bitcoin” book is available for free on github through the bitcoinbook repository. The code itself doesn’t quite allow you to read the book, but it does allow you to generate readable versions of the book. It’s written in a format called asciidoc, which is similar to the more common markdown format. While the PDF version of the book is available for free in many languages, the English language version is purposely left out of the free PDF downloads to encourage the purchase of the book and support the author and publisher.
The second edition of the book does not yet allow for derivatives in its license, and generating a PDF of the book is conceptually the same. So what we’ll be generating here is edition 1 of the book, from the
To download the book, we’ll use
git. Move to the directory you’d like to clone the book into and use the
git clone command to clone it.
git clone firstname.lastname@example.org:bitcoinbook/bitcoinbook.git
Next, we’ll check out the
Edition1Print1 to ensure we’re generating the properly licensed one.
git checkout Edition1Print1
Setting Up Our ASCIIDoctor Image
To convert our source code into a PDF, we’ll use a program called ASCIIDoctor. Since we don’t want to worry about the nuance of installing the program on our local machines, we’ll use Docker so we can just run it in an environment that is already set up and ready to go. We’ll need to mount the folder with the source code we want to convert as a volume in the ASCIIDoctor container, similar to how you’d mount an external hard drive to a real physical computer.
docker run command will run the docker image and, if you haven’t yet downloaded the image, will automatically download the image we need from DockerHub. We’ll mount a local folder with our
bitcoinbook source code to a special folder in the ASCIIDoctor image. The image already knows to check that directory for source code and convert it so we shouldn’t need to do much to have a PDF generated.
Let’s give it a try. Run the following command from your terminal:
docker run -it -v <path to your bitcoinbook>:/documents/ asciidoctor/docker-asciidoctor
This will drop us directly into a command shell in the container. In this container, we have access to all of the ASCIIDoctor commands and it starts us in the folder that we mounted in the volume when we ran the container.
Creating a PDF using ASCIIDoctor
Now that we have our container running, we just need to run the ASCIIDoctor command. You can run the command on individual chapters, or you can run it on the entire book.
book.asciidoc includes all of the other chapters and essentially generates the entire book in one PDF, which is what we want to do here. To generate the PDF, run the following ASCIIDoctor command:
You may see some warnings and errors generated, but if all goes well then at the end you should see a new file called
book.pdf with the newly generated book. Once you exit the container, the file will be in the directory you mounted to your container.
You’re Now One Step Closer to Mastering Bitcoin!
Congrats — you now have a copy of one of the best books written on the subject of bitcoin! Read through and enjoy, and then support the author and publisher by purchasing a print copy of the latest edition.