Skip to content

Commit 5def834

Browse files
committed
;doc: journal cheatsheet cleanups
1 parent 878ebac commit 5def834

File tree

1 file changed

+111
-71
lines changed

1 file changed

+111
-71
lines changed

hledger/hledger.m4.md

Lines changed: 111 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -815,91 +815,131 @@ Here's a quick cheatsheet/overview, followed by detailed descriptions of each pa
815815
```journal
816816
# Here is the main syntax of hledger's journal format
817817
# (omitting extra Ledger compatibility syntax).
818-
# hledger journals contain comments, directives, and transactions, in any order:
819818
820819
###############################################################################
821-
# 1. Comment lines are for notes or temporarily disabling things.
822-
# They begin with #, ;, or a line containing the word "comment".
823820
824-
# hash comment line
825-
; semicolon comment line
821+
# 1. These are comment lines, for notes or temporarily disabling things.
822+
; They begin with # or ;
823+
826824
comment
827-
These lines
828-
are commented.
825+
Or, lines can be enclosed within "comment" / "end comment".
826+
This is a block of
827+
commented lines.
829828
end comment
830829
831-
# Some but not all hledger entries can have same-line comments attached to them,
832-
# from ; (semicolon) to end of line.
830+
# Some journal entries can have semicolon comments at end of line ; like this
831+
# Some of them require 2 or more spaces before the semicolon.
833832
834833
###############################################################################
835-
# 2. Directives modify parsing or reports in some way.
836-
# They begin with a word or letter (or symbol).
837834
838-
account actifs ; type:A, declare an account that is an Asset. 2+ spaces before ;.
839-
account passifs ; type:L, declare an account that is a Liability, and so on.. (ALERX)
840-
alias chkg = assets:checking
841-
commodity $0.00
842-
decimal-mark .
843-
include /dev/null
844-
payee Whole Foods
845-
P 2022-01-01 AAAA $1.40
846-
~ monthly budget goals ; <- 2+ spaces between period expression and description
847-
expenses:food $400
848-
expenses:home $1000
849-
budgeted
835+
# 2. Directives customise processing or output in some way.
836+
# You don't need any directives to get started.
837+
# But they can add more error checking, or change how things are displayed.
838+
# They begin with a word, letter, or symbol.
839+
# They are most often placed at the top, before transactions.
840+
841+
account assets ; Declare valid account names and display order.
842+
account assets:savings ; A subaccount. This one represents a bank account.
843+
account assets:checking ; Another. Note, 2+ spaces after the account name.
844+
account assets:receivable ; Accounting type is inferred from english names,
845+
account passifs ; or declared with a "type" tag, type:L
846+
account expenses ; type:X
847+
; A follow-on comment line, indented.
848+
account expenses:rent ; Expense and revenue categories are also accounts.
849+
; Subaccounts inherit their parent's type.
850+
851+
commodity $0.00 ; Declare valid commodities and their display styles.
852+
commodity 1.000,00 EUR
853+
854+
decimal-mark . ; The decimal mark used in this file (if ambiguous).
855+
856+
payee Whole Foods ; Declare a valid payee name.
857+
858+
tag trip ; Declare a valid tag name.
859+
860+
P 2024-03-01 AAPL $179 ; Declare a market price for AAPL in $ on this date.
861+
862+
include other.journal ; Include another journal file here.
863+
864+
# Declare a recurring "periodic transaction", for budget/forecast reports
865+
~ monthly set budget goals ; <- Note, 2+ spaces before the description.
866+
(expenses:rent) $1000
867+
(expenses:food) $500
868+
869+
# Declare an auto posting rule, to modify existing transactions in reports
870+
= revenues:consulting
871+
liabilities:tax:2024:us *0.25 ; Add a tax liability & expense
872+
expenses:tax:2024:us *-0.25 ; for 25% of the revenue.
850873
851874
###############################################################################
852-
# 3. Transactions are what it's all about; they are dated events,
853-
# usually describing movements of money.
854-
# They begin with a date.
855-
856-
# DATE DESCRIPTION ; This is a transaction comment.
857-
# ACCOUNT NAME 1 AMOUNT1 ; <- posting 1. This is a posting comment.
858-
# ACCOUNT NAME 2 AMOUNT2 ; <- posting 2. Postings must be indented.
859-
# ; ^^ At least 2 spaces between account and amount.
860-
# ... ; Any number of postings is allowed. The amounts must balance (sum to 0).
861-
862-
2022-01-01 opening balances are declared this way
863-
assets:checking $1000 ; Account names can be anything. lower case is easy to type.
864-
assets:savings $1000 ; assets, liabilities, equity, revenues, expenses are common.
865-
assets:cash:wallet $100 ; : indicates subaccounts.
866-
liabilities:credit card $-200 ; liabilities, equity, revenues balances are usually negative.
867-
equity ; One amount can be left blank; $-1900 is inferred here.
868-
869-
2022-04-15 * (#12345) pay taxes
875+
876+
# 3. Transactions are what it's all about.
877+
# They are dated events, usually movements of money between 2 or more accounts.
878+
# They begin with a numeric date.
879+
# Here is their basic shape:
880+
#
881+
# DATE DESCRIPTION ; The transaction's date and optional description.
882+
# ACCOUNT1 AMOUNT ; A posting of an amount to/from this account, indented.
883+
# ACCOUNT2 AMOUNT ; A second posting, balancing the first.
884+
# ... ; More if needed. Amounts must sum to zero.
885+
# ; Note, 2+ spaces between account names and amounts.
886+
887+
2024-01-01 opening balances ; At the start, declare pre-existing balances this way.
888+
assets:savings $10000 ; Account names can be anything. lower case is easy to type.
889+
assets:checking $1000 ; assets, liabilities, equity, revenues, expenses are common.
890+
liabilities:credit card $-500 ; liabilities, equity, revenues balances are usually negative.
891+
equity:start ; One amount can be left blank. $-10500 is inferred here.
892+
; Some of these accounts we didn't declare above,
893+
; so -s/--strict would complain.
894+
895+
2024-01-03 ! (12345) pay rent
896+
; Additional transaction comment lines, indented.
870897
; There can be a ! or * after the date meaning "pending" or "cleared".
871-
; There can be a transaction code (text in parentheses) after the date/status.
872-
; Amounts' sign represents direction of flow, or credit/debit:
873-
assets:checking $-500 ; minus means removed from this account (credit)
874-
expenses:tax:us:2021 $500 ; plus means added to this account (debit)
875-
; revenue/expense categories are also "accounts"
876-
877-
2022-01-01 ; The description is optional.
878-
; Any currency/commodity symbols are allowed, on either side.
879-
assets:cash:wallet GBP -10
880-
expenses:clothing GBP 10
881-
assets:gringotts -10 gold
882-
assets:pouch 10 gold
883-
revenues:gifts -2 "Liquorice Wands" ; Complex symbols
884-
assets:bag 2 "Liquorice Wands" ; must be double-quoted.
885-
886-
2022-01-01 Cost in another commodity can be noted with @ or @@
887-
assets:investments 2.0 AAAA @ $1.50 ; @ means per-unit cost
888-
assets:investments 3.0 AAAA @@ $4 ; @@ means total cost
889-
assets:checking $-7.00
890-
891-
2022-01-02 assert balances
892-
; Balances can be asserted for extra error checking, in any transaction.
893-
assets:investments 0 AAAA = 5.0 AAAA
894-
assets:pouch 0 gold = 10 gold
895-
assets:savings $0 = $1000
896-
897-
1999-12-31 Ordering transactions by date is recommended but not required.
898+
; There can be a parenthesised (code) after the date/status.
899+
; Amounts' sign shows direction of flow.
900+
assets:checking $-500 ; Minus means removed from this account (credit).
901+
expenses:rent $500 ; Plus means added to this account (debit).
902+
903+
; Keeping transactions in date order is optional (but helps error checking).
904+
905+
2024-01-02 Gringott's Bank | withdrawal ; Description can be PAYEE | NOTE
906+
assets:bank:gold -10 gold
907+
assets:pouch 10 gold
908+
909+
2024-01-02 shopping
910+
expenses:clothing 1 gold
911+
expenses:wands 5 gold
912+
assets:pouch -6 gold
913+
914+
2024-01-02 receive gift
915+
revenues:gifts -3 "Chocolate Frogs" ; Complex commodity symbols
916+
assets:pouch 3 "Chocolate Frogs" ; must be in double quotes.
917+
918+
2024-01-15 buy some shares, in two lots ; Cost can be noted.
919+
assets:investments:2024-01-15 2.0 AAAA @ $1.50 ; @ means per-unit cost
920+
assets:investments:2024-01-15-02 3.0 AAAA @@ $4 ; @@ means total cost
921+
; ^ Per-lot subaccounts are sometimes useful.
922+
assets:checking $-7
923+
924+
2024-01-15 assert some account balances on this date
925+
; Balances can be asserted in any transaction, with =, for extra error checking.
926+
; Assertion txns like this one can be made with hledger close --assert --show-costs
927+
;
928+
assets:savings $0 = $10000
929+
assets:checking $0 = $493
930+
assets:bank:gold 0 gold = -10 gold
931+
assets:pouch 0 gold = 4 gold
932+
assets:pouch 0 "Chocolate Frogs" = 3 "Chocolate Frogs"
933+
assets:investments:2024-01-15 0.0 AAAA = 2.0 AAAA @ $1.50
934+
assets:investments:2024-01-15-02 0.0 AAAA = 3.0 AAAA @@ $4
935+
liabilities:credit card $0 = $-500
936+
937+
2024-02-01 note some event, or a transaction not yet fully entered, on this date
898938
; Postings are not required.
899939
900-
2022.01.01 These date
901-
2022/1/1 formats are
902-
12/31 also allowed (but consistent YYYY-MM-DD is recommended).
940+
; Some other date formats are allowed (but, consistent YYYY-MM-DD is useful).
941+
2024.01.01
942+
2024/1/1
903943
```
904944

905945
## Comments

0 commit comments

Comments
 (0)