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. A second layout leaves out the numbers, for a site that readers look things up in.

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 or anchor, a link that starts at the site's root, 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, and so is a Markdown file under book/ that book.yaml does not list.

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`.

Tabs

=== "Label" starts a tab, and the lines indented by four spaces under it are its content, which can be anything a page holds. Tabs in a row make one set, and any other line ends it.

=== "Syntax"

    ```text
    copy <source> <target>
    ```

=== "Example"

    ```bash
    copy notes.txt backup/notes.txt
    ```

Choosing a tab switches every set on the page with a tab of that label, and later pages open the same way. A set whose tabs hold only code blocks is drawn as one card with the labels in its title row. Tabs that each hold such a card, one set inside another, put their labels at the right of that row, which suits the same command on two platforms. The search leaves out the labels and keeps the text of every tab.

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.

Reference layout

layout: reference in book.yaml suits a site that readers consult instead of reading in order, such as a set of command guides. The project keeps the same shape, and a part becomes a topic that lists its pages.

What In the reference layout
Parts, chapters and sections Have no numbers, and the words Part and Chapter go. Figures, tables and boxes keep one count per chapter.
A page's first paragraph Moves to the page head as its introduction, and stays in the search.
summary Appears only in the contents, and may use inline Markdown such as `code`.
icon in a part's index.md Names an SVG in theme/icons/, placed beside the topic's title in the text's colour.
A part with no chapters Is listed as in preparation.
A page with two or more sections Lists them at its head under "On this page".
The home page Shows the contents before its text.
Previous and next links Go.
Inline code Breaks only at its spaces, so a token like :<line> stays whole.
Running text Is not hyphenated, and a box's title keeps its case.

A search result names the topic and the page.

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.
layout book book for numbered pages, or reference for unnumbered ones.
search_scope book, or site in the reference layout What the search box offers to search, as in "Search the book".
search_hint Type to search chapter and section text., or Type what you are looking for. in the reference layout The line under the search box.
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. When it is false, a code block keeps its copy button, which stays faintly visible on a touch screen.
glossary true Whether \glossary tags make glossary pages.
not_found_page false Whether the site has a 404.html for a missing address, with the sidebar and search. Needs url, because its links start from the site's path, so it shows without its styles on a local preview served from another path.
sitemap false Whether the site has a sitemap.xml listing every page. Needs url.
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, help and 404. The reference layout's own are under reference/: base, home, part, chapter, section and page_list.
theme/icons/NAME.svg An icon for a part in the reference layout.
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.2.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.2.0
File Size Uploaded Provenance Actions
bookspine-0.2.0.tar.gz 74.7 kB With provenance Details for bookspine-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for bookspine 0.2.0
File Actions
bookspine-0.2.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for bookspine-0.2.0-cp311-abi3-win_amd64.whl
bookspine-0.2.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.2.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
bookspine-0.2.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for bookspine-0.2.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
bookspine-0.2.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for bookspine-0.2.0-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 1.6 MB

Release files / bookspine-0.2.0.tar.gz

Download URL bookspine-0.2.0.tar.gz
Size 74.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0b9b26682921dbca8310928a9bf9a86e75dd70118498053ffb933552eb83c41a
BLAKE2b-256 checksum
How to use checksums
2e7bce71e4b226dafab1706f2aa0c4436a4022c6f00ec9fd16cc24c1fa140ff8
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 7, 2026.

Transparency log

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

Download URL bookspine-0.2.0-cp311-abi3-win_amd64.whl
Size 318.5 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
caf1c100f161585dc938ce2d8fbc63b55149fcadb3a95e28cf71cd5394165129
BLAKE2b-256 checksum
How to use checksums
5936fe81016b29c3db1cbf2e41e6e3d8d7866ba980567c4e65d14597ce3b8d0f
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 7, 2026.

Transparency log

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

Download URL bookspine-0.2.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 412.0 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
33d8ba4aac2432811a11836493dd56197e10ae12351b8fe6bfcbcf9403c80d3f
BLAKE2b-256 checksum
How to use checksums
c41a23a6a0298e9668524bc6f9b59fece5b5dcd7ba582a9bf6c8c616cb456778
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 7, 2026.

Transparency log

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

Download URL bookspine-0.2.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 406.8 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
0373fe0f588af619bf858a9513e70250d961f360f4238d4a7a04d6be3205c8e7
BLAKE2b-256 checksum
How to use checksums
6c2313a7d3fb92e17fb12dfb8f09d295361455e24250b1ae829b4baad5bfcb49
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 7, 2026.

Transparency log

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

Download URL bookspine-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
Size 377.3 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
563f5e364ddfbbc76b03b1f088a974e821a6de26eb4051dd97a885b25d77645c
BLAKE2b-256 checksum
How to use checksums
ce2a6c323a21dba4f75d8de9ed06c16d595da8a33b5d71800c3cb5a3a129e7cc
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 7, 2026.

Transparency log

Security for bookspine 0.2.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.2.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 7, 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