Skip to main content

bookspine

bookspine turns a directory of Markdown chapters into a textbook-style static site, with numbered parts, chapters, sections, equations, figures, tables and boxed environments, citations, client-side search, and light and dark colour schemes. The theme comes with the package, so a book holds only its content and one configuration file.

The build reads book.yaml and the Markdown pages, converts them to HTML, numbers and resolves them, applies the theme and writes the site.

Step What it does
Read Reads book.yaml and the Markdown files it lists, in reading order.
Convert Turns each page's Markdown into HTML.
Number Numbers sections, figures, captioned tables, boxes and equations, resolves citations and links, and collects the search index.
Theme Puts each page into its template and gathers the static files.
Write Replaces what the last build wrote in site/.

The build stops on a broken internal link, a missing figure, a citation without a reference entry, an \eqref to a label no numbered equation carries, or an equation label used twice. A failed build leaves site/ as it was.

Install

pip install bookspine

bookspine needs Python 3.11 or later and runs on Linux, macOS and Windows. pip installs a prebuilt wheel on x86-64 and ARM Linux with glibc 2.17 or later, on macOS with Apple silicon and on 64-bit Windows. Anywhere else it compiles the package, which needs a C compiler and, if Rust is not installed, downloads a copy of about 500 MB into the user cache.

Usage

A book is a project directory:

my-book/
├── book.yaml             # title, author, parts and chapters
├── book/
│   ├── index.md          # the title page
│   ├── help.md           # an optional help page
│   └── methods/          # a part
│       ├── index.md      # the part's opener
│       ├── basics.md     # a chapter on one page
│       └── figures/
└── theme/                # optional overrides

Build it and preview the result:

bookspine build my-book
python -m http.server --directory my-book/site 8000

Then open http://127.0.0.1:8000/.

bookspine build [PROJECT_DIR] [--site-dir DIR] [--allow-warnings]
Argument Meaning
PROJECT_DIR The directory holding book.yaml, by default the current one.
--site-dir DIR Where to write the site, by default site/ in the project directory.
--allow-warnings Do not fail the build on warnings. A reference that is never cited is a warning.

python -m bookspine runs the same command. Each build lists any files under theme/ that are in force.

Writing a book

Pages

Pages follow CommonMark, with tables, definition lists, footnotes and curly punctuation added, and every page starts with a YAML front matter block.

Key Meaning
title The page's title. Required.
summary One sentence, shown under the title and in the contents.
status For example in-preparation, which puts a badge in the contents and a notice on the page.
references Citation keys mapped to formatted entries, which may use Markdown.

Use ## for sections and ### for subsections; the build numbers them. An ## named "References" or "Further reading", or carrying {: .unnumbered }, stays unnumbered. Section anchors come from the heading text, so renaming a heading changes its link. {: #my-id } after a heading pins its anchor.

A page can also use these forms:

