4. Template Book#
We created a GitLab template repository containing an appropriate folder structure and template versions of the files you will need for your JupyterBook. You can start with a copy of this repository, add your content files and adjust the configurations.
4.1. Content#
You can store your MarkDown files with content in the folder called content. In the template book, this folder contains two templates: template-chapter.md and template-subchapter.md for your content. Each MarkDown file will eventually be one webpage in your JupyterBook, take this into account when you divide your content over the MarkDown files. For more examples of what features you can include in your content, you can check out our demobook.
4.2. Requirements file#
The requirements.txt file should contain a list of the libraries, modules, and packages that are required for your book. The packages myst_nb and jupyterquiz are required for building a jupyter book from MarkDown of Jupyter Notebook files. Additionally, other Sphinx modules that are used in your book should be included, such as sphinx-exercise, sphinx-proof and sphinx-inline-tabs. If you include Python code cells using libraries, such as numpy, scipy, matplotlib and plotly, they should be part of your requirements.txt file as well.
4.3. Table of content file#
You can structure your content for your Jupyter Book using the YAML table of content file (_toc.yml). Our template _toc.yml file provides default settings for creating a new book, which you should modify to include your content. Detailed information on how to do this can be found in a tutorial on the website of JupyterBook
4.4. Configuration file#
You can configure your Jupyter Book using the YAML configuration file (_config.yml).
This file controls a number of options and feature flags. Detailed information can be found in a tutorial on the website of JupyterBook
This section is a reference for the _config.yml structure of our template implementation and how it should be changed when creating a new book.
Caution
YAML can be tricky when it comes to how it treats certain kinds of values. For example, when using strings in YAML, it is usually fine to omit quotation marks around them. However, there are certain values that will be converted to boolean values if they do not have strings around them, for example, false, true, off, etc. In addition, pure numbers will be converted to float or int unless you put strings around them.
Our template _config.yml file provides default settings for creating a new book, which you can modify if necessary. These parameters are marked with an asterisk (*) in the following parameter lists and with the phrase Change this parameter in the _config.yml file for easy reference.
4.4.1. Book settings#
All the basic information regarding the book.
# Book Settings
title: "Template Jupyter Book"
author: Your Name
description: This is the template book for everyone that wants to create a new Jupyter Book from scratch.
copyright: Delft University of Technology, CC BY-SA 4.0
logo: content/images/tudelft.png
exclude_patterns: [ _build, Thumbs.db, .DS_Store, "**.ipynb_checkpoints" ]
# Only build files in the ToC to avoid building README, etc.
only_build_toc_files: true
Parameters
title*The title of the book. This will be placed in the left navigation bar.
author*The author of the book.
description*Text to indicate what the book is about.
copyrightCopyright tag to be placed in the footer.
logoA path to the book logo.
exclude_patternsPatterns to skip when building the book. Any files that match the patterns described there will be excluded from the build.
only_build_toc_filesAuto-exclude files not in the ToC and avoid building README, etc.
4.4.2. Execution settings#
No need to change anything. More information at: Execute and cache your pages.
# Execution Settings
execute:
execute_notebooks: force
cache: ""
exclude_patterns: [ ]
timeout: 30
run_in_temp: false
allow_errors: false
stderr_output: show
Parameters
execute_notebooksThis indicates whether to execute notebooks at build time. This must be one of “auto”, “force”, “cache” or “off”.
cacheA path to the Jupyter cache that will be used to store execution artifacts. Defaults to
_build/.jupyter_cache/.exclude_patternsA list of patterns to skip in execution (e.g. a notebook that takes a really long time).
timeoutThe maximum time (in seconds) that each notebook cell is allowed to run.
run_in_tempIf
True, then a temporary directory will be created and used as the command working directory (cwd), otherwise the notebook’s parent directory will be the cwd.allow_errorsIf
False, when a code cell raises an error, the execution is stopped; otherwise all cells are always run.stderr_outputThis must be one of ‘show’, ‘remove’, ‘remove-warn’, ‘warn’, ‘error’ or ‘severe’.
4.4.3. Parse and render settings#
No need to change anything. More information at: Syntax Extensions.
# Parse and Render Settings
parse:
myst_enable_extensions:
- amsmath
- colon_fence # To allow for ::: instead of ``` blocks.
- deflist
- dollarmath
- html_admonition
- html_image
- linkify
- replacements
- smartquotes
- substitution
- tasklist
myst_url_schemes: [ mailto, http, https ]
myst_dmath_double_inline: true
Parameters
myst_enable_extensionsExtra plugins of MyST for more capabilities.
myst_url_schemesURI schemes that will be recognised as external URLs in MarkDown links.
myst_dmath_double_inlineAllow display math ($$) within an inline context.
4.4.4. HTML-Specific Settings#
# HTML-specific settings
html:
favicon: "content/images/favicon.ico"
use_edit_page_button: true
use_repository_button: true
use_issues_button: false
use_multitoc_numbering: true
extra_navbar: ""
extra_footer: ""
google_analytics_id: ""
home_page_in_navbar: true
baseurl: ""
comments:
hypothesis: true
utterances: false
announcement: ""
Parameters
faviconA path to a favicon image.
use_edit_page_buttonThis indicates whether to add an “edit this page” button to pages. If
true, repository information in repository: must be filled in.use_repository_buttonThis indicates whether to add a link to your repository button.
use_issues_buttonThis indicates whether to add an “open an issue” button.
use_multitoc_numberingThis ensures continuous numbering across parts/chapters.
extra_navbar*An extra navigation bar will be displayed underneath the left navigation bar (optional).
extra_footer*An extra footer will be displayed underneath the footer (optional).
google_analytics_idA Google Analytics (GA) ID that can be used to track book views.
home_page_in_navbarThis indicates whether to include your home page in the left navigation bar.
baseurlThe base URL where your book will be hosted. This is used for creating image previews and social media.
hypothesisHypothesis for comments.
utterancesUtterances for comments.
announcement*This creates a banner announcement at the top of the site (optional).
4.4.5. LaTeX-specific settings#
# LaTeX-Specific Settings
latex:
latex_engine: pdflatex
use_jupyterbook_latex: true
latex_documents:
targetname: book.tex
Parameters
Define the name of the LaTeX output file for PDF builds.
latex_engineMust be one of ‘pdflatex’ or ‘xelatex’ (recommended for unicode), ‘luatex’, ‘platex’, ‘uplatex’.
use_jupyterbook_latexUse sphinx-jupyterbook-latex for pdf builds as default.
targetname*Name of the produced book from PDF build (optional).
4.4.7. Information about where the book exists on the web#
# Information about where the book exists on the web
repository:
url: https://gitlab.tudelft.nl/opentextbooks/how-to-manual/
path_to_book: ""
branch: master
Parameters
url*Online location of your book.
path_to_book*A path to your book’s folder, relative to the repository root (optional).
branch*This indicates which branch of the repository should be used when creating links (optional).
4.4.8. References#
No need to change anything.
# Add a bibtex file so that we can create citations
bibtex_bibfiles:
- references.bib
Parameters
bibtex_bibfilesFile with all the citations used in the book.
4.4.9. Advanced and power-user settings#
No need to change anything.
# Advanced and power-user settings
sphinx:
extra_extensions: [...]
local_extensions: [...]
recursive_update: false
config: [...]
Parameters
extra_extensionsA list of extra extensions to load by Sphinx (added to those already used by Jupyter Books).
local_extensionsA list of local extensions to load by Sphinx, specified by “name: path” items.
recursive_updateA boolean indicating whether to overwrite the Sphinx config (true) or recursively update (false).
configkey-value pairs to directly over-ride the Sphinx configuration.