Tokens#

The lexer uses only the standard Pygments token types, so every Pygments style, and every Sphinx theme, colours a ledger without custom CSS. The CSS class is the one the HTML formatter writes on each <span>; a style that sets a colour for it colours that element.

Mapping#

Beancount element

Example

Token type

CSS class

Comment

; checked

Comment.Single

c1

Hashbang, on the first line

#!/usr/bin/env bean-check

Comment.Hashbang

ch

Org-mode heading: * in the first column

* Accounts

Generic.Heading

gh

Other ignored lines: :, #, !, &, ? or % in the first column

:PROPERTIES:

Comment.Special

cs

Date

2026-01-31

Literal.Date

ld

Directive keyword after a date, txn, the * flag

balance, txn, *

Keyword

k

Other flags: !, &, #, ?, % or a capital letter

!

Keyword.Pseudo

kp

Directive without a date

option, plugin, include, pushtag, poptag, pushmeta, popmeta

Keyword.Namespace

kn

Boolean and null

TRUE, FALSE, NULL

Keyword.Constant

kc

Account, as one token

Assets:Bank:Checking

Name.Namespace

nn

Currency or commodity

USD, /ESM24

Name.Constant

no

Metadata key; the colon after it is punctuation

receipt:

Name.Attribute

na

Tag

#trip-2026

Name.Tag

nt

Link

^invoice-42

Name.Label

nl

String, quotes included

"Payee"

Literal.String.Double

s2

Escape in a string

\"

Literal.String.Escape

se

Number with a decimal point

1,234.56

Literal.Number.Float

mf

Number without one

42

Literal.Number.Integer

mi

Operators: price, tolerance, arithmetic, # in a cost

@, @@, ~, +, -, *, /, #

Operator

o

Punctuation

{, }, {{, }}, (, ), ,, |, :

Punctuation

p

Spaces, tabs and newlines

Text.Whitespace

w

Anything not recognized, such as ...

...

Text

none

Choices worth knowing#

The whole account is one token. A style cannot colour Assets differently from Bank:Checking, but every account reads as one unit, and the lexer stays simple.

Flags other than * are Keyword.Pseudo, not Keyword. Most styles colour the two differently, which sets pending entries (!) apart from cleared ones (*).

A single capital letter followed by a space is a flag where Beancount’s grammar expects one, after a date or at the start of a posting, and a one-letter currency everywhere else.

12026-01-09 P "Broker" "A transaction with the P flag"
2  Assets:Broker   2 V {310.00 USD}
3  Assets:Cash

Every element in one ledger#

The test suite uses this synthetic ledger to check that every element above is recognized. Beancount’s own parser accepts it.

#!/usr/bin/env bean-check
;; A synthetic ledger that uses every construct the lexer knows.
;; Nothing here describes a real person, account or balance.

* Options and plugins
option "title" "Example Ledger"
option "operating_currency" "USD"
plugin "beancount.plugins.auto_accounts"
include "prices.beancount"

** Accounts
2020-01-01 open Assets:US:Bank:Checking USD
2020-01-01 open Assets:US:Broker:Stocks VTI,V "FIFO"
2020-01-01 open Assets:US:Broker:Futures /ESM24
2020-01-01 open Assets:Cash
  description: "Pocket money"
2020-01-01 open Equity:Opening-Balances
2020-01-01 open Expenses:Food:Groceries USD
2020-01-01 open Expenses:Travel
2020-01-01 open Income:Salary USD
2020-01-01 open Liabilities:CreditCard:0042 USD
2025-12-31 close Liabilities:CreditCard:0042

** Commodities and prices
2020-01-01 commodity USD
  name: "US Dollar"
  export: "CASH"
2020-01-01 commodity VTI
  price: "USD:yahoo/VTI"
2026-01-02 price VTI 250.10 USD
2026/01/03 price V 310 USD

** Transactions
2026-01-05 * "Employer" "Salary for January" #payroll ^payslip-2026-01
  Assets:US:Bank:Checking  4,250.00 USD
  Income:Salary           -4,250.00 USD

2026-01-06 ! "Grocery store" "Weekly shopping" ; to be checked
  receipt: "receipts/2026-01-06.pdf"
  Expenses:Food:Groceries    (24.30 + 12.70) * 2 USD
  ! Assets:Cash              -74.00 USD

2026-01-07 txn "Opening balance"
  Assets:Cash                   100 USD
  Equity:Opening-Balances

2026-01-08 # "Broker" "Buy shares"
  Assets:US:Broker:Stocks    10 VTI {250.10 USD, 2026-01-08, "lot-1"}
  Assets:US:Bank:Checking

2026-01-09 P "Broker" "Buy more shares at a total cost"
  Assets:US:Broker:Stocks    5 VTI {{1,251.00 USD}}
  Assets:US:Broker:Stocks    2 V {502.12 # 9.95 USD}
  * Assets:US:Bank:Checking

2026-01-10 * "Broker" "Sell shares"
  Assets:US:Broker:Stocks    -3 VTI {} @ 255.00 USD
  Assets:US:Broker:Stocks    -1 V {} @@ 312.00 USD
  Assets:US:Bank:Checking    1,077.00 USD

2026-01-11 * "Split a bill"
  Expenses:Food:Groceries    90.00 / 3 USD
  Assets:Cash               -30.00 USD

2026-01-12 * "Futures margin"
  Assets:US:Broker:Futures   1 /ESM24 {5,000.00 USD}
  Assets:US:Bank:Checking

** Metadata of every kind
pushtag #trip-2026
pushmeta location: "Lisbon"
2026-02-01 * "Hotel" "Two nights"
  booked: 2026-01-15
  paid-with: Assets:US:Bank:Checking
  currency: USD
  category: #lodging
  refundable: FALSE
  confirmed: TRUE
  voucher: NULL
  nights: 2
  rate: 120.00 USD
  total: 2 * 120.00
  remarks:
  Expenses:Travel            240.00 USD
  Assets:US:Bank:Checking
popmeta location:
poptag #trip-2026

** Other directives
2026-02-28 balance Assets:US:Bank:Checking  3,000.00 ~ 0.01 USD
2026-02-28 pad Assets:Cash Equity:Opening-Balances
2026-03-01 note Assets:US:Bank:Checking "Called the bank about a fee" #bank
2026-03-01 document Assets:US:Bank:Checking "statements/2026-02.pdf" ^statement-2026-02
2026-03-01 event "location" "Lisbon, Portugal"
2026-03-01 query "cash" "
  SELECT account, sum(position)
  WHERE account ~ 'Assets:Cash'"
2026-03-01 custom "budget" Expenses:Food:Groceries "monthly" 400.00 USD TRUE 2026-03-31
2026-03-02 note Assets:Cash "A \"quoted\" word and a backslash \\"