Form Effect
[^note], with [^note]: Text on a line of its own A footnote, listed at the end of the page. Indent further paragraphs of the note by four spaces.
*[HTML]: HyperText Markup Language on a line of its own A tooltip on every HTML in the page.
++ctrl+alt+delete++ Those keys, drawn as keycaps. A name that is not a key leaves the text as written.
{: .class #id key="value" } on the line after a paragraph or list item Those attributes on it.

Parts and chapters

book.yaml lists the parts and their chapters in reading order. Parts take Roman numerals, and chapters are numbered continuously through the book.

parts:
  - dir: methods
    title: Methods
    chapters:
      - basics.md
      - dir: inference
        sections:
          - likelihoods.md
          - hypothesis-tests.md

dir is the part's directory under book/, which needs an index.md. A chapter is one Markdown file, or a dir with an index.md opener and one Markdown file per section. Each section page is numbered within the chapter (2.1, 2.2) and its ## headings become subsections (2.1.1). Figures, tables, numbered boxes and equations keep one running count through a chapter, so splitting a chapter changes none of those numbers. Each page has its own references and reference list.

Figures and tables

![caption](figures/name.svg) on a line of its own becomes a numbered figure. A local SVG is copied into the page, so it can use the theme's colours and follow the colour scheme. A table followed by a paragraph starting Table: becomes a numbered table, and a table with no caption takes no number. A button on each figure and table opens it enlarged.

Code

A fenced code block takes the colours of the language named after its opening fence, which any of these options may follow:

Option Effect
title="app.py" A title above the block.
hl_lines="1 3-4" Marks those lines.
linenums="1" Numbers the lines, starting from that number.

Inline code takes a language's colours when it starts with #! and the language's name, as in `#!python x = 1`.

Equations

Write inline math as $…$ or \(…\), and display math as $$ … $$ on lines of their own. \[…\] or a \begin{…} environment that starts a paragraph is display math too. Every display equation is numbered, and \notag suppresses a number. \label{eq:name} and \eqref{eq:name} reach any page in the book, so a label must be unique across it. Place \label after \end{aligned} or \end{split}, because MathJax discards one written inside them. A page with no math does not load MathJax.

Citations

[@key] cites an entry of the page's references, and [@a; @b] cites several. The reference list is generated at the end of the page, in order of first citation. A link that shows its own address, such as <https://example.org/a/long/path>, wraps between the address's elements with no hyphen added, so a long one fits a phone's screen.

Boxes

!!! kind "Title" sets material apart, and ??? kind "Title" makes it collapsible.

Kind Effect
definition, example, remark, recipe Numbered within the chapter, with a permalink.
warning, caution, note, tip Labelled, with no number.
Any other, such as summary Styled by its own name, with its title as written.

Glossary

A \glossary tag adds a reference to the book's glossary, which follows the last part with an opener, a page for terms and a page for equations. The tag prints nothing, as LaTeX's \index does. Each entry is a name that links to the place it marks, in alphabetical order. A page appears once it has an entry, so a book with no tags has no glossary.

Where Tag Entry
A paragraph or list item \glossary{Name} A term that links to this place.
The start of a box \glossary A term named after the box's title, linking to the box. \glossary{Name} gives it another name.
A display equation \glossary{Name} An equation of that name. It needs a \label and a number.
!!! definition "Jet"
    \glossary
    A collimated spray of hadrons.

$$
\sigma = \int f(x) \, \hat\sigma(x) \label{eq:xsec} \glossary{Factorisation formula}
$$

The build stops on a name used twice on a page, and on a named equation with no label or number.

Help page

A book can keep what a reader needs only now and then on a page of its own, such as its conventions, its notation, how to cite it and where to report a problem. help_page in book.yaml names a Markdown file in book/, and the foot of the sidebar links to it from every page, under the page's title. The page takes its address from the file's name, so help.md is served at help/, and the build stops if a part or the glossary holds that address. The page has no number, stays out of the contents and of the previous and next links, and is covered by the search.

Exporting

Every table, figure, code block and display equation has a button that opens a menu of file formats. It appears when the cursor is over that component. On a touch screen it stays faintly visible, except on a code block, where a tap shows it. It sits at the end of a caption, at the top right of a code block or a table without a caption, and at the left of an equation. A code block also has a button that copies its source in one click.

Component Formats
Table Markdown, CSV, LaTeX, PNG, PDF
SVG figure SVG, PNG, PDF
Other figure PNG, PDF
Code block PNG, PDF
Display equation LaTeX, PNG, PDF

Exports use the light colour scheme on a white background. Markdown and LaTeX keep a table's caption, and images and PDFs leave it out. A code block keeps its source's lines, however it wraps on the page. Every format except PDF can also be copied to the clipboard. LaTeX output defines the book's macros it uses, and states the packages it needs.

PDF opens the browser's print dialog with the page sized to the component, which keeps vectors and fonts: choose "Save as PDF" there. A browser that ignores the page size prints on its default paper.

Configuration

book.yaml takes the keys below, and an unknown key stops the build.

Key Default Meaning
title, author required The book's title and author.
subtitle, kicker empty The lines around the title on the home page.
url empty The published address.
repo empty The source repository, linked from the sidebar.
repo_host empty The name in that link, such as GitHub. Required with repo.
edit_url empty The prefix of a page's edit link, followed by its path under book/. No link appears when it is empty.
help_page empty The Markdown file in book/ linked from the foot of the sidebar.
parts empty The parts and chapters, as above.
enlarge_tables true Whether a table has a button that opens it enlarged. Figures always do.
export_menus true Whether tables, figures, code blocks and equations offer an export menu.
glossary true Whether \glossary tags make glossary pages.
wrap_code true Whether a long line of code wraps, its continuation indented past the line's own indentation, instead of scrolling sideways. A block with line numbers always scrolls.
mathjax_macros empty TeX macros, each a definition or [definition, argument count].
pygments_light, pygments_dark friendly, github-dark The code colours of each colour scheme.
title: A Book of Methods
author: A. Author
repo: https://github.com/example/methods
repo_host: GitHub
edit_url: https://github.com/example/methods/blob/main/book/
mathjax_macros:
  dd: \mathrm{d}
  vec: ['\boldsymbol{#1}', 1]

Overriding the theme

A book changes the theme through its own theme/ directory, which the build reads first.

Path Effect
theme/templates/NAME.html Replaces the package's template of that name. The templates are base, home, part, chapter, section, glossary and help.
theme/static/NAME Replaces the package's static file of that name, or adds a new one. A pygments.css here takes the place of the generated one.

A template replaced whole no longer receives changes from new releases, so extend the package's copy instead where a small change is enough. The package's templates stay reachable under bookspine/, and base.html has an empty extra_head block for additions to the page's head:

{% extends "bookspine/base.html" %}
{% block extra_head %}
<link rel="stylesheet" href="{{ page.root }}static/local.css">
{% endblock %}

The site directory

The build keeps a list of its top-level entries in site/.bookspine-stamp.json. A rebuild removes those entries whole and leaves any other top-level file alone. It stops if the directory is not empty and has no stamp, as it would for a mistyped --site-dir or a site/ written by another program, and it refuses a filesystem root, the home directory, the project directory and anything holding them.

Revision dates

The title page and footer show when the book was revised, by default the month of the build. A scheduled rebuild would advance that date with nothing changed, so set SOURCE_DATE_EPOCH to the last commit's time:

SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) bookspine build

