@@ -1581,17 +1581,19 @@ except they may contain [tags](#tags), which are not ignored.
1581
1581
1582
1582
<!-- same section name as Commands > tags, if reordering these update all #tags[-1] links -->
1583
1583
1584
- Tags are a way to add extra labels or labelled data to transactions, postings, or accounts,
1584
+ Tags are a way to add extra labels or data fields to transactions, postings, or accounts,
1585
1585
which you can then [ search] ( #queries ) or [ pivot] ( #pivoting ) on.
1586
1586
1587
- They are written as a word (optionally hyphenated) immediately followed by a full colon,
1588
- in a transaction or posting or account directive's [ comment] ( #account-comments ) .
1589
- (This is an exception to the usual rule that things in comments are ignored.)
1590
- You can write multiple tags separated by comma, and/or you can add more comment lines
1591
- and write more tags there.
1587
+ A tag is a word, optionally hyphenated, immediately followed by a full colon,
1588
+ in the [ comment] ( #account-comments ) of a transaction, a posting, or an account directive.
1589
+ Eg: ` 2024-01-01 a transaction ; foo: `
1590
+ Note this is an exception to the usual rule that things in comments are ignored.
1592
1591
1593
- Here five different tags are recorded: one on the checking account,
1594
- two on the transaction, and two on the expenses posting:
1592
+ You can write multiple tags on one line, separated by comma.
1593
+ Or you can write each tag on its own comment line (no comma needed in this case).
1594
+
1595
+ For example, here are five different tags:
1596
+ one on the ` assets:checking ` account, two on the transaction, and two on the ` expenses:food ` posting:
1595
1597
1596
1598
``` journal
1597
1599
account assets:checking ; accounttag:
@@ -1602,11 +1604,6 @@ account assets:checking ; accounttag:
1602
1604
expenses:food $1 ; postingtag:, another-posting-tag:
1603
1605
```
1604
1606
1605
- You can list tag names with ` hledger tags [NAMEREGEX] ` ,
1606
- or match by tag name with a ` tag:NAMEREGEX ` query.
1607
-
1608
- ### Tag inheritance
1609
-
1610
1607
Postings also inherit tags from their transaction and their account.
1611
1608
And transactions also acquire tags from their postings (and postings' accounts).
1612
1609
So in the example above, the expenses posting effectively has all five tags
@@ -1615,46 +1612,60 @@ and the transaction also has all five tags (by acquiring from the expenses posti
1615
1612
1616
1613
### Tag names
1617
1614
1618
- Tag names are currently not very clearly specified; any sequence of non-whitespace characters
1619
- followed by a colon may work.
1615
+ Most non-whitespace characters are allowed in tag names. Eg ` 😀: ` is a valid tag.
1620
1616
1621
- The following tag names are generated by hledger or have special significance to hledger,
1622
- so you may want to avoid using them yourself:
1617
+ You can list the tag names used in your journal with the [ tags ] ( #tags ) command: \
1618
+ ` hledger tags [NAMEREGEX] `
1623
1619
1624
- - ` balances ` -- a balance assertions transaction generated by close
1625
- - ` retain ` -- a retain earnings transaction generated by close
1626
- - ` start ` -- a opening balances, closing balances or balance assignment transaction generated by close
1627
- - ` generated-transaction ` -- a transaction generated by --forecast
1628
- - ` generated-posting ` -- a posting generated by --auto
1629
- - ` modified ` -- a transaction which has had postings added by --auto
1630
- - ` type ` -- declares an account's type in an account declaration
1631
- - ` t ` -- stores the (user defined, single letter) type of a 15m unit of time parsed from timedot format
1620
+ In commands which use a [ query] ( #queries ) , you can match by tag name. Eg:\
1621
+ ` hledger print tag:NAMEREGEX `
1632
1622
1633
- Some additional tag names with an underscore prefix are used internally and not displayed
1634
- in reports (but can be matched by queries):
1623
+ You can declare valid tag names with the [ tag directive] ( #tag-directive ) and then check them with the [ check] ( #check ) command.
1635
1624
1636
- - ` _generated-transaction `
1637
- - ` _generated-posting `
1638
- - ` _modified `
1639
- - ` _conversion-matched `
1625
+ ### Special tags
1640
1626
1627
+ Some tag names have special significance to hledger,
1628
+ and could produce an error message if you use them wrongly (the ` date: ` tag in particular).
1629
+ They are explained elsewhere, but here is a list for reference:
1630
+
1631
+ <!-- keep synced with JournalChecks.hs -->
1632
+ ```
1633
+ date -- overrides a posting's date
1634
+ date2 -- overrides a posting's secondary date
1635
+ type -- declares an account's type
1636
+ t -- appears on postings generated by timedot letters
1637
+ assert -- appears on txns generated by close --assert
1638
+ retain -- appears on txns generated by close --retain
1639
+ start -- appears on txns generated by close --migrate/--close/--open/--assign
1640
+ generated-transaction -- with --verbose-tags, appears on generated periodic txns
1641
+ generated-posting -- with --verbose-tags, appears on generated auto postings
1642
+ modified -- with --verbose-tags, appears on txns which have had auto postings added
1643
+
1644
+ Hidden tags used internally (and queryable):
1645
+ _generated-transaction -- always exists on generated periodic txns
1646
+ _generated-posting -- always exists on generated auto postings
1647
+ _modified -- always exists on txns which have had auto postings added
1648
+ _conversion-matched -- exists on postings which have been matched with a nearby @/@@ cost notation
1649
+ ```
1641
1650
1642
1651
### Tag values
1643
1652
1644
- Tags can have a value, which is any text after the colon up until a comma or end of line
1645
- (with surrounding whitespace removed) .
1646
- Note this means that hledger tag values can not contain commas.
1653
+ Tags can have a value, which is any text after the colon up until a comma or end of line, with surrounding whitespace removed.
1654
+ Ending at comma allows us to write multiple tags on one line, but also means that tag values can not contain commas .
1655
+
1647
1656
Eg in the following posting, the three tags' values are "value 1", "value 2", and "" (empty) respectively:
1648
1657
``` journal
1649
1658
expenses:food $10 ; foo, tag1: value 1 , tag2:value 2, bar tag3: , baz
1650
1659
```
1651
1660
1652
- Note that tags can be repeated, and are additive rather than overriding:
1661
+ Multiple tags with the same name are additive rather than overriding:
1653
1662
when the same tag name is seen again with a new value, the new name: value pair is added to the tags.
1654
- (It is not possible to override a tag's value or remove a tag.)
1663
+ It is not possible to override a previous tag's value or remove a tag.
1664
+
1665
+ You can list all the values used for a particular tag in the journal with\
1666
+ ` hledger tags TAGNAME --values `
1655
1667
1656
- You can list a tag's values with ` hledger tags TAGNAME --values ` ,
1657
- or match by tag value with a ` tag:NAMEREGEX=VALUEREGEX ` query.
1668
+ You can match on tag values with a query like ` tag:NAMEREGEX=VALUEREGEX `
1658
1669
1659
1670
## Directives
1660
1671
@@ -2299,7 +2310,7 @@ tag item-id
2299
2310
Any indented subdirectives are currently ignored.
2300
2311
2301
2312
The [ "tags" check] ( #check ) will report an error if any undeclared tag name is used.
2302
- It is quite easy to accidentally create a tag through normal use of colons in [ comments] (#comments] ;
2313
+ It is quite easy to accidentally create a tag through normal use of colons in [ comments] ( #comments ) ;
2303
2314
if you want to prevent this, you can declare and check your tags .
2304
2315
2305
2316
## Periodic transactions
0 commit comments