Visitar URL original
print: beancount: convert underscores in account names to CamelCase by waj · Pull Request #2596 · hledgerorg/hledger · GitHub
Skip to content

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

Closed
waj wants to merge 1 commit into
hledgerorg:mainfrom
waj:imp/beancount-account-underscores
Closed

waj wants to merge 1 commit into
hledgerorg: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
Member

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
Member

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
@simonmichael

Copy link
Copy Markdown
Member

I think the simplest, most consistent fix is to replace underscore with hyphen, as we do for spaces. Would you like to follow up on this @waj ?

simonmichael added a commit that referenced this pull request Sep 7, 2026
…2596]

Underscores are a common hledger word separator, like spaces; converting
them to dashes rather than hex-encoding them (assets:wells_fargo ->
Assets:Wells-fargo, not Assets:WellsC5ffargo) gives cleaner and more
consistent beancount account names.

AI usage: Opus 5, ~4k output tokens
@simonmichael

Copy link
Copy Markdown
Member

I went with that alternate fix. Thanks for raising the issue.

@simonmichael simonmichael removed the needs-changes To unblock: needs some changes made, in line with recommendations label Sep 7, 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. print

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants