Skip to content

Commit 6103d74

Browse files
committed
doc:Tags: improve the Special tags list, and the tags doc generally
1 parent baca5f8 commit 6103d74

File tree

1 file changed

+50
-39
lines changed

1 file changed

+50
-39
lines changed

hledger/hledger.m4.md

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,17 +1581,19 @@ except they may contain [tags](#tags), which are not ignored.
15811581

15821582
<!-- same section name as Commands > tags, if reordering these update all #tags[-1] links -->
15831583

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,
15851585
which you can then [search](#queries) or [pivot](#pivoting) on.
15861586

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.
15921591

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:
15951597

15961598
```journal
15971599
account assets:checking ; accounttag:
@@ -1602,11 +1604,6 @@ account assets:checking ; accounttag:
16021604
expenses:food $1 ; postingtag:, another-posting-tag:
16031605
```
16041606

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-
16101607
Postings also inherit tags from their transaction and their account.
16111608
And transactions also acquire tags from their postings (and postings' accounts).
16121609
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
16151612

16161613
### Tag names
16171614

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.
16201616

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]`
16231619

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`
16321622

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.
16351624

1636-
- `_generated-transaction`
1637-
- `_generated-posting`
1638-
- `_modified`
1639-
- `_conversion-matched`
1625+
### Special tags
16401626

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+
```
16411650

16421651
### Tag values
16431652

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+
16471656
Eg in the following posting, the three tags' values are "value 1", "value 2", and "" (empty) respectively:
16481657
```journal
16491658
expenses:food $10 ; foo, tag1: value 1 , tag2:value 2, bar tag3: , baz
16501659
```
16511660

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:
16531662
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`
16551667

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`
16581669

16591670
## Directives
16601671

@@ -2299,7 +2310,7 @@ tag item-id
22992310
Any indented subdirectives are currently ignored.
23002311

23012312
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);
23032314
if you want to prevent this, you can declare and check your tags .
23042315

23052316
## Periodic transactions

0 commit comments

Comments
 (0)