How-to and FAQ¶
This page contains more advanced and complete information about the
jupyter-book repository. See the sections below.
Enable Google Analytics¶
If you have a Google account, you can use Google Analytics to collect some information on the traffic to your Jupyter Book. With this tool, you can find out how many people are using your book, where they come from and how they access it, whether they are using the desktop or the mobile version etc.
To add Google Analytics to your Jupyter Book, navigate to Google Analytics, create a new Google Analytics account and add the url of your Jupyter Book to a new property. Once you have set everything up, your Google Analytics property will have a so-called Tracking-ID, that typically starts with the letters UA. All that you need to do is to copy this ID and paste it into your configuration file:
html: google_analytics_id: UA-XXXXXXXXX-X
Clean your book’s generated files¶
It is possible to “clean up” the files that you generate when you build your book. This is often useful if you have recently changed a lot of content in order to ensure that you build your book from a clean slate.
You can clean up your book’s generated content by running the following command:
jupyter-book clean mybookname/
By default, this will delete all folders inside
for a folder called
.jupyter_cache. This ensures that the content of your book
will be regenerated, while the cache that is generated by running your book’s code
will not be deleted (because regenerating it may take some time).
To delete the
.jupyter_cache folder as well, add the
--all flag like so:
jupyter-book clean mybookname/ --all
This will entirely remove the folders in the
Use raw HTML in Markdown¶
Jupyter Notebook Markdown allows you to use raw HTML in Markdown cells. This is discouraged in most cases, because it will usually just be passed through the build process as raw text, and so will not be subject to processes like:
relative path corrections
copying of assets to the build folder
multiple output type formatting (e.g. it will not show in PDFs!).
So, for instance, below we add:
<a href="../intro.md">Go Home HTML!</a> [Go Home Markdown!](../intro.md)
and you will find that the HTML link is broken:
Note that MyST Markdown now has some extended syntax features, which can allow you to use certain HTML elements in the correct manner.
For example, the raw HTML image tag
<img src="../images/fun-fish.png" alt="the fun fish!" width="200px"/>
See the image section for details.
Adding extra HTML to your book¶
There are a few places in Jupyter Book where you can add extra arbitrary HTML.
In all cases, this is done with a configuration value in your
Configuring to Improve Accessibility¶
Declaring the primary language used in your book assists screen reader and browser translation tools.
Language can be configured by providing the appropriate language code to the
language option, under
sphinx configuration in your
sphinx: config: language: en
This example will set the book language to English, which would be represented in your book’s HTML as
Working on Windows¶
Jupyter Book is now also tested against a Windows environment on Python 3.7 😀
For its specification, see the
windows-latest runner used by GitHub CI.
However, there is a known incompatibility for notebook execution, when using Python 3.8 (see issue #906).
If you’re running a recent version of Windows 10 and encounter any issues, you may also wish to try installing Windows Subsystem for Linux.
As of June 5, 2020, there were three open issues that required Windows-specific changes. We hope these are now fixed in version 0.8 of Jupyter Book but, in case any issues still arise, we leave these community tips, which are known to work for some users. Note that there is no guarantee that they will work on all Windows installations.
Jupyter Book currently reads and writes files on Windows in the native Windows encoding, which causes encoding errors for some characters in UTF8 encoded notebooks.
Work-around: Beginning with Python 3.7 cmd.exe or powershell enviroments that set PYTHONUTF8=1 override the native locale encoding and use UTF8 for all input/output.
A new Windows event loop
The asyncio event loop has been changed for Python 3.8 causing sphinx-build to fail.
Work-around: Pin to Python 3.7.6. This environment_win.yml file does that, and also installs runjb to fix issue 1.
Nested tables of contents
_toc.ymlfiles that reference Markdown files in sub-folders are failing for some Windows users. That is, this original _toc.yml file will fail with a message saying Jupyter Book “
cannot find index.md”
Work-around: Flatten the layout of the book to a single level, i.e. this _toc.yml file works with Windows.
The following workflow should succeed using a miniconda powershell terminal on Windows 10:
conda install git
git clone https://github.com/eoas-ubc/quantecon-mini-example.git
git checkout windows
conda env create -f environment_win.yml
conda activate wintest
After the build, view the HTML with:
Manually specify extra files/folders to be included in a website¶
Jupyter Book will copy over any files that are linked from within its pages so that the links work in the built website. However, sometimes you’d like to manually ensure that files and folders are included in your built website. For example, if you’d like to link to them from outside your built documentation, but not from within your built documentation.
To manually specify items to copy over, use the
html_extra_path Sphinx configuration.
You can configure this with Jupyter Book like so:
sphinx: config: html_extra_path: ['folder1', 'folder2']
When you build your book’s HTML, Jupyter Book will ensure that all files and folders inside the folders specified in
html_extra_path will be copied over to your built website.
For example, if you have a folder structure in your book like so:
assets └── data └── mydataset.csv
and the following Jupyter Book configuration:
sphinx: config: html_extra_path: ['assets']
Then the dataset will be accessible at
Enabling a custom builder using
You can initiate builds for a custom builder using:
jb build <project> --builder=custom --custom-builder=<builder-name>
sphinx users may find an extension that builds a different type of output from
the Sphinx AST such as sphinx-tojupyter
which is an extension for building notebooks that only includes
sphinx-tojupyter will be deprecated once
myst syntax rendering support is available in jupyter notebooks.
You can enable the
jupyter builder by adding it to the
sphinx: extra_extensions: [sphinx_tojupyter]
and using the
custom option via
jb build <project> --builder=custom --custom-builder=jupyter
Developers: When using other output targets, the package will need to support specifying the
mime type priority for
See this code for further details