doc: document balance assignments (#438)

This commit is contained in:
Simon Michael 2016-12-10 07:56:57 -08:00
parent fe58ef7946
commit 47ca1965b2
4 changed files with 296 additions and 162 deletions

View File

@ -327,7 +327,7 @@ You can usually find an equivalent journal entry using real postings,
which is more correct and provides better error checking. which is more correct and provides better error checking.
.SS Balance Assertions .SS Balance Assertions
.PP .PP
hledger supports ledger\-style balance assertions in journal files. hledger supports Ledger\-style balance assertions in journal files.
These look like \f[C]=EXPECTEDBALANCE\f[] following a posting\[aq]s These look like \f[C]=EXPECTEDBALANCE\f[] following a posting\[aq]s
amount. amount.
Eg in this example we assert the expected dollar balance in accounts a Eg in this example we assert the expected dollar balance in accounts a
@ -423,6 +423,44 @@ Balance assertions are checked against all postings, both real and
virtual. virtual.
They are not affected by the \f[C]\-\-real/\-R\f[] flag or They are not affected by the \f[C]\-\-real/\-R\f[] flag or
\f[C]real:\f[] query. \f[C]real:\f[] query.
.SS Balance Assignments
.PP
Ledger\-style balance assignments are also supported.
These are like balance assertions, but with no posting amount on the
left side of the equals sign; instead it is calculated automatically so
as to satisfy the assertion.
This can be a convenience during data entry, eg when setting opening
balances:
.IP
.nf
\f[C]
;\ starting\ a\ new\ journal,\ set\ asset\ account\ balances\
2016/1/1\ opening\ balances
\ \ assets:checking\ \ \ \ \ \ \ \ \ \ \ \ =\ $409.32
\ \ assets:savings\ \ \ \ \ \ \ \ \ \ \ \ \ =\ $735.24
\ \ assets:cash\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ =\ $42
\ \ equity:opening\ balances
\f[]
.fi
.PP
or when adjusting a balance to reality:
.IP
.nf
\f[C]
;\ no\ cash\ left;\ update\ balance,\ record\ any\ untracked\ spending\ as\ a\ generic\ expense
2016/1/15
\ \ assets:cash\ \ \ \ =\ $0
\ \ expenses:misc
\f[]
.fi
.PP
The calculated amount depends on the account\[aq]s balance in the
commodity at that point (which depends on the previously\-dated postings
of the commodity to that account since the last balance assertion or
assignment).
Note that using balance assignments makes your journal a little less
explicit; to know the exact amount posted, you have to run hledger or do
the calculations yourself, instead of just reading it.
.SS Prices .SS Prices
.SS Transaction prices .SS Transaction prices
.PP .PP

View File

@ -70,6 +70,7 @@ File: hledger_journal.5.info, Node: FILE FORMAT, Next: EDITOR SUPPORT, Prev:
* Amounts:: * Amounts::
* Virtual Postings:: * Virtual Postings::
* Balance Assertions:: * Balance Assertions::
* Balance Assignments::
* Prices:: * Prices::
* Comments:: * Comments::
* Tags:: * Tags::
@ -331,12 +332,12 @@ can usually find an equivalent journal entry using real postings, which
is more correct and provides better error checking. is more correct and provides better error checking.
 
File: hledger_journal.5.info, Node: Balance Assertions, Next: Prices, Prev: Virtual Postings, Up: FILE FORMAT File: hledger_journal.5.info, Node: Balance Assertions, Next: Balance Assignments, Prev: Virtual Postings, Up: FILE FORMAT
1.6 Balance Assertions 1.6 Balance Assertions
====================== ======================
hledger supports ledger-style balance assertions in journal files. These hledger supports Ledger-style balance assertions in journal files. These
look like `=EXPECTEDBALANCE' following a posting's amount. Eg in this look like `=EXPECTEDBALANCE' following a posting's amount. Eg in this
example we assert the expected dollar balance in accounts a and b after example we assert the expected dollar balance in accounts a and b after
each posting: each posting:
@ -442,9 +443,44 @@ Balance assertions are checked against all postings, both real and
virtual. They are not affected by the `--real/-R' flag or `real:' query. virtual. They are not affected by the `--real/-R' flag or `real:' query.
 
File: hledger_journal.5.info, Node: Prices, Next: Comments, Prev: Balance Assertions, Up: FILE FORMAT File: hledger_journal.5.info, Node: Balance Assignments, Next: Prices, Prev: Balance Assertions, Up: FILE FORMAT
1.7 Prices 1.7 Balance Assignments
=======================
Ledger-style balance assignments are also supported. These are like
balance assertions, but with no posting amount on the left side of the
equals sign; instead it is calculated automatically so as to satisfy the
assertion. This can be a convenience during data entry, eg when setting
opening balances:
; starting a new journal, set asset account balances
2016/1/1 opening balances
assets:checking = $409.32
assets:savings = $735.24
assets:cash = $42
equity:opening balances
or when adjusting a balance to reality:
; no cash left; update balance, record any untracked spending as a generic expense
2016/1/15
assets:cash = $0
expenses:misc
The calculated amount depends on the account's balance in the
commodity at that point (which depends on the previously-dated postings
of the commodity to that account since the last balance assertion or
assignment). Note that using balance assignments makes your journal a
little less explicit; to know the exact amount posted, you have to run
hledger or do the calculations yourself, instead of just reading it.

File: hledger_journal.5.info, Node: Prices, Next: Comments, Prev: Balance Assignments, Up: FILE FORMAT
1.8 Prices
========== ==========
* Menu: * Menu:
@ -455,7 +491,7 @@ File: hledger_journal.5.info, Node: Prices, Next: Comments, Prev: Balance Ass
 
File: hledger_journal.5.info, Node: Transaction prices, Next: Market prices, Up: Prices File: hledger_journal.5.info, Node: Transaction prices, Next: Market prices, Up: Prices
1.7.1 Transaction prices 1.8.1 Transaction prices
------------------------ ------------------------
When recording a transaction, you can also record an amount's price in When recording a transaction, you can also record an amount's price in
@ -509,7 +545,7 @@ conversion rate of purchases made in a foreign currency.
 
File: hledger_journal.5.info, Node: Market prices, Prev: Transaction prices, Up: Prices File: hledger_journal.5.info, Node: Market prices, Prev: Transaction prices, Up: Prices
1.7.2 Market prices 1.8.2 Market prices
------------------- -------------------
Market prices are not tied to a particular transaction; they represent Market prices are not tied to a particular transaction; they represent
@ -540,7 +576,7 @@ P 2010/1/1 € $1.40
 
File: hledger_journal.5.info, Node: Comments, Next: Tags, Prev: Prices, Up: FILE FORMAT File: hledger_journal.5.info, Node: Comments, Next: Tags, Prev: Prices, Up: FILE FORMAT
1.8 Comments 1.9 Comments
============ ============
Lines in the journal beginning with a semicolon (`;') or hash (`#') or Lines in the journal beginning with a semicolon (`;') or hash (`#') or
@ -581,8 +617,8 @@ end comment
 
File: hledger_journal.5.info, Node: Tags, Next: Directives, Prev: Comments, Up: FILE FORMAT File: hledger_journal.5.info, Node: Tags, Next: Directives, Prev: Comments, Up: FILE FORMAT
1.9 Tags 1.10 Tags
======== =========
A _tag_ is a word followed by a full colon inside a transaction or A _tag_ is a word followed by a full colon inside a transaction or
posting comment. You can write multiple tags, comma separated. Eg: `; a posting comment. You can write multiple tags, comma separated. Eg: `; a
@ -609,7 +645,7 @@ are simple strings.
 
File: hledger_journal.5.info, Node: Directives, Prev: Tags, Up: FILE FORMAT File: hledger_journal.5.info, Node: Directives, Prev: Tags, Up: FILE FORMAT
1.10 Directives 1.11 Directives
=============== ===============
* Menu: * Menu:
@ -626,7 +662,7 @@ File: hledger_journal.5.info, Node: Directives, Prev: Tags, Up: FILE FORMAT
 
File: hledger_journal.5.info, Node: Account aliases, Next: account directive, Up: Directives File: hledger_journal.5.info, Node: Account aliases, Next: account directive, Up: Directives
1.10.1 Account aliases 1.11.1 Account aliases
---------------------- ----------------------
You can define aliases which rewrite your account names (after reading You can define aliases which rewrite your account names (after reading
@ -655,7 +691,7 @@ be useful for:
 
File: hledger_journal.5.info, Node: Basic aliases, Next: Regex aliases, Up: Account aliases File: hledger_journal.5.info, Node: Basic aliases, Next: Regex aliases, Up: Account aliases
1.10.1.1 Basic aliases 1.11.1.1 Basic aliases
...................... ......................
To set an account alias, use the `alias' directive in your journal To set an account alias, use the `alias' directive in your journal
@ -680,7 +716,7 @@ alias checking = assets:bank:wells fargo:checking
 
File: hledger_journal.5.info, Node: Regex aliases, Next: Multiple aliases, Prev: Basic aliases, Up: Account aliases File: hledger_journal.5.info, Node: Regex aliases, Next: Multiple aliases, Prev: Basic aliases, Up: Account aliases
1.10.1.2 Regex aliases 1.11.1.2 Regex aliases
...................... ......................
There is also a more powerful variant that uses a regular expression, There is also a more powerful variant that uses a regular expression,
@ -706,7 +742,7 @@ alias /^(.+):bank:([^:]+)(.*)/ = \1:\2 \3
 
File: hledger_journal.5.info, Node: Multiple aliases, Next: end aliases, Prev: Regex aliases, Up: Account aliases File: hledger_journal.5.info, Node: Multiple aliases, Next: end aliases, Prev: Regex aliases, Up: Account aliases
1.10.1.3 Multiple aliases 1.11.1.3 Multiple aliases
......................... .........................
You can define as many aliases as you like using directives or You can define as many aliases as you like using directives or
@ -723,7 +759,7 @@ order:
 
File: hledger_journal.5.info, Node: end aliases, Prev: Multiple aliases, Up: Account aliases File: hledger_journal.5.info, Node: end aliases, Prev: Multiple aliases, Up: Account aliases
1.10.1.4 end aliases 1.11.1.4 end aliases
.................... ....................
You can clear (forget) all currently defined aliases with the `end You can clear (forget) all currently defined aliases with the `end
@ -735,7 +771,7 @@ end aliases
 
File: hledger_journal.5.info, Node: account directive, Next: apply account directive, Prev: Account aliases, Up: Directives File: hledger_journal.5.info, Node: account directive, Next: apply account directive, Prev: Account aliases, Up: Directives
1.10.2 account directive 1.11.2 account directive
------------------------ ------------------------
The `account' directive predefines account names, as in Ledger and The `account' directive predefines account names, as in Ledger and
@ -757,7 +793,7 @@ account expenses:food
 
File: hledger_journal.5.info, Node: apply account directive, Next: Multi-line comments, Prev: account directive, Up: Directives File: hledger_journal.5.info, Node: apply account directive, Next: Multi-line comments, Prev: account directive, Up: Directives
1.10.3 apply account directive 1.11.3 apply account directive
------------------------------ ------------------------------
You can specify a parent account which will be prepended to all accounts You can specify a parent account which will be prepended to all accounts
@ -796,7 +832,7 @@ supported.
 
File: hledger_journal.5.info, Node: Multi-line comments, Next: commodity directive, Prev: apply account directive, Up: Directives File: hledger_journal.5.info, Node: Multi-line comments, Next: commodity directive, Prev: apply account directive, Up: Directives
1.10.4 Multi-line comments 1.11.4 Multi-line comments
-------------------------- --------------------------
A line containing just `comment' starts a multi-line comment, and a A line containing just `comment' starts a multi-line comment, and a
@ -805,7 +841,7 @@ line containing just `end comment' ends it. See comments.
 
File: hledger_journal.5.info, Node: commodity directive, Next: Default commodity, Prev: Multi-line comments, Up: Directives File: hledger_journal.5.info, Node: commodity directive, Next: Default commodity, Prev: Multi-line comments, Up: Directives
1.10.5 commodity directive 1.11.5 commodity directive
-------------------------- --------------------------
The `commodity' directive predefines commodities (currently this is The `commodity' directive predefines commodities (currently this is
@ -840,7 +876,7 @@ commodity INR
 
File: hledger_journal.5.info, Node: Default commodity, Next: Default year, Prev: commodity directive, Up: Directives File: hledger_journal.5.info, Node: Default commodity, Next: Default year, Prev: commodity directive, Up: Directives
1.10.6 Default commodity 1.11.6 Default commodity
------------------------ ------------------------
The D directive sets a default commodity (and display format), to be The D directive sets a default commodity (and display format), to be
@ -861,7 +897,7 @@ D $1,000.00
 
File: hledger_journal.5.info, Node: Default year, Next: Including other files, Prev: Default commodity, Up: Directives File: hledger_journal.5.info, Node: Default year, Next: Including other files, Prev: Default commodity, Up: Directives
1.10.7 Default year 1.11.7 Default year
------------------- -------------------
You can set a default year to be used for subsequent dates which don't You can set a default year to be used for subsequent dates which don't
@ -888,7 +924,7 @@ Y2010 ; change default year to 2010
 
File: hledger_journal.5.info, Node: Including other files, Prev: Default year, Up: Directives File: hledger_journal.5.info, Node: Including other files, Prev: Default year, Up: Directives
1.10.8 Including other files 1.11.8 Including other files
---------------------------- ----------------------------
You can pull in the content of additional journal files by writing an You can pull in the content of additional journal files by writing an
@ -929,69 +965,71 @@ Tag Table:
Node: Top94 Node: Top94
Node: FILE FORMAT2284 Node: FILE FORMAT2284
Ref: #file-format2410 Ref: #file-format2410
Node: Transactions2569 Node: Transactions2593
Ref: #transactions2689 Ref: #transactions2713
Node: Dates3632 Node: Dates3656
Ref: #dates3760 Ref: #dates3784
Node: Simple dates3825 Node: Simple dates3849
Ref: #simple-dates3953 Ref: #simple-dates3977
Node: Secondary dates4317 Node: Secondary dates4341
Ref: #secondary-dates4473 Ref: #secondary-dates4497
Node: Posting dates6033 Node: Posting dates6057
Ref: #posting-dates6164 Ref: #posting-dates6188
Node: Account names7535 Node: Account names7559
Ref: #account-names7674 Ref: #account-names7698
Node: Amounts8159 Node: Amounts8183
Ref: #amounts8297 Ref: #amounts8321
Node: Virtual Postings10396 Node: Virtual Postings10420
Ref: #virtual-postings10557 Ref: #virtual-postings10581
Node: Balance Assertions11777 Node: Balance Assertions11801
Ref: #balance-assertions11941 Ref: #balance-assertions11978
Node: Assertions and ordering12763 Node: Assertions and ordering12800
Ref: #assertions-and-ordering12948 Ref: #assertions-and-ordering12985
Node: Assertions and commodities13979 Node: Assertions and commodities14016
Ref: #assertions-and-commodities14205 Ref: #assertions-and-commodities14242
Node: Assertions and subaccounts14897 Node: Assertions and subaccounts14934
Ref: #assertions-and-subaccounts15131 Ref: #assertions-and-subaccounts15168
Node: Assertions and virtual postings15653 Node: Assertions and virtual postings15690
Ref: #assertions-and-virtual-postings15862 Ref: #assertions-and-virtual-postings15899
Node: Prices16003 Node: Balance Assignments16040
Ref: #prices16135 Ref: #balance-assignments16209
Node: Transaction prices16186 Node: Prices17327
Ref: #transaction-prices16331 Ref: #prices17460
Node: Market prices17938 Node: Transaction prices17511
Ref: #market-prices18073 Ref: #transaction-prices17656
Node: Comments18961 Node: Market prices19263
Ref: #comments19083 Ref: #market-prices19398
Node: Tags20195 Node: Comments20286
Ref: #tags20313 Ref: #comments20408
Node: Directives21236 Node: Tags21520
Ref: #directives21351 Ref: #tags21640
Node: Account aliases21544 Node: Directives22563
Ref: #account-aliases21690 Ref: #directives22678
Node: Basic aliases22292 Node: Account aliases22871
Ref: #basic-aliases22437 Ref: #account-aliases23017
Node: Regex aliases23125 Node: Basic aliases23619
Ref: #regex-aliases23295 Ref: #basic-aliases23764
Node: Multiple aliases24065 Node: Regex aliases24452
Ref: #multiple-aliases24239 Ref: #regex-aliases24622
Node: end aliases24735 Node: Multiple aliases25392
Ref: #end-aliases24877 Ref: #multiple-aliases25566
Node: account directive24979 Node: end aliases26062
Ref: #account-directive25161 Ref: #end-aliases26204
Node: apply account directive25457 Node: account directive26306
Ref: #apply-account-directive25655 Ref: #account-directive26488
Node: Multi-line comments26315 Node: apply account directive26784
Ref: #multi-line-comments26507 Ref: #apply-account-directive26982
Node: commodity directive26634 Node: Multi-line comments27642
Ref: #commodity-directive26820 Ref: #multi-line-comments27834
Node: Default commodity27693 Node: commodity directive27961
Ref: #default-commodity27868 Ref: #commodity-directive28147
Node: Default year28404 Node: Default commodity29020
Ref: #default-year28571 Ref: #default-commodity29195
Node: Including other files28994 Node: Default year29731
Ref: #including-other-files29153 Ref: #default-year29898
Node: EDITOR SUPPORT29549 Node: Including other files30321
Ref: #editor-support29669 Ref: #including-other-files30480
Node: EDITOR SUPPORT30876
Ref: #editor-support30996
 
End Tag Table End Tag Table

View File

@ -251,8 +251,8 @@ Virtual postings have some legitimate uses, but those are few. You can usually f
## Balance Assertions ## Balance Assertions
hledger supports ledger-style hledger supports
[balance assertions](http://ledger-cli.org/3.0/doc/ledger3.html#Balance-assertions) [Ledger-style balance assertions](http://ledger-cli.org/3.0/doc/ledger3.html#Balance-assertions)
in journal files. in journal files.
These look like `=EXPECTEDBALANCE` following a posting's amount. Eg in These look like `=EXPECTEDBALANCE` following a posting's amount. Eg in
this example we assert the expected dollar balance in accounts a and b after this example we assert the expected dollar balance in accounts a and b after
@ -339,6 +339,36 @@ Balance assertions are checked against all postings, both real and
flag or `real:` query. flag or `real:` query.
## Balance Assignments
[Ledger-style balance assignments](http://ledger-cli.org/3.0/doc/ledger3.html#Balance-assignments) are also supported.
These are like [balance assertions](#balance-assertions), but with no posting amount on the left side of the equals sign;
instead it is calculated automatically so as to satisfy the assertion.
This can be a convenience during data entry, eg when setting opening balances:
```journal
; starting a new journal, set asset account balances
2016/1/1 opening balances
assets:checking = $409.32
assets:savings = $735.24
assets:cash = $42
equity:opening balances
```
or when adjusting a balance to reality:
```journal
; no cash left; update balance, record any untracked spending as a generic expense
2016/1/15
assets:cash = $0
expenses:misc
```
The calculated amount depends on the account's balance in the commodity at that point
(which depends on the previously-dated postings of the commodity to that account
since the last balance assertion or assignment).
Note that using balance assignments makes your journal a little less explicit;
to know the exact amount posted, you have to run hledger or do the calculations yourself,
instead of just reading it.
## Prices ## Prices
### Transaction prices ### Transaction prices

View File

@ -253,7 +253,7 @@ FILE FORMAT
more correct and provides better error checking. more correct and provides better error checking.
Balance Assertions Balance Assertions
hledger supports ledger-style balance assertions in journal files. hledger supports Ledger-style balance assertions in journal files.
These look like =EXPECTEDBALANCE following a posting's amount. Eg in These look like =EXPECTEDBALANCE following a posting's amount. Eg in
this example we assert the expected dollar balance in accounts a and b this example we assert the expected dollar balance in accounts a and b
after each posting: after each posting:
@ -329,21 +329,49 @@ FILE FORMAT
Balance assertions are checked against all postings, both real and vir- Balance assertions are checked against all postings, both real and vir-
tual. They are not affected by the --real/-R flag or real: query. tual. They are not affected by the --real/-R flag or real: query.
Balance Assignments
Ledger-style balance assignments are also supported. These are like
balance assertions, but with no posting amount on the left side of the
equals sign; instead it is calculated automatically so as to satisfy
the assertion. This can be a convenience during data entry, eg when
setting opening balances:
; starting a new journal, set asset account balances
2016/1/1 opening balances
assets:checking = $409.32
assets:savings = $735.24
assets:cash = $42
equity:opening balances
or when adjusting a balance to reality:
; no cash left; update balance, record any untracked spending as a generic expense
2016/1/15
assets:cash = $0
expenses:misc
The calculated amount depends on the account's balance in the commodity
at that point (which depends on the previously-dated postings of the
commodity to that account since the last balance assertion or assign-
ment). Note that using balance assignments makes your journal a little
less explicit; to know the exact amount posted, you have to run hledger
or do the calculations yourself, instead of just reading it.
Prices Prices
Transaction prices Transaction prices
When recording a transaction, you can also record an amount's price in When recording a transaction, you can also record an amount's price in
another commodity. This documents the exchange rate, cost (of a pur- another commodity. This documents the exchange rate, cost (of a pur-
chase), or selling price (of a sale) that was in effect within this chase), or selling price (of a sale) that was in effect within this
particular transaction (or more precisely, within the particular post- particular transaction (or more precisely, within the particular post-
ing). These transaction prices are fixed, and do not change. ing). These transaction prices are fixed, and do not change.
Such priced amounts can be displayed in their transaction price's com- Such priced amounts can be displayed in their transaction price's com-
modity, by using the --cost/-B flag (B for "cost Basis"), supported by modity, by using the --cost/-B flag (B for "cost Basis"), supported by
most hledger commands. most hledger commands.
There are three ways to specify a transaction price: There are three ways to specify a transaction price:
1. Write the unit price (aka exchange rate), as @ UNITPRICE after the 1. Write the unit price (aka exchange rate), as @ UNITPRICE after the
amount: amount:
2009/1/1 2009/1/1
@ -357,7 +385,7 @@ FILE FORMAT
assets:cash assets:cash
3. Or let hledger infer the price so as to balance the transaction. To 3. Or let hledger infer the price so as to balance the transaction. To
permit this, you must fully specify all posting amounts, and their permit this, you must fully specify all posting amounts, and their
sum must have a non-zero amount in exactly two commodities: sum must have a non-zero amount in exactly two commodities:
2009/1/1 2009/1/1
@ -371,17 +399,17 @@ FILE FORMAT
assets:foreign currency $135.00 assets:foreign currency $135.00
assets:cash $-135.00 assets:cash $-135.00
Example use for transaction prices: recording the effective conversion Example use for transaction prices: recording the effective conversion
rate of purchases made in a foreign currency. rate of purchases made in a foreign currency.
Market prices Market prices
Market prices are not tied to a particular transaction; they represent Market prices are not tied to a particular transaction; they represent
historical exchange rates between two commodities, usually from some historical exchange rates between two commodities, usually from some
public market which publishes such rates. public market which publishes such rates.
When market prices are known, the -V/--value option will use them to When market prices are known, the -V/--value option will use them to
convert reported amounts to their market value as of the report end convert reported amounts to their market value as of the report end
date. This option is currently available only with the balance com- date. This option is currently available only with the balance com-
mand. mand.
You record market prices (Ledger calls them historical prices) with a P You record market prices (Ledger calls them historical prices) with a P
@ -391,7 +419,7 @@ FILE FORMAT
P DATE COMMODITYSYMBOL UNITPRICE P DATE COMMODITYSYMBOL UNITPRICE
For example, the following directives say that the euro's exchange rate For example, the following directives say that the euro's exchange rate
was 1.35 US dollars during 2009, and $1.40 from 2010 onward (and was 1.35 US dollars during 2009, and $1.40 from 2010 onward (and
unknown before 2009). unknown before 2009).
P 2009/1/1 $1.35 P 2009/1/1 $1.35
@ -400,17 +428,17 @@ FILE FORMAT
Example use for market prices: tracking the value of stocks. Example use for market prices: tracking the value of stocks.
Comments Comments
Lines in the journal beginning with a semicolon (;) or hash (#) or Lines in the journal beginning with a semicolon (;) or hash (#) or
asterisk (*) are comments, and will be ignored. (Asterisk comments asterisk (*) are comments, and will be ignored. (Asterisk comments
make it easy to treat your journal like an org-mode outline in emacs.) make it easy to treat your journal like an org-mode outline in emacs.)
Also, anything between comment and end comment directives is a Also, anything between comment and end comment directives is a
(multi-line) comment. If there is no end comment, the comment extends (multi-line) comment. If there is no end comment, the comment extends
to the end of the file. to the end of the file.
You can attach comments to a transaction by writing them after the You can attach comments to a transaction by writing them after the
description and/or indented on the following lines (before the post- description and/or indented on the following lines (before the post-
ings). Similarly, you can attach comments to an individual posting by ings). Similarly, you can attach comments to an individual posting by
writing them after the amount and/or indented on the following lines. writing them after the amount and/or indented on the following lines.
Some examples: Some examples:
@ -435,30 +463,30 @@ FILE FORMAT
; a journal comment (because not indented) ; a journal comment (because not indented)
Tags Tags
A tag is a word followed by a full colon inside a transaction or post- A tag is a word followed by a full colon inside a transaction or post-
ing comment. You can write multiple tags, comma separated. Eg: ing comment. You can write multiple tags, comma separated. Eg:
; a comment containing sometag:, anothertag:. You can search for tags ; a comment containing sometag:, anothertag:. You can search for tags
with the tag: query. with the tag: query.
A tag can also have a value, which is any text between the colon and A tag can also have a value, which is any text between the colon and
the next comma or newline, excluding leading/trailing whitespace. (So the next comma or newline, excluding leading/trailing whitespace. (So
hledger tag values can not contain commas or newlines). hledger tag values can not contain commas or newlines).
Tags in a transaction comment affect the transaction and all of its Tags in a transaction comment affect the transaction and all of its
postings, while tags in a posting comment affect only that posting. postings, while tags in a posting comment affect only that posting.
For example, the following transaction has three tags (A, TAG2, For example, the following transaction has three tags (A, TAG2,
third-tag) and the posting has four (A, TAG2, third-tag, posting-tag): third-tag) and the posting has four (A, TAG2, third-tag, posting-tag):
1/1 a transaction ; A:, TAG2: 1/1 a transaction ; A:, TAG2:
; third-tag: a third transaction tag, this time with a value ; third-tag: a third transaction tag, this time with a value
(a) $1 ; posting-tag: (a) $1 ; posting-tag:
Tags are like Ledger's metadata feature, except hledger's tag values Tags are like Ledger's metadata feature, except hledger's tag values
are simple strings. are simple strings.
Directives Directives
Account aliases Account aliases
You can define aliases which rewrite your account names (after reading You can define aliases which rewrite your account names (after reading
the journal, before generating reports). hledger's account aliases can the journal, before generating reports). hledger's account aliases can
be useful for: be useful for:
@ -475,8 +503,8 @@ FILE FORMAT
See also How to use account aliases. See also How to use account aliases.
Basic aliases Basic aliases
To set an account alias, use the alias directive in your journal file. To set an account alias, use the alias directive in your journal file.
This affects all subsequent journal entries in the current file or its This affects all subsequent journal entries in the current file or its
included files. The spaces around the = are optional: included files. The spaces around the = are optional:
alias OLD = NEW alias OLD = NEW
@ -484,53 +512,53 @@ FILE FORMAT
Or, you can use the --alias 'OLD=NEW' option on the command line. This Or, you can use the --alias 'OLD=NEW' option on the command line. This
affects all entries. It's useful for trying out aliases interactively. affects all entries. It's useful for trying out aliases interactively.
OLD and NEW are full account names. hledger will replace any occur- OLD and NEW are full account names. hledger will replace any occur-
rence of the old account name with the new one. Subaccounts are also rence of the old account name with the new one. Subaccounts are also
affected. Eg: affected. Eg:
alias checking = assets:bank:wells fargo:checking alias checking = assets:bank:wells fargo:checking
# rewrites "checking" to "assets:bank:wells fargo:checking", or "checking:a" to "assets:bank:wells fargo:checking:a" # rewrites "checking" to "assets:bank:wells fargo:checking", or "checking:a" to "assets:bank:wells fargo:checking:a"
Regex aliases Regex aliases
There is also a more powerful variant that uses a regular expression, There is also a more powerful variant that uses a regular expression,
indicated by the forward slashes. (This was the default behaviour in indicated by the forward slashes. (This was the default behaviour in
hledger 0.24-0.25): hledger 0.24-0.25):
alias /REGEX/ = REPLACEMENT alias /REGEX/ = REPLACEMENT
or --alias '/REGEX/=REPLACEMENT'. or --alias '/REGEX/=REPLACEMENT'.
REGEX is a case-insensitive regular expression. Anywhere it matches REGEX is a case-insensitive regular expression. Anywhere it matches
inside an account name, the matched part will be replaced by REPLACE- inside an account name, the matched part will be replaced by REPLACE-
MENT. If REGEX contains parenthesised match groups, these can be ref- MENT. If REGEX contains parenthesised match groups, these can be ref-
erenced by the usual numeric backreferences in REPLACEMENT. Note, cur- erenced by the usual numeric backreferences in REPLACEMENT. Note, cur-
rently regular expression aliases may cause noticeable slow-downs. rently regular expression aliases may cause noticeable slow-downs.
(And if you use Ledger on your hledger file, they will be ignored.) Eg: (And if you use Ledger on your hledger file, they will be ignored.) Eg:
alias /^(.+):bank:([^:]+)(.*)/ = \1:\2 \3 alias /^(.+):bank:([^:]+)(.*)/ = \1:\2 \3
# rewrites "assets:bank:wells fargo:checking" to "assets:wells fargo checking" # rewrites "assets:bank:wells fargo:checking" to "assets:wells fargo checking"
Multiple aliases Multiple aliases
You can define as many aliases as you like using directives or com- You can define as many aliases as you like using directives or com-
mand-line options. Aliases are recursive - each alias sees the result mand-line options. Aliases are recursive - each alias sees the result
of applying previous ones. (This is different from Ledger, where of applying previous ones. (This is different from Ledger, where
aliases are non-recursive by default). Aliases are applied in the fol- aliases are non-recursive by default). Aliases are applied in the fol-
lowing order: lowing order:
1. alias directives, most recently seen first (recent directives take 1. alias directives, most recently seen first (recent directives take
precedence over earlier ones; directives not yet seen are ignored) precedence over earlier ones; directives not yet seen are ignored)
2. alias options, in the order they appear on the command line 2. alias options, in the order they appear on the command line
end aliases end aliases
You can clear (forget) all currently defined aliases with the You can clear (forget) all currently defined aliases with the
end aliases directive: end aliases directive:
end aliases end aliases
account directive account directive
The account directive predefines account names, as in Ledger and Bean- The account directive predefines account names, as in Ledger and Bean-
count. This may be useful for your own documentation; hledger doesn't count. This may be useful for your own documentation; hledger doesn't
make use of it yet. make use of it yet.
; account ACCT ; account ACCT
@ -545,8 +573,8 @@ FILE FORMAT
; etc. ; etc.
apply account directive apply account directive
You can specify a parent account which will be prepended to all You can specify a parent account which will be prepended to all
accounts within a section of the journal. Use the apply account and accounts within a section of the journal. Use the apply account and
end apply account directives like so: end apply account directives like so:
apply account home apply account home
@ -563,7 +591,7 @@ FILE FORMAT
home:food $10 home:food $10
home:cash $-10 home:cash $-10
If end apply account is omitted, the effect lasts to the end of the If end apply account is omitted, the effect lasts to the end of the
file. Included files are also affected, eg: file. Included files are also affected, eg:
apply account business apply account business
@ -572,16 +600,16 @@ FILE FORMAT
apply account personal apply account personal
include personal.journal include personal.journal
Prior to hledger 1.0, legacy account and end spellings were also sup- Prior to hledger 1.0, legacy account and end spellings were also sup-
ported. ported.
Multi-line comments Multi-line comments
A line containing just comment starts a multi-line comment, and a line A line containing just comment starts a multi-line comment, and a line
containing just end comment ends it. See comments. containing just end comment ends it. See comments.
commodity directive commodity directive
The commodity directive predefines commodities (currently this is just The commodity directive predefines commodities (currently this is just
informational), and also it may define the display format for amounts informational), and also it may define the display format for amounts
in this commodity (overriding the automatically inferred format). in this commodity (overriding the automatically inferred format).
It may be written on a single line, like this: It may be written on a single line, like this:
@ -593,8 +621,8 @@ FILE FORMAT
; separating thousands with comma. ; separating thousands with comma.
commodity 1,000.0000 AAAA commodity 1,000.0000 AAAA
or on multiple lines, using the "format" subdirective. In this case or on multiple lines, using the "format" subdirective. In this case
the commodity symbol appears twice and should be the same in both the commodity symbol appears twice and should be the same in both
places: places:
; commodity SYMBOL ; commodity SYMBOL
@ -607,10 +635,10 @@ FILE FORMAT
format INR 9,99,99,999.00 format INR 9,99,99,999.00
Default commodity Default commodity
The D directive sets a default commodity (and display format), to be The D directive sets a default commodity (and display format), to be
used for amounts without a commodity symbol (ie, plain numbers). (Note used for amounts without a commodity symbol (ie, plain numbers). (Note
this differs from Ledger's default commodity directive.) The commodity this differs from Ledger's default commodity directive.) The commodity
and display format will be applied to all subsequent commodity-less and display format will be applied to all subsequent commodity-less
amounts, or until the next D directive. amounts, or until the next D directive.
# commodity-less amounts should be treated as dollars # commodity-less amounts should be treated as dollars
@ -622,8 +650,8 @@ FILE FORMAT
b b
Default year Default year
You can set a default year to be used for subsequent dates which don't You can set a default year to be used for subsequent dates which don't
specify a year. This is a line beginning with Y followed by the year. specify a year. This is a line beginning with Y followed by the year.
Eg: Eg:
Y2009 ; set default year to 2009 Y2009 ; set default year to 2009
@ -643,24 +671,24 @@ FILE FORMAT
assets assets
Including other files Including other files
You can pull in the content of additional journal files by writing an You can pull in the content of additional journal files by writing an
include directive, like this: include directive, like this:
include path/to/file.journal include path/to/file.journal
If the path does not begin with a slash, it is relative to the current If the path does not begin with a slash, it is relative to the current
file. Glob patterns (*) are not currently supported. file. Glob patterns (*) are not currently supported.
The include directive can only be used in journal files. It can The include directive can only be used in journal files. It can
include journal, timeclock or timedot files, but not CSV files. include journal, timeclock or timedot files, but not CSV files.
EDITOR SUPPORT EDITOR SUPPORT
Add-on modes exist for various text editors, to make working with jour- Add-on modes exist for various text editors, to make working with jour-
nal files easier. They add colour, navigation aids and helpful com- nal files easier. They add colour, navigation aids and helpful com-
mands. For hledger users who edit the journal file directly (the mands. For hledger users who edit the journal file directly (the
majority), using one of these modes is quite recommended. majority), using one of these modes is quite recommended.
These were written with Ledger in mind, but also work with hledger These were written with Ledger in mind, but also work with hledger
files: files:
@ -677,7 +705,7 @@ EDITOR SUPPORT
REPORTING BUGS REPORTING BUGS
Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel
or hledger mail list) or hledger mail list)
@ -691,7 +719,7 @@ COPYRIGHT
SEE ALSO SEE ALSO
hledger(1), hledger-ui(1), hledger-web(1), hledger-api(1), hledger(1), hledger-ui(1), hledger-web(1), hledger-api(1),
hledger_csv(5), hledger_journal(5), hledger_timeclock(5), hledger_time- hledger_csv(5), hledger_journal(5), hledger_timeclock(5), hledger_time-
dot(5), ledger(1) dot(5), ledger(1)