In this tutorial we are going to create and publish a Jupyter book
. Jupyter Book is an open source project for building publication-quality books and documents from computational material.
This is a gallery of Jupyter Books built from across the community.
Building a Jupyter Book broadly consists of these steps:
To start this tutorial, you need Anaconda. If you don't already have Anaconda, go to anaconda.com and choose the appropriate Graphical Installer
for your system (Windows, MacOS or Linux). Install the software on your system:
Here some tips if you have problems installing Anaconda: troubleshooting.
Install Jupyter Book in the Anaconda environment of your choice (e.g., your base environment):
jupyter-book
:conda install -c conda-forge jupyter-book
ghp-import
conda install -c conda-forge ghp-import
ghp-import is a lightweight Python package that makes it easy to push HTML content to a GitHub repository
We are going to follow these instructions to quickly create a sample book:
books
).cd books
jupyter-book create mynewbook/
This will generate a mini Jupyter Book that you can both build and explore locally.
It will have a few decisions made for you, and you can explore the configuration of the book in _config.yml
and its structure in _toc.yml
.
Use this book as inspiration, or as a starting point to work from.
All of the configuration for your book is in a YAML file called _config.yml
.
You can define metadata for your book (such as its title), add a book logo, turn on different "interactive" buttons (such as a GitHub button), and more. To get an overview about all options, visit the documentation. Here, we just make some minor changes:
_config.yml
in your code editor.Now that you've got a Jupyter Book folder structure, you can create the HTML (or PDF) for each of your book's pages.
Once you've added content and configured your book, it's time to build outputs for your book. We'll use the jupyter-book build command line tool to create a HTML output.
cd
into your path (books)cd books
jupyter-book build mynewbook/
This will generate a HTML site which will be placed in the _build/html folder
Now that you've created the HTML for your book, it's time to publish it online. That's covered in the next section.
If you want to learn more about the details of how to build your book, visit the documentation.
Next, we add the folder to GitHub. I use GitHub Desktop to create a new repository:
Now, we'll publish the build artifact of our book online, so that it is rendered as a website.
First, update the settings for your GitHub pages site:
Next, you need to create a personal access token in GitHub:
In your terminal:
cd
into the main branch of your book's root directory (which should contain the _build/html folder):cd mynewbook
ghp-import
and point it to your HTML files, like so:ghp-import -n -p -f _build/html
Typically after a few minutes your site should be viewable online at a url such as:
To update your online book:
jupyter-book build mynewbook/
ghp-import
to push the newly built HTML to the gh-pages branch:ghp-import -n -p -f _build/html
Congratulations! You have completed the tutorial and learned how to:
✅ Create a virtual environment for your Jupyter book
✅ Install Jupyter book in your virtual environment
✅ Create a Jupyter book
✅ Publish your book with GitHub Pages
Next, you may want to proceed with this tutorial to create a more complex book:
Thank you for participating in this tutorial. If you found any issues along the way I'd appreciate it if you'd raise them by clicking the "Report a mistake" button at the bottom left of this site.
Copyright: Jan Kirenz (2021) | kirenz.com | CC BY-NC 2.0 License