License

MIT

Metadata

Release files for bookspine 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bookspine 0.1.0
File Size Uploaded Provenance Actions
bookspine-0.1.0.tar.gz 67.0 kB With provenance Details for bookspine-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for bookspine 0.1.0
File Actions
bookspine-0.1.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for bookspine-0.1.0-cp311-abi3-win_amd64.whl
bookspine-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for bookspine-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
bookspine-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for bookspine-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
bookspine-0.1.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for bookspine-0.1.0-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 1.5 MB

Release files / bookspine-0.1.0.tar.gz

Download URL bookspine-0.1.0.tar.gz
Size 67.0 kB
Tags Source
SHA-256 checksum
How to use checksums
69ade648542a74d4ee8ef6b124d5699a9bb23e9c2b576b65bd20e0fd497ad90a
BLAKE2b-256 checksum
How to use checksums
8d7f6811237346efd53a70e03b40d78961441939144e76c50ef5cb7b70e0bb79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / bookspine-0.1.0-cp311-abi3-win_amd64.whl

Download URL bookspine-0.1.0-cp311-abi3-win_amd64.whl
Size 307.3 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
267314c1b0123c4a3a8b2099682c5ef920380e93eb582099b28f51d38ac5cc28
BLAKE2b-256 checksum
How to use checksums
b3d8e4c0479b6962699d313ced52e73fed7efb73e12f53713686f1e0a47e9600
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / bookspine-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL bookspine-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 400.9 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
c293a009fcdf8c3e77f079f1aa7c6eff3e357c4d0ebda88d12a9b439cc556c8f
BLAKE2b-256 checksum
How to use checksums
2a654c31452bf7d787b748e124f543a87e3b769b2c9d537dcf2ed5e4d03accc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / bookspine-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL bookspine-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 395.6 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
e52b2c50f2c5a6fe5a7db784a61109696448a9cd7cbcde1fc810814f2efbd7b3
BLAKE2b-256 checksum
How to use checksums
1b94dd4094761723ab27e646c9459b6c502130de2057e944865e49594ca8dbdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / bookspine-0.1.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL bookspine-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Size 366.2 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
cdb5db641ff3c6911f00a75b104cacf0d243313e68db0002019f176e50b95918
BLAKE2b-256 checksum
How to use checksums
6b43987cf7a7aa209b9c06b5f09a50564d9fd555406fcdfce513ec807c20734e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Security for bookspine 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for bookspine-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page