Highlight ledgers in Sphinx#
In this tutorial you create a small Sphinx project written in Markdown, and highlight a Beancount ledger in it. It takes about five minutes.
You need Python 3.11 or later and uv.
Create the project#
Create a folder for the project, and add Sphinx, MyST-Parser and pygments-beancount to it:
mkdir ledger-docs
cd ledger-docs
uv init --bare
uv add sphinx myst-parser pygments-beancount
Configure Sphinx#
Create conf.py with the smallest configuration that reads Markdown:
project = "Ledger docs"
extensions = ["myst_parser"]
Nothing in it mentions Beancount. Installing pygments-beancount registers the lexer with Pygments, and Sphinx asks Pygments for it.
Write a page#
Create index.md with a fenced code block whose language is beancount:
# My ledger
```beancount
2026-01-01 open Assets:Bank:Checking USD
2026-01-01 open Expenses:Groceries USD
2026-01-06 * "Grocery store" "Weekly shopping"
Expenses:Groceries 74.00 USD
Assets:Bank:Checking
```
Build it#
Build the HTML with warnings as errors:
uv run sphinx-build -W -b html . _build/html
Open _build/html/index.html in a browser.
The ledger looks like this:
12026-01-01 open Assets:Bank:Checking USD
22026-01-01 open Expenses:Groceries USD
3
42026-01-06 * "Grocery store" "Weekly shopping"
5 Expenses:Groceries 74.00 USD
6 Assets:Bank:Checking
Dates, keywords, accounts, amounts and currencies each have their own colour, taken from the theme’s Pygments style.
What you learned#
Installing pygments-beancount is the whole integration: no Sphinx extension and no change to
conf.py.beancountis the language name for code blocks;beanworks too.Building with
-Wmakes Sphinx fail if a block cannot be highlighted.
Next steps#
Use the lexer in Sphinx and MyST shows every other way to show a ledger: directives with options, included files, inline code and line numbers.
Tokens lists the token each Beancount element becomes.