Skip to content

print: beancount: convert underscores in account names to CamelCase - #2596

Open
waj wants to merge 1 commit into
plaintextaccounting:mainfrom
waj:imp/beancount-account-underscores
Open

print: beancount: convert underscores in account names to CamelCase#2596
waj wants to merge 1 commit into
plaintextaccounting:mainfrom
waj:imp/beancount-account-underscores

Conversation

@waj

@waj waj commented May 19, 2026

Copy link
Copy Markdown
Contributor

Underscore-separated subparts within an account name component are now capitalised and joined, so e.g. assets:wells_fargo:fima_usd becomes Assets:WellsFargo:FimaUsd instead of the previous hex-encoded Assets:WellsC5ffargo:FimaC5fusd. Underscores in hledger account names are conventionally used as a space substitute, so treating them as word boundaries produces much cleaner Beancount output.

Underscore-separated subparts within an account name component are now
capitalised and joined, so e.g. assets:wells_fargo:fima_usd becomes
Assets:WellsFargo:FimaUsd instead of the previous hex-encoded
Assets:WellsC5ffargo:FimaC5fusd. Underscores in hledger account names
are conventionally used as a space substitute, so treating them as word
boundaries produces much cleaner Beancount output.
@simonmichael

Copy link
Copy Markdown
Collaborator

Thanks for the PR.
We haven't had review bandwidth to keep up with PRs lately; this will be reviewed ASAP.

@simonmichael simonmichael changed the title imp: print: beancount: convert underscores in account names to CamelCase print: beancount: convert underscores in account names to CamelCase Jul 31, 2026
@simonmichael simonmichael added print beancount The beancount output format. labels Jul 31, 2026
@simonmichael

simonmichael commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

I use hyphens rather than underscores to separate account name sub-parts; and of course spaces are the other common separator. Here's how they're all handled currently:

~/src/hledger$ cat a.j
2000-01-01
  Assets
  Expenses:foo_bar  1
  Expenses:foo-bar  1
  Expenses:foo bar  1

~/src/hledger$ hledger -f a.j print -O beancount
...
2000-01-01 *
    Assets:A
    Expenses:FooC5fbar            1 CC
    Expenses:Foo-bar              1 CC
    Expenses:Foo-bar              1 CC

Would it be simpler and more consistent to replace _ with - ?

https://hledger.org/1.52/hledger.html#beancount-account-names currently says

hledger will adjust your account names to make valid Beancount account names by capitalising each part, replacing spaces with -, replacing other unsupported characters with C<HEXBYTES>, prepending A to account name parts which don't begin with a letter or digit, and appending :A to account names which have only one part.

It would be nice to always use - and never C<HEXBYTES>; but I think we can't do that, because then you could quite easily get names containing many hyphens, likely to overlap.

@simonmichael simonmichael added journal The journal file format, and its features. needs-changes To unblock: needs some changes made, in line with recommendations labels Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beancount The beancount output format. journal The journal file format, and its features. needs-changes To unblock: needs some changes made, in line with recommendations print

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants