diff options
author | thdox <thdox@free.fr> | 2013-04-27 14:48:43 +0200 |
---|---|---|
committer | thdox <thdox@free.fr> | 2013-04-27 14:48:43 +0200 |
commit | a7f1a434028fb2600dd75f8fe00dd0ace522ce1b (patch) | |
tree | 142e17c862ca4933c5375467a09e38156a94654d /doc | |
parent | 9219c59533e89d314e747217b95e1197df20248e (diff) | |
download | fork-ledger-a7f1a434028fb2600dd75f8fe00dd0ace522ce1b.tar.gz fork-ledger-a7f1a434028fb2600dd75f8fe00dd0ace522ce1b.tar.bz2 fork-ledger-a7f1a434028fb2600dd75f8fe00dd0ace522ce1b.zip |
Fill paragraph with alignment on 70th column
Diffstat (limited to 'doc')
-rw-r--r-- | doc/ledger3.texi | 2340 |
1 files changed, 1277 insertions, 1063 deletions
diff --git a/doc/ledger3.texi b/doc/ledger3.texi index 76000988..f0ed4619 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -128,9 +128,9 @@ all accounting, and if you haven't started yet, now is the time to learn. The little booklet that comes with your checkbook is a journal, so we'll describe double-entry accounting in terms of that. -@c If you use -@c another GUI accounting program like GnuCash, the vast majority of its -@c functionality is geared towards helping you keep a journal. +@c If you use another GUI accounting program like GnuCash, the vast +@c majority of its functionality is geared towards helping you keep +@c a journal. A checkbook journal records debits (subtractions, or withdrawals) and credits (additions, or deposits) with reference to a single account: @@ -150,12 +150,12 @@ about your life and habits, and sometimes that information can start telling you things you aren't aware of. Such is the aim of all good accounting tools. -The next step up from a checkbook journal, is a journal that keeps track -of all your accounts, not just checking. In such a journal, you record -not only who gets paid---in the case of a debit---but where the money -came from. In a checkbook journal, its assumed that all the money -comes from your checking account. But in a general journal, you write -posting two-lines: the source account and target account. +The next step up from a checkbook journal, is a journal that keeps +track of all your accounts, not just checking. In such a journal, you +record not only who gets paid---in the case of a debit---but where the +money came from. In a checkbook journal, its assumed that all the +money comes from your checking account. But in a general journal, you +write posting two-lines: the source account and target account. @emph{There must always be a debit from at least one account for every credit made to another account}. This is what is meant by ``double-entry'' accounting: the journal must always balance to zero, @@ -164,13 +164,13 @@ with an equal number of debits and credits. For example, let's say you have a checking account and a brokerage account, and you can write checks from both of them. Rather than keep -two checkbooks, you decide to use one journal for both. In this general -journal you need to record a payment to Pacific Bell for your monthly -phone bill, and a transfer (via check) from your brokerage account to -your checking account. The Pacific Bell bill is $23.00, let's say, and -you want to pay it from your checking account. In the general journal -you need to say where the money came from, in addition to where it's -going to. These transactions might look like this: +two checkbooks, you decide to use one journal for both. In this +general journal you need to record a payment to Pacific Bell for your +monthly phone bill, and a transfer (via check) from your brokerage +account to your checking account. The Pacific Bell bill is $23.00, +let's say, and you want to pay it from your checking account. In the +general journal you need to say where the money came from, in addition +to where it's going to. These transactions might look like this: @smallexample 9/29 Pacific Bell $23.00 $23.00 @@ -179,13 +179,13 @@ going to. These transactions might look like this: (123) Brokerage $-100.00 0 @end smallexample -The posting must balance to $0: $23 went to Pacific Bell, $23 came from -Checking. The next entry shows check number 123 written against your -brokerage account, transferring money to your checking account. There is -nothing left over to be accounted for, since the money has simply moved -from one account to another in both cases. This is the basis of -double-entry accounting: money never pops in or out of existence; it is -always a posting from one account to another. +The posting must balance to $0: $23 went to Pacific Bell, $23 came +from Checking. The next entry shows check number 123 written against +your brokerage account, transferring money to your checking account. +There is nothing left over to be accounted for, since the money has +simply moved from one account to another in both cases. This is the +basis of double-entry accounting: money never pops in or out of +existence; it is always a posting from one account to another. Keeping a general journal is the same as keeping two separate journals: One for Pacific Bell and one for Checking. In that case, each time a @@ -198,12 +198,13 @@ deal with multiple accounts. @cindex account, meaning of @cindex meaning of account Here is a good place for an aside on the use of the word `account'. -Most private people consider an account to be something that holds money -at an institution for them. Ledger uses a more general definition -of the word. An account is anywhere money can go. Other finance -programs use ``categories'', Ledger uses accounts. So, for +Most private people consider an account to be something that holds +money at an institution for them. Ledger uses a more general +definition of the word. An account is anywhere money can go. Other +finance programs use ``categories'', Ledger uses accounts. So, for example, if you buy some groceries at Trader Joe's then more groceries at Whole Foods Markets you might assign the transactions like this + @smallexample 2011/03/15 Trader Joe's Expenses:Groceries $100.00 @@ -212,24 +213,25 @@ at Whole Foods Markets you might assign the transactions like this Expenses:Groceries $75.00 Assets:Checking @end smallexample + In both cases the money goes to the ``Groceries'' account, even though the payees were different. You can set up your accounts in any way you choose. Enter the beauty of computerized accounting. The purpose of the -Ledger program is to make general journal accounting simple, by keeping -track of the balances for you. Your only job is to enter the -postings. If an individual posting does not balance, Ledger displays an -error and indicates the incorrect posting.@footnote{In some -special cases, it automatically balances this transaction for you.} +Ledger program is to make general journal accounting simple, by +keeping track of the balances for you. Your only job is to enter the +postings. If an individual posting does not balance, Ledger displays +an error and indicates the incorrect posting.@footnote{In some special +cases, it automatically balances this transaction for you.} In summary, there are two aspects of Ledger use: updating the journal data file, and using the Ledger tool to view the summarized result of your transactions. And just for the sake of example---as a starting point for those who -want to dive in head-first---here are the journal transactions from above, -formatted as the Ledger program wishes to see them: +want to dive in head-first---here are the journal transactions from +above, formatted as the Ledger program wishes to see them: @smallexample 2004/09/29 Pacific Bell @@ -256,9 +258,9 @@ data, not for altering it. @section Building the program Ledger is written in ANSI C++, and should compile on any platform. It -depends on the GNU multiple precision arithmetic library (libgmp), and the -Perl regular expression library (libpcre). It was developed using GNU -make and gcc 3.3, on a PowerBook running OS/X. +depends on the GNU multiple precision arithmetic library (libgmp), and +the Perl regular expression library (libpcre). It was developed using +GNU make and gcc 3.3, on a PowerBook running OS/X. To build and install once you have these libraries on your system, enter these commands: @@ -271,13 +273,14 @@ enter these commands: @node Getting Help, , Building the Program, Introduction to Ledger @section Getting help -Ledger has a complete online help system based on GNU Info. This manual -can be searched directly from the command line using the following -options: -@code{ledger --help} bring up this entire manual in your tty. +Ledger has a complete online help system based on GNU Info. This +manual can be searched directly from the command line using the +following options: @code{ledger --help} bring up this entire manual in +your tty. If you need help on how to use Ledger, or run into problems, you can -join the Ledger mailing list at @url{http://groups.google.com/group/ledger-cli}. +join the Ledger mailing list at +@url{http://groups.google.com/group/ledger-cli}. You can also find help at the @code{#ledger} channel on the IRC server @code{irc.freenode.net}. @@ -295,14 +298,15 @@ You can also find help at the @code{#ledger} channel on the IRC server @section Start a Journal File @cindex journals -A journal is a record of your financial transactions and will be central -to using Ledger. For now we just want to get a taste of what Ledger can -do. An example journal is included with the source code distribution, -called @file{drewr3.dat} (@pxref{Example Data File}). +A journal is a record of your financial transactions and will be +central to using Ledger. For now we just want to get a taste of what +Ledger can do. An example journal is included with the source code +distribution, called @file{drewr3.dat} (@pxref{Example Data File}). Copy it someplace convenient and open up a terminal window in that directory. -If you would rather start with your own journal right away please see @ref{Keeping a Journal}. +If you would rather start with your own journal right away please +@pxref{Keeping a Journal}. @node Run Some Reports, , Start a Journal, Ledger Tutorial @section Run a Few Reports @@ -315,14 +319,14 @@ If you would rather start with your own journal right away please see @ref{Keepi @end menu Please note that as a command line program, Ledger is controlled from -your shell. There are several different command shells that all behave -slightly differently with respect to some special characters. In -particular, the BASH shell will interpret $ signs differently than +your shell. There are several different command shells that all +behave slightly differently with respect to some special characters. +In particular, the BASH shell will interpret $ signs differently than ledger and they must be escaped to reach the actual program. Another -example is zsh, which will interpret ^ differently than ledger expects. -In all cases that follow you should take that into account when entering -the command line arguments given. There are too many variations between -shells to give concrete examples for each. +example is zsh, which will interpret ^ differently than ledger +expects. In all cases that follow you should take that into account +when entering the command line arguments given. There are too many +variations between shells to give concrete examples for each. @node Balance Report, Register Report, Run Some Reports, Run Some Reports @subsection Balance Report @@ -360,8 +364,9 @@ Ledger will generate: $ -243.60 @end smallexample -@noindent Showing you the balance of all accounts. Options and search terms can pare -this down to show only the accounts you want. +@noindent +Showing you the balance of all accounts. Options and search terms can +pare this down to show only the accounts you want. A more useful report is to show only your Assets and Liabilities: @@ -390,7 +395,8 @@ To show all transactions and a running total: ledger -f drewr3.dat register @end smallexample -@noindent Ledger will generate: +@noindent +Ledger will generate: @smallexample 10-Dec-01 Checking balance Assets:Checking $ 1,000.00 $ 1,000.00 @@ -426,9 +432,12 @@ ledger -f drewr3.dat register (Liabilities:Tithe) $ -3.60 $ -243.60 @end smallexample -@noindent To limit this to a more useful subset, simply add the accounts you are interested in seeing transactions for: +@noindent +To limit this to a more useful subset, simply add the accounts you are +interested in seeing transactions for: @cindex accounts, limiting by @cindex limiting by accounts + @smallexample $ ledger -f drewr3.dat register Groceries 10-Dec-20 Organic Co-op Expense:Food:Groceries $ 37.50 $ 37.50 @@ -441,14 +450,18 @@ $ ledger -f drewr3.dat register Groceries 11-Jan-19 Grocery Store Expense:Food:Groceries $ 44.00 $ 334.00 @end smallexample -@noindent Which matches the balance reported for the @code{Groceries} account: +@noindent +Which matches the balance reported for the @code{Groceries} account: @smallexample $ ledger -f drewr3.dat balance Groceries $ 334.00 Expenses:Food:Groceries @end smallexample -@noindent If you would like to find transaction to only a certain payee use @code{payee} or @@: +@noindent +If you would like to find transaction to only a certain payee use +@code{payee} or @@: + @smallexample $ ledger -f drewr3.dat register payee "Organic" 10-Dec-20 Organic Co-op Expense:Food:Groceries $ 37.50 $ 37.50 @@ -466,10 +479,11 @@ $ ledger -f drewr3.dat register payee "Organic" @findex cleared A very useful report is to show what your obligations are versus what -expenditures have actually been recorded. It can take several days for -a check to clear, but you should treat it as money spent. The -@code{cleared} report shows just that (note that the cleared report will -not format correctly for accounts that contain multiple commodities): +expenditures have actually been recorded. It can take several days +for a check to clear, but you should treat it as money spent. The +@code{cleared} report shows just that (note that the cleared report +will not format correctly for accounts that contain multiple +commodities): @smallexample $ ledger -f drewr3.dat cleared @@ -495,15 +509,18 @@ $ ledger -f drewr3.dat cleared $ -243.60 0 @end smallexample -@noindent The first column shows the outstanding balance, the second column shows the ``cleared'' balance. +@noindent +The first column shows the outstanding balance, the second column +shows the ``cleared'' balance. + @node Using the Windows command line, , Cleared Report, Run Some Reports @subsection Using the Windows Command Line @cindex windows cmd.exe @cindex currency symbol display on windows Using ledger under the windows command shell has one significant -limitation. CMD.exe is limited to standard ASCII characters and as such -cannot display any currency symbols other than dollar signs ($). +limitation. CMD.exe is limited to standard ASCII characters and as +such cannot display any currency symbols other than dollar signs ($). @node Principles of Accounting, Keeping a Journal, Ledger Tutorial, Top @@ -525,10 +542,10 @@ cannot display any currency symbols other than dollar signs ($). @section Accounting with Ledger Accounting is simply tracking your money. It can range from nothing, -and just waiting for automatic overdraft protection to kick in, or not, -to a full blown double entry accounting system. Ledger accomplishes the -latter. With ledger you can handle your personal finances or your -businesses. Double-entry accounting scales. +and just waiting for automatic overdraft protection to kick in, or +not, to a full blown double entry accounting system. Ledger +accomplishes the latter. With ledger you can handle your personal +finances or your businesses. Double-entry accounting scales. @cindex double-entry accounting @node Stating where money goes, Assets and Liabilities, Accounting with Ledger, Principles of Accounting @@ -545,10 +562,10 @@ Money is transferred from one or more accounts to one or more other accounts. To record the posting, an amount is @emph{subtracted} from the source accounts, and @emph{added} to the target accounts. -In order to write a Ledger transaction correctly, you must determine where -the money comes from and where it goes to. For example, when you are -paid a salary, you must add money to your bank account and also -subtract it from an income account: +In order to write a Ledger transaction correctly, you must determine +where the money comes from and where it goes to. For example, when +you are paid a salary, you must add money to your bank account and +also subtract it from an income account: @smallexample 9/29 My Employer @@ -711,10 +728,10 @@ personal transaction, which shows the need for reimbursement: @end smallexample This is the same as above, except that you own Company XYZ, and are -keeping track of its expenses in the same ledger file. This transaction -should be immediately followed by an equivalent transaction, which shows the -kind of expense, and also notes the fact that $100.00 is now payable -to you: +keeping track of its expenses in the same ledger file. This +transaction should be immediately followed by an equivalent +transaction, which shows the kind of expense, and also notes the fact +that $100.00 is now payable to you: @smallexample 2004/09/29 Circuit City @@ -722,12 +739,12 @@ to you: Company XYZ:Accounts Payable:Your Name @end smallexample -This second transaction shows that Company XYZ has just spent $100.00 on -software, and that this $100.00 came from Your Name, which must be +This second transaction shows that Company XYZ has just spent $100.00 +on software, and that this $100.00 came from Your Name, which must be paid back. -These two transactions can also be merged, to make things a little clearer. -Note that all amounts must be specified now: +These two transactions can also be merged, to make things a little +clearer. Note that all amounts must be specified now: @smallexample 2004/09/29 Circuit City @@ -768,10 +785,10 @@ gives you a very accurate information trail. The advantage to keep these doubled transactions together is that they always stay in sync. The advantage to keeping them apart is that it clarifies the transfer's point of view. To keep the postings in -separate files, just separate the two transactions that were joined above. -For example, for both the expense and the pay-back shown above, the -following four transactions would be created. Two in your personal ledger -file: +separate files, just separate the two transactions that were joined +above. For example, for both the expense and the pay-back shown +above, the following four transactions would be created. Two in your +personal ledger file: @smallexample 2004/09/29 Circuit City @@ -799,14 +816,14 @@ apply account Company XYZ end apply account @end smallexample -(Note: The @code{apply account} above means that all accounts mentioned in -the file are children of that account. In this case it means that all -activity in the file relates to Company XYZ). +(Note: The @code{apply account} above means that all accounts +mentioned in the file are children of that account. In this case it +means that all activity in the file relates to Company XYZ). -After creating these transactions, you will always know that $100.00 was -spent using your MasterCard on behalf of Company XYZ, and that Company -XYZ spent the money on computer software and paid it back about two -weeks later. +After creating these transactions, you will always know that $100.00 +was spent using your MasterCard on behalf of Company XYZ, and that +Company XYZ spent the money on computer software and paid it back +about two weeks later. @node Commodities and Currencies, Accounts and Inventories, Assets and Liabilities, Principles of Accounting @section Commodities and Currencies @@ -1007,8 +1024,8 @@ acquired them online. The only purpose for choosing one kind of source account over another is for generate more informative reports later on. The more you know, the better analysis you can perform. -If you later sell some of these items to another player, the transaction -would look like: +If you later sell some of these items to another player, the +transaction would look like: @smallexample 10/2 Sturm Brightblade @@ -1022,8 +1039,8 @@ Sturm Brightblade. @node Understanding Equity, Dealing with Petty Cash, Accounts and Inventories, Principles of Accounting @section Understanding Equity -The most confusing transaction in any ledger will be your equity account--- -because starting balances can't come out of nowhere. +The most confusing transaction in any ledger will be your equity +account---because starting balances can't come out of nowhere. When you first start your ledger, you will likely already have money in some of your accounts. Let's say there's $100 in your checking @@ -1222,17 +1239,18 @@ ledger --code-as-payee -P reg ^Expenses @@School Both approaches yield different kinds of flexibility, depending on how you prefer to think of your funds: as virtual accounts, or as tags -associated with particular transactions. Your own tastes will decide which -is best for your situation. +associated with particular transactions. Your own tastes will decide +which is best for your situation. @node Keeping a Journal, Transactions, Principles of Accounting, Top @chapter Keeping a Journal -The most important part of accounting is keeping a good journal. If you -have a good journal, tools can be written to work whatever mathematical -tricks you need to better understand your spending patterns. Without a -good journal, no tool, however smart, can help you. +The most important part of accounting is keeping a good journal. If +you have a good journal, tools can be written to work whatever +mathematical tricks you need to better understand your spending +patterns. Without a good journal, no tool, however smart, can help +you. The Ledger program aims at making journal transactions as simple as possible. Since it is a command-line tool, it does not provide a user @@ -1242,8 +1260,8 @@ GnuCash's data files directly. In that case, read the GnuCash manual now, and skip to the next chapter. If you are not using GnuCash, but a text editor to maintain your -journal, read on. Ledger has been designed to make data transactions as -simple as possible, by keeping the journal format easy, and also by +journal, read on. Ledger has been designed to make data transactions +as simple as possible, by keeping the journal format easy, and also by automagically determining as much information as possible based on the nature of your transactions. @@ -1283,10 +1301,10 @@ posting, with the additional of a check number: @end smallexample As you can see, it is very similar to what would be written on paper, -minus the computed balance totals, and adding in account names that work -better with Ledger's scheme of things. In fact, since -Ledger is smart about many things, you don't need to specify the -balanced amount, if it is the same as the first line: +minus the computed balance totals, and adding in account names that +work better with Ledger's scheme of things. In fact, since Ledger is +smart about many things, you don't need to specify the balanced +amount, if it is the same as the first line: @smallexample 9/29 (1023) Pacific Bell @@ -1294,8 +1312,8 @@ balanced amount, if it is the same as the first line: Assets:Checking @end smallexample -For this transaction, Ledger will figure out that $-23.00 must come from -@code{Assets:Checking} in order to balance the transaction. +For this transaction, Ledger will figure out that $-23.00 must come +from @code{Assets:Checking} in order to balance the transaction. Also note the structure of the account entries. There is an implied hierarchy established by separating with colons (@pxref{Structuring @@ -1305,14 +1323,14 @@ Your Accounts}). @cindex spaces in postings @cindex posting format details @strong{The format is very flexible and it isn't necessary that you -indent and space out things exactly as shown. The only requirements are -that the start of the transaction (the date typically) is at the +indent and space out things exactly as shown. The only requirements +are that the start of the transaction (the date typically) is at the beginning of the first line of the transaction, and the accounts are indented by at least one space. If you omit the leading spaces in the -account lines Ledger will generate an error. There must be at least two -spaces, or a tab, between the amount and the account. If you do not -have adequate separation between the amount and the account Ledger will -give an error and stop calculating.} +account lines Ledger will generate an error. There must be at least +two spaces, or a tab, between the amount and the account. If you do +not have adequate separation between the amount and the account Ledger +will give an error and stop calculating.} @node Starting up, Structuring Your Accounts, Most Basic Entry, Keeping a Journal @@ -1320,8 +1338,8 @@ give an error and stop calculating.} @cindex initial equity @cindex beginning ledger -Unless you have recently arrived from another planet, you already have a -financial state. You need to capture that financial state so that +Unless you have recently arrived from another planet, you already have +a financial state. You need to capture that financial state so that Ledger has a starting point. At some convenient point in time you knew the balances and outstanding @@ -1376,8 +1394,9 @@ Starting the structure off this way will make it simpler for you to get answers to the questions you really need to ask about your finances. Beneath these top level accounts you can have any level of detail you -desire. For example, if you want to keep specific track of how much you spend on -burgers and fries, you could have the following: +desire. For example, if you want to keep specific track of how much +you spend on burgers and fries, you could have the following: + @smallexample Expenses:Food:Hamburgers and Fries @end smallexample @@ -1388,12 +1407,13 @@ Expenses:Food:Hamburgers and Fries @cindex comments, characters Comments are generally started using a ';'. However, in order to -increase compatibility with other text manipulation programs and methods -four additional comment characters are valid if used at the beginning -of a line: @code{#}, @code{|}, and @code{*} and @code{%}. +increase compatibility with other text manipulation programs and +methods four additional comment characters are valid if used at the +beginning of a line: @code{#}, @code{|}, and @code{*} and @code{%}. @cindex block comments @cindex comments, block -Block comments can be made by use @code{@!comment} ... @code{@!end comment} +Block comments can be made by use @code{@!comment} ... @code{@!end +comment} @smallexample @@ -1423,10 +1443,11 @@ There are several forms of comments within a transaction, for example: Assets:Credit Union:Checking @end smallexample -@noindent The first comment is global and Ledger will not attach it to any specific -transactions. The comments within the transaction must all start with `;'s and are -preserved as part of the transaction. The `:'s indicate meta-data and tags -(@pxref{Metadata}). +@noindent +The first comment is global and Ledger will not attach it to any +specific transactions. The comments within the transaction must all +start with `;'s and are preserved as part of the transaction. The +`:'s indicate meta-data and tags (@pxref{Metadata}). @node Currency and Commodities, Keeping it Consistent, Commenting on your journal, Keeping a Journal @section Currency and Commodities @@ -1435,11 +1456,11 @@ preserved as part of the transaction. The `:'s indicate meta-data and tags Ledger is agnostic when it comes to how you value your accounts. Dollars, Euros, Pounds, Francs, Shares etc. are just ``commodities''. -Holdings in stocks, bonds, mutual funds and other financial instruments -can be labeled using whatever is convenient for you (stock ticker -symbols are suggested for publicly traded assets).@footnote{you can -track @emph{anything}, even time or distance traveled. As long as it cannot be -created or destroyed inside your accounting system.} +Holdings in stocks, bonds, mutual funds and other financial +instruments can be labeled using whatever is convenient for you (stock +ticker symbols are suggested for publicly traded assets).@footnote{You +can track @emph{anything}, even time or distance traveled. As long as +it cannot be created or destroyed inside your accounting system.} For the rest of this manual, we will only use the word ``commodities'' when referring to the units on a transaction value. @@ -1447,12 +1468,13 @@ when referring to the units on a transaction value. This is fundamentally different than many common accounting packages, which assume the same currency throughout all of your accounts. This means if you typically operate in Euros, but travel to the US and have -some expenses, you would have to do the currency conversion @emph{before} you -made the entry into your financial system. With ledger this is not -required. In the same journal you can have entries in any or all -commodities you actually hold. You can use the reporting capabilities -to convert all commodities to a single commodity for reporting purposes -without ever changing the underlying entry. +some expenses, you would have to do the currency conversion +@emph{before} you made the entry into your financial system. With +ledger this is not required. In the same journal you can have entries +in any or all commodities you actually hold. You can use the +reporting capabilities to convert all commodities to a single +commodity for reporting purposes without ever changing the underlying +entry. For example, the following entries reflect transaction made for a business trip to Europe from the US: @@ -1467,9 +1489,9 @@ business trip to Europe from the US: Assets:Cash @end smallexample -This says that $66.00 came out of checking and turned into 50 Euros. The -implied exchange rate was $1.32. Then 35.00 Euros was spent on Dinner -in Munich. +This says that $66.00 came out of checking and turned into 50 +Euros. The implied exchange rate was $1.32. Then 35.00 Euros was +spent on Dinner in Munich. Running a ledger balance report shows: @smallexample @@ -1484,11 +1506,11 @@ $ ledger -f example.dat bal E50.00 @end smallexample -The top two lines show my current assets as $-66.00 in checking (in this -very short example I didn't establish opening an opening balance for the -checking account) and E15.00. After spending on dinner i have E15.00 in -my wallet. The bottom line balances to zero, but is shown in two lines -since we haven't told ledger to convert commodities. +The top two lines show my current assets as $-66.00 in checking (in +this very short example I didn't establish opening an opening balance +for the checking account) and E15.00. After spending on dinner i have +E15.00 in my wallet. The bottom line balances to zero, but is shown +in two lines since we haven't told ledger to convert commodities. @menu * Naming Commodities:: @@ -1500,9 +1522,10 @@ since we haven't told ledger to convert commodities. @node Naming Commodities, Buying and Selling Stock, Currency and Commodities, Currency and Commodities @subsection Naming Commodities -Commodity names can have any character, including white-space. However, -if you include white-space or numeric characters the commodity name must -be enclosed in double quotes: +Commodity names can have any character, including white-space. +However, if you include white-space or numeric characters the +commodity name must be enclosed in double quotes: + @smallexample 1999/06/09 ! Achat Actif:SG PEE STK 49.957 "Arcancia Equilibre 454" @@ -1521,8 +1544,9 @@ be enclosed in double quotes: Buying stock is a typical example that many will use that involves multiple commodities in the same transaction. The type of the share -(AAPL for Apple Inc.) and the share purchase price in the currency unit -you made the purchase in ($ for AAPL). Yes, the typical convention is as follows: +(AAPL for Apple Inc.) and the share purchase price in the currency +unit you made the purchase in ($ for AAPL). Yes, the typical +convention is as follows: @smallexample 2004/05/01 Stock purchase @@ -1540,7 +1564,8 @@ both liquid and commodity assets. Now, on the day of the sale: Assets:Broker $2,500.00 @end smallexample -@noindent You can, of course, elide the amount of the last posting. It is there +@noindent +You can, of course, elide the amount of the last posting. It is there for clarity's sake. The @{$30.00@} is a lot price. You can also use a lot date, @@ -1552,11 +1577,11 @@ price/date and your taxation model is based on longest-held-first. @cindex fixing lot prices @cindex consumable commodity pricing -Commodities that you keep in order to sell them at a later time have a -variable value that fluctuates with the market prices. Commodities that -you consume should not fluctuate in value, but stay at the lot price -they were purchased at. As an extension of ``lot pricing'', you can fix -the per-unit price of a commodity. +Commodities that you keep in order to sell them at a later time have +a variable value that fluctuates with the market prices. Commodities +that you consume should not fluctuate in value, but stay at the lot +price they were purchased at. As an extension of ``lot pricing'', you +can fix the per-unit price of a commodity. For example, say you buy 10 gallons of gas at $1.20. In future ``value'' reports, you don't want these gallons reported in terms of @@ -1597,10 +1622,10 @@ both exist, you ask? To support things like this: @end smallexample This transaction says that you bought 11 gallons priced at $2.299 per -gallon at a @strong{cost to you} of $2.30 per gallon. Ledger auto-generates -a balance posting in this case to Equity:Capital Losses to reflect the -1.1 cent difference, which is then balanced by Assets:Checking because -its amount is null. +gallon at a @strong{cost to you} of $2.30 per gallon. Ledger +auto-generates a balance posting in this case to Equity:Capital Losses +to reflect the 1.1 cent difference, which is then balanced by +Assets:Checking because its amount is null. @node Complete control over commodity pricing, , Fixing Lot Prices, Currency and Commodities @subsection Complete control over commodity pricing @@ -1619,35 +1644,39 @@ points of interception, you can specify the valuation method: @item by changing the journal default of @code{market} @end enumerate -Fixated pricing (such as @code{@{=$20@})} still plays a role in this scheme. As far as -valuation goes, it's shorthand for writing @code{((s,d,t -> market($20,d,t)))}. +Fixated pricing (such as @code{@{=$20@})} still plays a role in this +scheme. As far as valuation goes, it's shorthand for writing +@code{((s,d,t -> market($20,d,t)))}. A valuation function receives three arguments: @table @code @item source - A string identifying the commodity whose price is being asked for +A string identifying the commodity whose price is being asked for (example: "EUR") @item date - The reference date the price should be relative. +The reference date the price should be relative. + @item target A string identifying the ``target'' commodity, or the commodity the - returned price should be in. This argument is null if @code{--market} - was used instead of @code{--exchange}. + returned price should be in. This argument is null if + @code{--market} was used instead of @code{--exchange}. @end table -The valuation function should return an amount. If you've written your -function in Python, you can return something like @code{Amount("$100")}. If the -function returns an explicit value, that value is always used, regardless -of the commodity, the date, or the desired target commodity. For example, +The valuation function should return an amount. If you've written +your function in Python, you can return something like +@code{Amount("$100")}. If the function returns an explicit value, +that value is always used, regardless of the commodity, the date, or +the desired target commodity. For example, @smallexample define myfunc_seven(s, d, t) = 7 EUR @end smallexample -In order to specify a fixed price, but still valuate that price into the -target commodity, use something like this: +In order to specify a fixed price, but still valuate that price into +the target commodity, use something like this: + @smallexample define myfunc_five(s, d, t) = market(5 EUR, d, t) @end smallexample @@ -1655,12 +1684,14 @@ define myfunc_five(s, d, t) = market(5 EUR, d, t) The @code{value} directive sets the valuation used for all commodities used in the rest of the data stream. This is the fallback, if nothing more specific is found. + @smallexample value myfunc_seven @end smallexample You can set a specific valuation function on a per-commodity basis. Instead of defining a function, you can also pass a lambda. + @smallexample commodity $ value s, d, t -> 6 EUR @@ -1674,8 +1705,8 @@ account Expenses:Food5 value myfunc_five @end smallexample -The metadata field @code{Value}, if found, overrides the valuation function -on a transaction-wide or per-posting basis. +The metadata field @code{Value}, if found, overrides the valuation +function on a transaction-wide or per-posting basis. @smallexample = @@XACT and Food @@ -1753,14 +1784,18 @@ data, but also easy to enter accounts or payees inconsistently or with spelling errors. In order to combat inconsistency you can define allowable accounts and -or payees. For simplicity, create a separate text file and enter define -accounts a payees like +or payees. For simplicity, create a separate text file and enter +define accounts a payees like + @smallexample account Expenses account Expenses:Utilities ... @end smallexample -Using the @code{--strict} option will cause Ledger to complain if any accounts are not previously defined: + +Using the @code{--strict} option will cause Ledger to complain if any +accounts are not previously defined: + @smallexample 15:27:39 ~/ledger (next) > ledger bal --strict Warning: "FinanceData/Master.dat", line 6: Unknown account 'Liabilities:Tithe Owed' @@ -1768,12 +1803,15 @@ Warning: "FinanceData/Master.dat", line 8: Unknown account 'Liabilities:Tithe Ow Warning: "FinanceData/Master.dat", line 15: Unknown account 'Allocation:Equities:Domestic' @end smallexample -If you have a large Ledger register already created use the @code{accounts} command to get started: +If you have a large Ledger register already created use the +@code{accounts} command to get started: + @smallexample ledger accounts >> Accounts.dat @end smallexample -@noindent You will have to edit this file to add the @code{account} directive. +@noindent +You will have to edit this file to add the @code{account} directive. @node Journal Format, Converting from other formats, Keeping it Consistent, Keeping a Journal @section Journal Format @@ -1795,22 +1833,23 @@ how it should be interpreted. Allowable initial characters are: @table @code @item NUMBER -A line beginning with a number denotes a transaction. It may be followed -by any number of lines, each beginning with white-space, to denote the -transaction's account postings. The format of the first line is: +A line beginning with a number denotes a transaction. It may be +followed by any number of lines, each beginning with white-space, to +denote the transaction's account postings. The format of the first +line is: @smallexample DATE[=EDATE] [*|!] [(CODE)] DESC @end smallexample If @code{*} appears after the date (with optional effective date), it -indicates the transaction is ``cleared'', which can mean whatever the user -wants it to mean. If @code{!} appears after the date, it indicates d -the transaction is ``pending''; i.e., tentatively cleared from the user's -point of view, but not yet actually cleared. If a @code{CODE} appears -in parentheses, it may be used to indicate a check number, or the type -of the posting. Following these is the payee, or a description of -the posting. +indicates the transaction is ``cleared'', which can mean whatever the +user wants it to mean. If @code{!} appears after the date, it +indicates d the transaction is ``pending''; i.e., tentatively cleared +from the user's point of view, but not yet actually cleared. If +a @code{CODE} appears in parentheses, it may be used to indicate +a check number, or the type of the posting. Following these is the +payee, or a description of the posting. The format of each following posting is: @@ -1836,13 +1875,14 @@ P DATE SYMBOL PRICE @end smallexample @item = -An automated transaction. A value expression must appear after the equal -sign. +An automated transaction. A value expression must appear after the +equal sign. -After this initial line there should be a set of one or more -postings, just as if it were normal transaction. If the amounts of the -postings have no commodity, they will be applied as modifiers to -whichever real posting is matched by the value expression (@pxref{Automated Transactions}). +After this initial line there should be a set of one or more postings, +just as if it were normal transaction. If the amounts of the postings +have no commodity, they will be applied as modifiers to whichever real +posting is matched by the value expression (@pxref{Automated +Transactions}). @item ~ A period transaction. A period expression must appear after the tilde. @@ -1851,9 +1891,9 @@ After this initial line there should be a set of one or more postings, just as if it were normal transaction. @item ; # % | * -A line beginning with a colon, pound, percent, bar or asterisk indicates -a comment, and is ignored. Comments will not be returned in a ``print'' -response. +A line beginning with a colon, pound, percent, bar or asterisk +indicates a comment, and is ignored. Comments will not be returned in +a ``print'' response. @item indented ; If the semi colon is indented and occurs inside a transaction, it is parsed as a persistent note for its preceding category. These notes or @@ -1888,16 +1928,18 @@ whitespace: default @end smallexample -The @code{note} sub-directive associates a textual note with the account. This can -be accessed later using the @code{note} valexpr function in any account context. +The @code{note} sub-directive associates a textual note with the +account. This can be accessed later using the @code{note} valexpr +function in any account context. -The @code{alias} sub-directive, which can occur multiple times, allows the alias to -be used in place of the full account name anywhere that account names are -allowed. +The @code{alias} sub-directive, which can occur multiple times, allows +the alias to be used in place of the full account name anywhere that +account names are allowed. -The @code{payee} sub-directive, which can occur multiple times, provides regexps -that identify the account if that payee is encountered and an account within -its transaction ends in the name "Unknown". Example: +The @code{payee} sub-directive, which can occur multiple times, +provides regexps that identify the account if that payee is +encountered and an account within its transaction ends in the name +"Unknown". Example: @smallexample 2012-02-27 KFC @@ -1905,26 +1947,28 @@ its transaction ends in the name "Unknown". Example: Assets:Cash @end smallexample -The @code{check} and @code{assert} directives warn or error (respectively) if the given -value expression evaluates to false within the context of any posting. +The @code{check} and @code{assert} directives warn or error +(respectively) if the given value expression evaluates to false within +the context of any posting. -The @code{eval} directive evaluates the value expression in the context of the -account at the time of definition. At the moment this has little value. +The @code{eval} directive evaluates the value expression in the +context of the account at the time of definition. At the moment this +has little value. -The @code{default} directive specifies that this account should be used as the -``balancing account'' for any future transactions that contain only a single -posting. +The @code{default} directive specifies that this account should be +used as the ``balancing account'' for any future transactions that +contain only a single posting. @item apply account @c instance_t::master_account_directive -Sets the root for all accounts following the directive. Ledger supports -a hierarchical tree of accounts. It may be convenient to keep two -``root accounts''. For example you may be tracking your personal -finances and your business finances. In order to keep them separate you -could preface all personal accounts with @code{personal:} and all -business account with @code{business:}. You can easily split out large -groups of transaction without manually editing them using the account -directive. For example: +Sets the root for all accounts following the directive. Ledger +supports a hierarchical tree of accounts. It may be convenient to +keep two ``root accounts''. For example you may be tracking your +personal finances and your business finances. In order to keep them +separate you could preface all personal accounts with @code{personal:} +and all business account with @code{business:}. You can easily split +out large groups of transaction without manually editing them using +the account directive. For example: @smallexample apply account Personal @@ -1957,27 +2001,25 @@ is defined and are effected by @code{account} directives that precede them. @item assert @c instance_t::assert_directive -An assertion can throw an error if a condition is not met during Ledger's run. +An assertion can throw an error if a condition is not met during +Ledger's run. @smallexample - assert <VALUE EXPRESSION BOOLEAN RESULT> - @end smallexample - @item bucket @c instance_t::default_account_directive Defines the default account to use for balancing transactions. -Normally, each transaction has at least two postings, which must balance -to zero. Ledger allows you to leave one posting with no amount and -automatically calculate balance the transaction in the posting. The -@code{bucket} allows you to fill in all postings and automatically -generate an additional posting to the bucket account balancing the -transaction. The following example set the @code{Assets:Checking} as -the bucket: -@smallexample +Normally, each transaction has at least two postings, which must +balance to zero. Ledger allows you to leave one posting with no +amount and automatically calculate balance the transaction in the +posting. The @code{bucket} allows you to fill in all postings and +automatically generate an additional posting to the bucket account +balancing the transaction. The following example set the +@code{Assets:Checking} as the bucket: +@smallexample bucket Assets:Checking 2011/01/25 Tom's Used Cars Expenses:Auto $ 5,500.00 @@ -1999,8 +2041,8 @@ account. For example: capture Expenses:Deductible:Medical Medical @end smallexample -Would cause any posting with @code{Medical} in its name to be replaced with -@code{Expenses:Deductible:Medical}. +Would cause any posting with @code{Medical} in its name to be replaced +with @code{Expenses:Deductible:Medical}. Ledger will display the mapped payees in @code{print} and @@ -2008,7 +2050,8 @@ Ledger will display the mapped payees in @code{print} and @item check @c instance_t::check_directive in textual.cc -A check can issue a warning if a condition is not met during Ledger's run. +A check can issue a warning if a condition is not met during Ledger's +run. @smallexample @@ -2020,14 +2063,15 @@ check <VALUE EXPRESSION BOOLEAN RESULT> Start a block comment, closed by @code{end comment}. @item commodity -Pre-declare commodity names. This only has effect if @code{--strict} or -@code{--pedantic} is used (see below). +Pre-declare commodity names. This only has effect if @code{--strict} +or @code{--pedantic} is used (see below). commodity $ commodity CAD -The @code{commodity} directive supports several optional sub-directives, if they -immediately follow the commodity directive and if they begin with whitespace: +The @code{commodity} directive supports several optional +sub-directives, if they immediately follow the commodity directive and +if they begin with whitespace: @smallexample commodity $ @@ -2037,16 +2081,16 @@ immediately follow the commodity directive and if they begin with whitespace: default @end smallexample -The @code{note} sub-directive associates a textual note with the commodity. At -present this has no value other than documentation. +The @code{note} sub-directive associates a textual note with the +commodity. At present this has no value other than documentation. -The @code{format} directive gives you a way to tell Ledger how to format this -commodity. In future using this directive will disable Ledger's observation -of other ways that commodity is used, and will provide the ``canonical'' -representation. +The @code{format} directive gives you a way to tell Ledger how to +format this commodity. In future using this directive will disable +Ledger's observation of other ways that commodity is used, and will +provide the ``canonical'' representation. -The @code{nomarket} directive states that the commodity's price should never be -auto-downloaded. +The @code{nomarket} directive states that the commodity's price should +never be auto-downloaded. The @code{default} directive marks this as the ``default'' commodity. @@ -2071,9 +2115,9 @@ Closes block commands like @code{tag} or @code{comment}. @item fixed @c instance_t::fixed_directive in textual.cc -A fixed block is used to set fixated prices (@pxref{Fixated prices}) for a series of -transactions. It's purely a typing saver, for use when entering many -transactions with fixated prices. +A fixed block is used to set fixated prices (@pxref{Fixated prices}) +for a series of transactions. It's purely a typing saver, for use +when entering many transactions with fixated prices. Thus, the following: @smallexample @@ -2112,16 +2156,17 @@ Include the stated file as if it were part of the current file. @item payee @c instance_t::payee_mapping_directive in textual.cc -The @code{payee} directive supports one optional sub-directive, if it immediately -follows the payee directive and if it begins with whitespace: +The @code{payee} directive supports one optional sub-directive, if it +immediately follows the payee directive and if it begins with +whitespace: @smallexample payee KFC alias KENTUCKY FRIED CHICKEN @end smallexample -The @code{alias} directive provides a regexp which, if it matches a parsed payee, -the declared payee name is substituted: +The @code{alias} directive provides a regexp which, if it matches +a parsed payee, the declared payee name is substituted: @smallexample 2012-02-27 KENTUCKY FRIED CHICKEN ; will be read as being 'KFC' @@ -2133,7 +2178,8 @@ Ledger will display the mapped payees in @code{print} and @item apply tag @c instance_t::tag_directive in textual.cc -Allows you to designate a block of transactions and assign the same tag to all. Tags can have values and may be nested. +Allows you to designate a block of transactions and assign the same +tag to all. Tags can have values and may be nested. @smallexample apply tag hastag apply tag nestedtag: true @@ -2154,7 +2200,8 @@ end apply tag nestedtag end apply tag hastag @end smallexample -@noindent is the equivalent of +@noindent +is the equivalent of @smallexample 2011/01/25 Tom's Used Cars @@ -2176,8 +2223,9 @@ end apply tag hastag Income:Sales @end smallexample -Note that anything following ``@code{end tag}'' is ignored. placing the -name of the tag that is being closed is a simple way to keep track. +Note that anything following ``@code{end tag}'' is ignored. placing +the name of the tag that is being closed is a simple way to keep +track. @item tag Pre-declares tag names. This only has effect if @code{--strict} or @@ -2188,8 +2236,9 @@ Pre-declares tag names. This only has effect if @code{--strict} or tag CSV @end smallexample -The 'tag' directive supports two optional sub-directives, if they immediately -follow the tag directive and if they begin with whitespace: +The 'tag' directive supports two optional sub-directives, if they +immediately follow the tag directive and if they begin with +whitespace: @smallexample tag Receipt @@ -2197,23 +2246,25 @@ follow the tag directive and if they begin with whitespace: assert value != "foobar" @end smallexample -The @code{check} and @code{assert} directives warn or error (respectively) if the given -value expression evaluates to false within the context of any use of the -related tag. In such a context, ``value'' is bound to the value of the tag -(which may not be a string if typed-metadata is used!). Such checks or -assertions are not called if no value is given. +The @code{check} and @code{assert} directives warn or error +(respectively) if the given value expression evaluates to false within +the context of any use of the related tag. In such a context, +``value'' is bound to the value of the tag (which may not be a string +if typed-metadata is used!). Such checks or assertions are not called +if no value is given. @item test @c instance_t::comment_directive in textual.cc -This is a synonym for @code{comment} and must be closed by an @code{end} tag. +This is a synonym for @code{comment} and must be closed by an +@code{end} tag. @item year @c instance_t::year_directive in textual.cc Denotes the year used for all subsequent transactions that give a date -without a year. The year should appear immediately after the directive, for -example: @code{year 2004}. This is useful at the beginning of a file, to -specify the year for that file. If all transactions specify a year, -however, this command has no effect. +without a year. The year should appear immediately after the +directive, for example: @code{year 2004}. This is useful at the +beginning of a file, to specify the year for that file. If all +transactions specify a year, however, this command has no effect. @end table @@ -2240,12 +2291,13 @@ N SYMBOL @item D AMOUNT Specifies the default commodity to use, by specifying an amount in the -expected format. The @command{transaction} command will use this commodity -as the default when none other can be determined. This command may be -used multiple times, to set the default flags for different -commodities; whichever is seen last is used as the default commodity. -For example, to set US dollars as the default commodity, while also -setting the thousands flag and decimal flag for that commodity, use: +expected format. The @command{transaction} command will use this +commodity as the default when none other can be determined. This +command may be used multiple times, to set the default flags for +different commodities; whichever is seen last is used as the default +commodity. For example, to set US dollars as the default commodity, +while also setting the thousands flag and decimal flag for that +commodity, use: @smallexample D $1,000.00 @end smallexample @@ -2269,34 +2321,39 @@ syntax of its timelog files. There are numerous tools to help convert various formats to a Ledger file. Most banks will generate a commas separated value file that can -easily be parsed into Ledger format using one of those tools. Some of the more popular tools are: +easily be parsed into Ledger format using one of those tools. Some of +the more popular tools are: + @itemize @item @code{icsv2ledger} @item @code{csvToLedger} @item @code{CSV2Ledger} @end itemize -@noindent Directly pulling information from banks is outside the scope of Ledger's -function. + +@noindent +Directly pulling information from banks is outside the scope of +Ledger's function. @node Archiving Previous Years, , Converting from other formats, Keeping a Journal @section Archiving Previous Years -After a while, your journal can get to be pretty large. While this will -not slow down Ledger---it's designed to process journals very +After a while, your journal can get to be pretty large. While this +will not slow down Ledger---it's designed to process journals very quickly---things can start to feel ``messy''; and it's a universal complaint that when finances feel messy, people avoid them. Thus, archiving the data from previous years into their own files can -offer a sense of completion, and freedom from the past. But how to best -accomplish this with the ledger program? There are two commands that -make it very simple: @command{print}, and @command{equity}. +offer a sense of completion, and freedom from the past. But how to +best accomplish this with the ledger program? There are two commands +that make it very simple: @command{print}, and @command{equity}. -Let's take an example file, with data ranging from year 2000 until 2004. -We want to archive years 2000 and 2001 to their own file, leaving just -2003 and 2004 in the current file. So, use @command{print} to output -all the earlier transactions to a file called @file{ledger-old.dat}: +Let's take an example file, with data ranging from year 2000 until +2004. We want to archive years 2000 and 2001 to their own file, +leaving just 2003 and 2004 in the current file. So, use +@command{print} to output all the earlier transactions to a file +called @file{ledger-old.dat}: @smallexample ledger -f ledger.dat -b 2000 -e 2001 print > ledger-old.dat @@ -2377,9 +2434,9 @@ The most basic form of transaction is: Assets:Cash $-20.00 @end smallexample -This transaction has a date, a payee or description, a target account (the -first posting), and a source account (the second posting). Each posting -specifies what action is taken related to that account. +This transaction has a date, a payee or description, a target account +(the first posting), and a source account (the second posting). Each +posting specifies what action is taken related to that account. A transaction can have any number of postings: @@ -2393,9 +2450,9 @@ A transaction can have any number of postings: @node Eliding amounts, Auxiliary dates, Basic format, Transactions @section Eliding amounts -The first thing you can do to make things easier is elide amounts. That is, -if exactly one posting has no amount specified, Ledger will infer the inverse -of the other postings' amounts: +The first thing you can do to make things easier is elide amounts. +That is, if exactly one posting has no amount specified, Ledger will +infer the inverse of the other postings' amounts: @smallexample 2012-03-10 KFC @@ -2404,8 +2461,10 @@ of the other postings' amounts: Liabilities:Credit ; same as specifying $-10 @end smallexample -@noindent If the other postings use multiple commodities, Ledger will copy the empty -posting N times and fill in the negated values of the various commodities: +@noindent +If the other postings use multiple commodities, Ledger will copy the +empty posting N times and fill in the negated values of the various +commodities: @smallexample 2012-03-10 KFC @@ -2416,7 +2475,8 @@ posting N times and fill in the negated values of the various commodities: Liabilities:Credit @end smallexample -@noindent This transaction is identical to writing: +@noindent +This transaction is identical to writing: @smallexample 2012-03-10 KFC @@ -2432,8 +2492,8 @@ posting N times and fill in the negated values of the various commodities: @node Auxiliary dates, Codes, Eliding amounts, Transactions @section Auxiliary dates -You can associate a second date with a transaction by following the primary -date with an equals sign: +You can associate a second date with a transaction by following the +primary date with an equals sign: @smallexample 2012-03-10=2012-03-08 KFC @@ -2441,17 +2501,18 @@ date with an equals sign: Assets:Cash $-20.00 @end smallexample -What this auxiliary date means is entirely up to you. The only use Ledger has -for it is that if you specify @code{--aux-date}, then all reports and calculations -(including pricing) will use the aux date as if it were the primary date. +What this auxiliary date means is entirely up to you. The only use +Ledger has for it is that if you specify @code{--aux-date}, then all +reports and calculations (including pricing) will use the aux date as +if it were the primary date. @node Codes, Transaction state, Auxiliary dates, Transactions @section Codes -A transaction can have a textual ``code''. This has no meaning and is only -displayed by the print command. Checking accounts often use codes like DEP, -XFER, etc., as well as check numbers. This is to give you a place to put -those codes: +A transaction can have a textual ``code''. This has no meaning and is +only displayed by the print command. Checking accounts often use +codes like DEP, XFER, etc., as well as check numbers. This is to give +you a place to put those codes: @smallexample 2012-03-10 (#100) KFC @@ -2462,9 +2523,9 @@ those codes: @node Transaction state, Transaction notes, Codes, Transactions @section Transaction state -A transaction can have a ``state'': cleared, pending, or uncleared. The default -is uncleared. To mark a transaction cleared, put a * before the payee, and -after date or code: +A transaction can have a ``state'': cleared, pending, or uncleared. +The default is uncleared. To mark a transaction cleared, put a * +before the payee, and after date or code: @smallexample 2012-03-10 * KFC @@ -2472,7 +2533,8 @@ after date or code: Assets:Cash @end smallexample -@noindent To mark it pending, use a !: +@noindent +To mark it pending, use a !: @smallexample 2012-03-10 ! KFC @@ -2480,16 +2542,17 @@ after date or code: Assets:Cash @end smallexample -What these mean is entirely up to you. The @code{--cleared} option will limits to -reports to only cleared items, while @code{--uncleared} shows both uncleared and -pending items, and @code{--pending} shows only pending items. - -I use cleared to mean that I've reconciled the transaction with my bank -statement, and pending to mean that I'm in the middle of a reconciliation. +What these mean is entirely up to you. The @code{--cleared} option +will limits to reports to only cleared items, while @code{--uncleared} +shows both uncleared and pending items, and @code{--pending} shows +only pending items. +I use cleared to mean that I've reconciled the transaction with my +bank statement, and pending to mean that I'm in the middle of +a reconciliation. -When you clear a transaction, that's really just shorthand for clearing all of -its postings. That is: +When you clear a transaction, that's really just shorthand for +clearing all of its postings. That is: @smallexample 2012-03-10 * KFC @@ -2497,7 +2560,8 @@ its postings. That is: Assets:Cash @end smallexample -@noindent Is the same as writing: +@noindent +Is the same as writing: @smallexample 2012-03-10 KFC @@ -2505,8 +2569,9 @@ its postings. That is: * Assets:Cash @end smallexample -@noindent You can mark individual postings as cleared or pending, in case one ``side'' of -the transaction has cleared, but the other hasn't yet: +@noindent +You can mark individual postings as cleared or pending, in case one +``side'' of the transaction has cleared, but the other hasn't yet: @smallexample 2012-03-10 KFC @@ -2527,8 +2592,9 @@ introduce a note about the transaction using the ; character: Assets:Cash @end smallexample -@noindent Notes can also appear on the next line, so long as that line begins with -whitespace: +@noindent +Notes can also appear on the next line, so long as that line begins +with whitespace: @smallexample 2012-03-10 * KFC ; yum, chicken... @@ -2542,11 +2608,10 @@ whitespace: Assets:Cash @end smallexample - -A transaction note is shared by all its postings. This becomes significant -when querying for metadata (see below). To specify that a note belongs only -to one posting, place it after a hard separator after the amount, or on its -own line preceded by whitespace: +A transaction note is shared by all its postings. This becomes +significant when querying for metadata (see below). To specify that +a note belongs only to one posting, place it after a hard separator +after the amount, or on its own line preceded by whitespace: @smallexample 2012-03-10 * KFC @@ -2558,10 +2623,10 @@ own line preceded by whitespace: @node Metadata, Virtual postings, Transaction notes, Transactions @section Metadata -One of Ledger's more powerful features is the ability to associate typed -metadata with postings and transactions (by which I mean all of a -transaction's postings). This metadata can be queried, displayed, and used in -calculations. +One of Ledger's more powerful features is the ability to associate +typed metadata with postings and transactions (by which I mean all of +a transaction's postings). This metadata can be queried, displayed, +and used in calculations. The are two forms of metadata: tags and tag/value pairs. @@ -2574,7 +2639,8 @@ The are two forms of metadata: tags and tag/value pairs. @node Metadata tags, Metadata values, Metadata, Metadata @subsection Metadata tags -To tag an item, put any word not containing whitespace between two colons: +To tag an item, put any word not containing whitespace between two +colons: @smallexample 2012-03-10 * KFC @@ -2595,9 +2661,9 @@ You can gang up multiple tags by sharing colons: @node Metadata values, Typed metadata, Metadata tags, Metadata @subsection Metadata values -To associate a value with a tag, use the syntax "Key: Value", where the value -can be any string of characters. Whitespace is needed after the colon, and -cannot appear in the Key: +To associate a value with a tag, use the syntax "Key: Value", where +the value can be any string of characters. Whitespace is needed after +the colon, and cannot appear in the Key: @smallexample 2012-03-10 * KFC @@ -2620,10 +2686,11 @@ For example, although I can specify a date textually like so: ; AuxDate: 2012/02/30 @end smallexample -@noindent This date is just a string, and won't be parsed as a date -unless its value is used in a date-context (at which time the string -is parsed into a date automatically every time it is needed as a -date). If on the other hand I write this: +@noindent +This date is just a string, and won't be parsed as a date unless its +value is used in a date-context (at which time the string is parsed +into a date automatically every time it is needed as a date). If on +the other hand I write this: @smallexample 2012-03-10 * KFC @@ -2632,22 +2699,25 @@ date). If on the other hand I write this: ; AuxDate:: [2012/02/30] @end smallexample -@noindent Then it is parsed as a date only once, and during parsing -of the journal file, which would let me know right away that it is an -invalid date. +@noindent +Then it is parsed as a date only once, and during parsing of the +journal file, which would let me know right away that it is an invalid +date. @node Virtual postings, Expression amounts, Metadata, Transactions @section Virtual postings -Ordinarily, the amounts of all postings in a transaction must balance to zero. -This is non-negotiable. It's what double-entry accounting is all about! But -there are some tricks up Ledger's sleeve... +Ordinarily, the amounts of all postings in a transaction must balance +to zero. This is non-negotiable. It's what double-entry accounting +is all about! But there are some tricks up Ledger's sleeve... -You can use virtual accounts to transfer amounts to an account on the sly, -bypassing the balancing requirement. The trick is that these postings are not -considered ``real'', and can be removed from all reports using @code{--real}. +You can use virtual accounts to transfer amounts to an account on the +sly, bypassing the balancing requirement. The trick is that these +postings are not considered ``real'', and can be removed from all +reports using @code{--real}. -To specify a virtual account, surround the account name with parentheses: +To specify a virtual account, surround the account name with +parentheses: @smallexample 2012-03-10 * KFC @@ -2656,9 +2726,9 @@ To specify a virtual account, surround the account name with parentheses: (Budget:Food) $-20.00 @end smallexample -If you want, you can state that virtual postings @emph{should} balance against -one or more other virtual postings by using brackets (which look ``harder'') -rather than parentheses: +If you want, you can state that virtual postings @emph{should} balance +against one or more other virtual postings by using brackets (which +look ``harder'') rather than parentheses: @smallexample 2012-03-10 * KFC @@ -2671,9 +2741,9 @@ rather than parentheses: @node Expression amounts, Balance verification, Virtual postings, Transactions @section Expression amounts -An amount is usually a numerical figure with an (optional) commodity, but it -can also be any value expression. To indicate this, surround the amount -expression with parentheses: +An amount is usually a numerical figure with an (optional) commodity, +but it can also be any value expression. To indicate this, surround +the amount expression with parentheses: @smallexample 2012-03-10 * KFC @@ -2691,9 +2761,10 @@ expression with parentheses: * Balancing transactions:: @end menu -If at the end of a posting's amount (and after the cost too, if there is one) -there is an equals sign, then Ledger will verify that the total value for that -account as of that posting matches the amount specified. +If at the end of a posting's amount (and after the cost too, if there +is one) there is an equals sign, then Ledger will verify that the +total value for that account as of that posting matches the amount +specified. There are two forms of this features: balance assertions, and balance assignments. @@ -2710,8 +2781,8 @@ A balance assertion has this general form: Assets:Cash $-20.00 = $500.00 @end smallexample -This simply asserts that after subtracting $20.00 from Assets:Cash, that the -resulting total matches $500.00. If not, it is an error. +This simply asserts that after subtracting $20.00 from Assets:Cash, +that the resulting total matches $500.00. If not, it is an error. @node Balance assignments, Resetting a balance, Balance assertions, Balance verification @subsection Balance assignments @@ -2724,16 +2795,16 @@ A balance assignment has this form: Assets:Cash = $500.00 @end smallexample -This sets the amount of the second posting to whatever it would need to be for -the total in Assets:Cash to be $500.00 after the posting. If the resulting -amount is not $-20.00 in this case, it is an error. +This sets the amount of the second posting to whatever it would need +to be for the total in Assets:Cash to be $500.00 after the posting. +If the resulting amount is not $-20.00 in this case, it is an error. @node Resetting a balance, Balancing transactions, Balance assignments, Balance verification @subsection Resetting a balance -Say your book-keeping has gotten a bit out of date, and your Ledger balance no -longer matches your bank balance. You can create an adjustment transaction -using balance assignments: +Say your book-keeping has gotten a bit out of date, and your Ledger +balance no longer matches your bank balance. You can create an +adjustment transaction using balance assignments: @smallexample 2012-03-10 Adjustment @@ -2741,12 +2812,12 @@ using balance assignments: Equity:Adjustments @end smallexample -Since the second posting is also null, it's value will become the inverse of -whatever amount is generated for the first posting. +Since the second posting is also null, it's value will become the +inverse of whatever amount is generated for the first posting. -This is the only time in ledger when more than one posting's amount may be -empty --- and then only because it's not true empty, it is indirectly provided -by the balance assignment's value. +This is the only time in ledger when more than one posting's amount +may be empty --- and then only because it's not true empty, it is +indirectly provided by the balance assignment's value. @node Balancing transactions, , Resetting a balance, Balance verification @subsection Balancing transactions @@ -2758,26 +2829,27 @@ As a consequence of all the above, consider the following transaction: [Assets:Brokerage] = 10 AAPL @end smallexample -What this says is: set the amount of the posting to whatever value is needed -so that Assets:Brokerage contains 10 AAPL. Then, because this posting must -balance, ensure that its value is zero. This can only be true if -Assets:Brokerage does indeed contain 10 AAPL at that point in the input file. +What this says is: set the amount of the posting to whatever value is +needed so that Assets:Brokerage contains 10 AAPL. Then, because this +posting must balance, ensure that its value is zero. This can only be +true if Assets:Brokerage does indeed contain 10 AAPL at that point in +the input file. -A balanced virtual transaction is used simply to indicate to Ledger that this -is not a ``real'' transaction. It won't appear in any reports anyway (unless -you use a register report with @code{--empty}). +A balanced virtual transaction is used simply to indicate to Ledger +that this is not a ``real'' transaction. It won't appear in any +reports anyway (unless you use a register report with @code{--empty}). @node Posting cost, Explicit posting costs, Balance verification, Transactions @section Posting cost -When you transfer a commodity from one account to another, sometimes it get -transformed during the transaction. This happens when you spend money on gas, -for example, which transforms dollars into gallons of gasoline, or dollars -into stocks in a company. +When you transfer a commodity from one account to another, sometimes +it get transformed during the transaction. This happens when you +spend money on gas, for example, which transforms dollars into gallons +of gasoline, or dollars into stocks in a company. -In those cases, Ledger will remember the ``cost'' of that transaction for you, -and can use it during reporting in various ways. Here's an example of a stock -purchase: +In those cases, Ledger will remember the ``cost'' of that transaction +for you, and can use it during reporting in various ways. Here's an +example of a stock purchase: @smallexample 2012-03-10 My Broker @@ -2786,14 +2858,14 @@ purchase: @end smallexample This is different from transferring 10 AAPL shares from one account to -another, in this case you are @emph{exchanging} one commodity for another. The -resulting posting cost is $50.00 per share. +another, in this case you are @emph{exchanging} one commodity for +another. The resulting posting cost is $50.00 per share. @node Explicit posting costs, Posting cost expressions, Posting cost, Transactions @section Explicit posting costs -You can make any posting's cost explicit using the @@ symbol after the amount -or amount expression: +You can make any posting's cost explicit using the @@ symbol after the +amount or amount expression: @smallexample 2012-03-10 My Broker @@ -2801,8 +2873,8 @@ or amount expression: Assets:Brokerage:Cash $-500.00 @end smallexample -When you do this, since Ledger can now figure out the balancing amount from -the first posting's cost, you can elide the other amount: +When you do this, since Ledger can now figure out the balancing amount +from the first posting's cost, you can elide the otheramount: @smallexample 2012-03-10 My Broker @@ -2817,22 +2889,26 @@ the first posting's cost, you can elide the other amount: @node Primary and secondary commodities, , Explicit posting costs, Explicit posting costs @subsection Primary and secondary commodities -It is a general convention within Ledger that the ``top'' postings in a -transaction contain the target accounts, while the final posting contains the -source account. Whenever a commodity is exchanged like this, the commodity -moved to the target account is considered ``secondary'', while the commodity -used for purchasing and tracked in the cost is ``primary''. +It is a general convention within Ledger that the ``top'' postings in +a transaction contain the target accounts, while the final posting +contains the source account. Whenever a commodity is exchanged like +this, the commodity moved to the target account is considered +``secondary'', while the commodity used for purchasing and tracked in +the cost is ``primary''. -Said another way, whenever Ledger sees a posting cost of the form "AMOUNT @@ -AMOUNT", the commodity used in the second amount is marked ``primary''. +Said another way, whenever Ledger sees a posting cost of the form +"AMOUNT @@ AMOUNT", the commodity used in the second amount is marked +``primary''. -The only meaning a primary commodity has is that @code{-V} flag will never convert a -primary commodity into any other commodity. @code{-X} still will, however. +The only meaning a primary commodity has is that @code{-V} flag will +never convert a primary commodity into any other commodity. @code{-X} +still will, however. @node Posting cost expressions, Total posting costs, Explicit posting costs, Transactions @section Posting cost expressions -Just as you can have amount expressions, you can have posting expressions: +Just as you can have amount expressions, you can have posting +expressions: @smallexample 2012-03-10 My Broker @@ -2851,9 +2927,9 @@ You can even have both: @node Total posting costs, Virtual posting costs, Posting cost expressions, Transactions @section Total posting costs -The cost figure following the @@ character specifies the @emph{per-unit} price for -the commodity being transferred. If you'd like to specify the total cost -instead, use @@@@: +The cost figure following the @@ character specifies the +@emph{per-unit} price for the commodity being transferred. If you'd +like to specify the total cost instead, use @@@@: @smallexample 2012-03-10 My Broker @@ -2872,10 +2948,11 @@ Ledger reads this as if you had written: @node Virtual posting costs, Commodity prices, Total posting costs, Transactions @section Virtual posting costs -Normally whenever a commodity exchange like this happens, the price of the -exchange (such as $50 per share of AAPL, above) is recorded in Ledger's -internal price history database. To prevent this from happening in the case -of an exceptional transaction, surround the @@ or @@@@ with parentheses: +Normally whenever a commodity exchange like this happens, the price of +the exchange (such as $50 per share of AAPL, above) is recorded in +Ledger's internal price history database. To prevent this from +happening in the case of an exceptional transaction, surround the @@ +or @@@@ with parentheses: @smallexample 2012-03-10 My Brother @@ -2886,10 +2963,11 @@ of an exceptional transaction, surround the @@ or @@@@ with parentheses: @node Commodity prices, Prices vs. costs, Virtual posting costs, Transactions @section Commodity prices -When a transaction occurs that exchange one commodity for another, Ledger -records that commodity price not only within its internal price database, but -also attached to the commodity itself. Usually this fact remains invisible to -the user, unless you turn on @code{--lot-prices} to show these hidden price figures. +When a transaction occurs that exchange one commodity for another, +Ledger records that commodity price not only within its internal price +database, but also attached to the commodity itself. Usually this +fact remains invisible to the user, unless you turn on +@code{--lot-prices} to show these hidden price figures. For example, consider the stock sale given above: @@ -2899,14 +2977,14 @@ For example, consider the stock sale given above: Assets:Brokerage:Cash @end smallexample -The commodity transferred into Assets:Brokerage is not actually 10 AAPL, but -rather 10 AAPL @{$5.00@}. The figure in braces after the amount is called the -``lot price''. It's Ledger's way of remembering that this commodity was -transferred through an exchange, and that $5.00 was the price of that -exchange. +The commodity transferred into Assets:Brokerage is not actually 10 +AAPL, but rather 10 AAPL @{$5.00@}. The figure in braces after the +amount is called the ``lot price''. It's Ledger's way of remembering +that this commodity was transferred through an exchange, and that +$5.00 was the price of that exchange. -This becomes significant if you later sell that commodity again. For example, -you might write this: +This becomes significant if you later sell that commodity again. For +example, you might write this: @smallexample 2012-04-10 My Broker @@ -2914,8 +2992,8 @@ you might write this: Assets:Brokerage -10 AAPL @@ $75.00 @end smallexample -And that would be perfectly fine, but how do you track the capital gains on -the sale? It could be done with a virtual posting: +And that would be perfectly fine, but how do you track the capital +gains on the sale? It could be done with a virtual posting: @smallexample 2012-04-10 My Broker @@ -2924,12 +3002,12 @@ the sale? It could be done with a virtual posting: (Income:Capital Gains) $-250.00 @end smallexample -But this gets messy since capital gains income is very real, and not quite -appropriate for a virtual posting. +But this gets messy since capital gains income is very real, and not +quite appropriate for a virtual posting. -Instead, if you reference that same hidden price annotation, Ledger will -figure out that the price of the shares you're selling, and the cost you're -selling them at, don't balance: +Instead, if you reference that same hidden price annotation, Ledger +will figure out that the price of the shares you're selling, and the +cost you're selling them at, don't balance: @smallexample 2012-04-10 My Broker @@ -2937,10 +3015,10 @@ selling them at, don't balance: Assets:Brokerage -10 AAPL @{$50.00@} @@ $75.00 @end smallexample -This transaction will fail because the $250.00 price difference between the -price you bought those shares at, and the cost you're selling them for, does -not match. The lot price also identifies which shares you purchased on that -prior date. +This transaction will fail because the $250.00 price difference +between the price you bought those shares at, and the cost you're +selling them for, does not match. The lot price also identifies which +shares you purchased on that prior date. @menu * Total commodity prices:: @@ -2949,9 +3027,9 @@ prior date. @node Total commodity prices, , Commodity prices, Commodity prices @subsection Total commodity prices -As a shorthand, you can specify the total price instead of the per-share -price in doubled braces. This goes well with total costs, but is not required -to be used with them: +As a shorthand, you can specify the total price instead of the +per-share price in doubled braces. This goes well with total costs, +but is not required to be used with them: @smallexample 2012-04-10 My Broker @@ -2960,12 +3038,13 @@ to be used with them: Income:Capital Gains $-250.00 @end smallexample -It should be noted that this is a convenience only for cases where you buy and -sell whole lots. The @{@{$500.00@}@} is @emph{not} an attribute of commodity, whereas -@{$5.00@} is. In fact, when you write @{@{$500.00@}@}, Ledger just divides that -value by 10 and sees @{$50.00@}. So if you use the print command to look at -this transaction, you'll see the single form in the output. The double price -form is a shorthand only. +It should be noted that this is a convenience only for cases where you +buy and sell whole lots. The @{@{$500.00@}@} is @emph{not} an +attribute of commodity, whereas @{$5.00@} is. In fact, when you write +@{@{$500.00@}@}, Ledger just divides that value by 10 and sees +@{$50.00@}. So if you use the print command to look at this +transaction, you'll see the single form in the output. The double +price form is a shorthand only. Plus, it comes with dangers. This works fine: @@ -2985,7 +3064,8 @@ Plus, it comes with dangers. This works fine: Income:Capital Gains $-125.00 @end smallexample -@noindent But this does not do what you might expect: +@noindent +But this does not do what you might expect: @smallexample 2012-04-10 My Broker @@ -3003,8 +3083,9 @@ Plus, it comes with dangers. This works fine: Income:Capital Gains $-125.00 @end smallexample -And in cases where the amounts do not divide into whole figure and must be -rounded, the capital gains figure could be off by a cent. Use with caution. +And in cases where the amounts do not divide into whole figure and +must be rounded, the capital gains figure could be off by a cent. Use +with caution. @node Prices vs. costs, Fixated prices, Commodity prices, Transactions @section Prices vs. costs @@ -3022,17 +3103,18 @@ following two transactions are equivalent: Assets:Brokerage:Cash $750.00 @end smallexample -However, note that what you see in some reports may differ, for example in the -print report. Functionally, however, there is no difference, and neither the -register nor the balance report are sensitive to this difference. +However, note that what you see in some reports may differ, for +example in the print report. Functionally, however, there is no +difference, and neither the register nor the balance report are +sensitive to this difference. @node Fixated prices, Lot dates, Prices vs. costs, Transactions @section Fixated prices and costs -If you buy a stock last year, and ask for its value today, Ledger will consult -its price database to see what the most recent price for that stock is. You -can short-circuit this lookup by ``fixing'' the price at the time of a -transaction. This is done using @{=AMOUNT@}: +If you buy a stock last year, and ask for its value today, Ledger will +consult its price database to see what the most recent price for that +stock is. You can short-circuit this lookup by ``fixing'' the price +at the time of a transaction. This is done using @{=AMOUNT@}: @smallexample 2012-04-10 My Broker @@ -3040,15 +3122,15 @@ transaction. This is done using @{=AMOUNT@}: Assets:Brokerage:Cash $750.00 @end smallexample -These 10 AAPL will now always be reported as being worth $50, no matter what -else happens to the stock in the meantime. +These 10 AAPL will now always be reported as being worth $50, no +matter what else happens to the stock in the meantime. -Fixated prices are a special case of using lot valuation expressions (see -below) to fix the value of a commodity lot. +Fixated prices are a special case of using lot valuation expressions +(see below) to fix the value of a commodity lot. -Since price annotations and costs are largely interchangeable and a matter of -preference, there is an equivalent syntax for specified fixated prices by way -of the cost: +Since price annotations and costs are largely interchangeable and +a matter of preference, there is an equivalent syntax for specified +fixated prices by way of the cost: @smallexample 2012-04-10 My Broker @@ -3056,16 +3138,17 @@ of the cost: Assets:Brokerage:Cash $750.00 @end smallexample -This is the same as the previous transaction, with the same caveats found in -@ref{Prices vs. costs}. +This is the same as the previous transaction, with the same caveats +found in @ref{Prices vs. costs}. @node Lot dates, Lot notes, Fixated prices, Transactions @section Lot dates -In addition to lot prices, you can specify lot dates and reveal them with -@code{--lot-dates}. Other than that, however, they have no special meaning to -Ledger. They are specified after the amount in square brackets (the same way -that dates are parsed in value expressions): +In addition to lot prices, you can specify lot dates and reveal them +with @code{--lot-dates}. Other than that, however, they have no +special meaning to Ledger. They are specified after the amount in +square brackets (the same way that dates are parsed in value +expressions): @smallexample 2012-04-10 My Broker @@ -3078,8 +3161,9 @@ that dates are parsed in value expressions): @section Lot notes You can also associate arbitrary notes for your own record keeping in -parentheses, and reveal them with @code{--lot-notes}. One caveat is that the note -cannot begin with an @@ character, as that would indicate a virtual cost: +parentheses, and reveal them with @code{--lot-notes}. One caveat is +that the note cannot begin with an @@ character, as that would +indicate a virtual cost: @smallexample 2012-04-10 My Broker @@ -3088,28 +3172,30 @@ cannot begin with an @@ character, as that would indicate a virtual cost: Income:Capital Gains $-125.00 @end smallexample -You can any combination of lot prices, dates or notes, in any order. They are -all optional. +You can any combination of lot prices, dates or notes, in any order. +They are all optional. To show all lot information in a report, use @code{--lots}. @node Lot value expressions, Automated Transactions, Lot notes, Transactions @section Lot value expressions -Normally when you ask Ledger to display the values of commodities held, it -uses a value expression called ``market'' to determine the most recent value -from its price database --- even downloading prices from the Internet, if @code{-Q} -was specified and a suitable ``getquote'' script is found on your system. +Normally when you ask Ledger to display the values of commodities +held, it uses a value expression called ``market'' to determine the +most recent value from its price database --- even downloading prices +from the Internet, if @code{-Q} was specified and a suitable +``getquote'' script is found on your system. -However, you can override this valuation logic by providing a commodity -valuation expression in doubled parentheses. This expression must result in -one of two values: either an amount to always be used as the per-share price -for that commodity; or a function taking three argument which is called to -determine that price. +However, you can override this valuation logic by providing +a commodity valuation expression in doubled parentheses. This +expression must result in one of two values: either an amount to +always be used as the per-share price for that commodity; or +a function taking three argument which is called to determine that +price. -If you use the functional form, you can either specify a function name, or a -lambda expression. Here's a function that yields the price as $10 in whatever -commodity is being requested: +If you use the functional form, you can either specify a function +name, or a lambda expression. Here's a function that yields the price +as $10 in whatever commodity is being requested: @smallexample define ten_dollars(s, date, t) = market($10, date, t) @@ -3124,8 +3210,8 @@ I can now use that in a lot value expression as follows: Income:Capital Gains $-125.00 @end smallexample -Alternatively, I could do the same thing without pre-defining a function by -using a lambda expression taking three arguments: +Alternatively, I could do the same thing without pre-defining +a function by using a lambda expression taking three arguments: @smallexample 2012-04-10 My Broker @@ -3138,35 +3224,38 @@ The arguments passed to these functions have the following meaning: @itemize @item source - The source commodity string, or an amount object. If it is a - string, the return value must be an amount representing the - price of the commodity identified by that string (example: ``$''). - If it is an amount, return the value of that amount as a new - amount (usually calculated as commodity price times source amount). + The source commodity string, or an amount object. If it is + a string, the return value must be an amount representing the + price of the commodity identified by that string (example: + ``$''). If it is an amount, return the value of that amount + as a new amount (usually calculated as commodity price times + source amount). @item date - The date to use for determining the value. If null, it means no - date was specified, which can mean whatever you want it to mean. + The date to use for determining the value. If null, it means + no date was specified, which can mean whatever you want it to + mean. @item target - If not null, a string representing the desired target commodity - that the commodity price, or repriced amount, should be valued - in. Note that this string can be a comma-separated list, and - that some or all of the commodities in that list may be suffixed - with an exclamation mark, to indicate what is being desired. + If not null, a string representing the desired target + commodity that the commodity price, or repriced amount, should + be valued in. Note that this string can be a comma-separated + list, and that some or all of the commodities in that list may + be suffixed with an exclamation mark, to indicate what is + being desired. @end itemize -In most cases, it is simplest to either use explicit amounts in your valuation -expressions, or just pass the arguments down to market after modifying them to -suit your needs. +In most cases, it is simplest to either use explicit amounts in your +valuation expressions, or just pass the arguments down to market after +modifying them to suit your needs. @node Automated Transactions, , Lot value expressions, Transactions @section Automated Transactions -An automated transaction is a special kind of transaction which adds its -postings to other transactions any time one of that other transactions' -postings matches its predicate. The predicate uses the same query syntax as -the Ledger command line. +An automated transaction is a special kind of transaction which adds +its postings to other transactions any time one of that other +transactions' postings matches its predicate. The predicate uses the +same query syntax as the Ledger command line. Consider this posting: @@ -3184,8 +3273,8 @@ If I write this automated transaction before it in the file: Bar $-50.00 @end smallexample -Then the first transaction will be modified during parsing as if I'd written -this: +Then the first transaction will be modified during parsing as if I'd +written this: @smallexample 2012-03-10 KFC @@ -3197,9 +3286,10 @@ this: Bar $-50.00 @end smallexample -Despite this fancy logic, automated transactions themselves follow most of the -same rules as regular transactions: their postings must balance (unless you -use a virtual posting), you can have metadata, etc. +Despite this fancy logic, automated transactions themselves follow +most of the same rules as regular transactions: their postings must +balance (unless you use a virtual posting), you can have metadata, +etc. One thing you cannot do, however, is elide amounts in an automated transaction. @@ -3219,9 +3309,9 @@ transaction. @node Amount multipliers, Accessing the matching posting's amount, Automated Transactions, Automated Transactions @subsection Amount multipliers -As a special case, if an automated transaction's posting's amount (phew) has -no commodity, it is taken as a multiplier upon the matching posting's cost. -For example: +As a special case, if an automated transaction's posting's amount +(phew) has no commodity, it is taken as a multiplier upon the matching +posting's cost. For example: @smallexample = expr true @@ -3248,10 +3338,10 @@ Then the latter transaction turns into this during parsing: @node Accessing the matching posting's amount, Referring to the matching posting's account, Amount multipliers, Automated Transactions @subsection Accessing the matching posting's amount -If you use an amount expression for an automated transaction's posting, that -expression has access to all the details of the matched posting. For example, -you can refer to that posting's amount using the ``amount'' value expression -variable: +If you use an amount expression for an automated transaction's +posting, that expression has access to all the details of the matched +posting. For example, you can refer to that posting's amount using +the ``amount'' value expression variable: @smallexample = expr true @@ -3275,9 +3365,9 @@ This becomes: @node Referring to the matching posting's account, Applying metadata to every matched posting, Accessing the matching posting's amount, Automated Transactions @subsection Referring to the matching posting's account -Sometimes want to refer to the account that matched in some way within the -automated transaction itself. This is done by using the string $account, -anywhere within the account part of the automated posting: +Sometimes want to refer to the account that matched in some way within +the automated transaction itself. This is done by using the string +$account, anywhere within the account part of the automated posting: @smallexample = food @@ -3300,8 +3390,9 @@ Becomes: @node Applying metadata to every matched posting, Applying metadata to the generated posting, Referring to the matching posting's account, Automated Transactions @subsection Applying metadata to every matched posting -If the automated transaction has a transaction note, that note is copied -(along with any metadata) to every posting that matches the predicate: +If the automated transaction has a transaction note, that note is +copied (along with any metadata) to every posting that matches the +predicate: @smallexample = food @@ -3326,8 +3417,8 @@ Becomes: @node Applying metadata to the generated posting, State flags, Applying metadata to every matched posting, Automated Transactions @subsection Applying metadata to the generated posting -If the automated transaction's posting has a note, that note is carried to the -generated posting within the matched transaction: +If the automated transaction's posting has a note, that note is +carried to the generated posting within the matched transaction: @smallexample = food @@ -3349,16 +3440,18 @@ Becomes: Assets:Cash $-20.00 @end smallexample -This is slightly different from the rules for regular transaction notes, in -that an automated transaction's note does not apply to every posting within -the automated transaction itself, but rather to every posting it matches. +This is slightly different from the rules for regular transaction +notes, in that an automated transaction's note does not apply to every +posting within the automated transaction itself, but rather to every +posting it matches. @node State flags, Effective Dates, Applying metadata to the generated posting, Automated Transactions @subsection State flags -Although you cannot mark an automated transaction as a whole as cleared or -pending, you can mark its postings with a * or ! before the account name, and -that state flag gets carried to the generated posting. +Although you cannot mark an automated transaction as a whole as +cleared or pending, you can mark its postings with a * or ! before the +account name, and that state flag gets carried to the generated +posting. @node Effective Dates, Periodic Transactions, State flags, Automated Transactions @subsection Effective Dates @@ -3372,44 +3465,55 @@ Ledger you can control every aspect of the timing of a transaction. Say you're in business. If you bill a customer, you can enter something like @cindex effective date of invoice + @smallexample 2008/01/01=2008/01/14 Client invoice ; estimated date you'll be paid Assets:Accounts Receivable $100.00 Income: Client name @end smallexample -@noindent Then, when you receive the payment, you change it to + +@noindent +Then, when you receive the payment, you change it to @smallexample 2008/01/01=2008/01/15 Client invoice ; actual date money received Assets:Accounts Receivable $100.00 Income: Client name @end smallexample -@noindent and add something like + +@noindent +and add something like @smallexample 2008/01/15 Client payment Assets:Checking $100.00 Assets:Accounts Receivable @end smallexample + Now @smallexample - ledger --subtotal --begin 2008/01/01 --end 2008/01/14 bal Income +ledger --subtotal --begin 2008/01/01 --end 2008/01/14 bal Income @end smallexample -@noindent gives you your accrued income in the first two weeks of the year, and + +@noindent +gives you your accrued income in the first two weeks of the year, and + @smallexample - ledger --effective --subtotal --begin 2008/01/01 --end 2008/01/14 bal Income +ledger --effective --subtotal --begin 2008/01/01 --end 2008/01/14 bal Income @end smallexample -@noindent gives you your cash basis income in the same two weeks. + +@noindent +gives you your cash basis income in the same two weeks. Another use is distributing costs out in time. As an example, suppose -you just prepaid into a local vegetable co-op that sustains you through -the winter. It cost $225 to join the program, so you write a check. -You don't want your October grocery budget to be blown because you bought -food ahead, however. What you really want is for the money to be evenly -distributed over the next six months so that your monthly budgets -gradually take a hit for the vegetables you'll pick up from the co-op, -even though you've already paid for them. +you just prepaid into a local vegetable co-op that sustains you +through the winter. It cost $225 to join the program, so you write +a check. You don't want your October grocery budget to be blown +because you bought food ahead, however. What you really want is for +the money to be evenly distributed over the next six months so that +your monthly budgets gradually take a hit for the vegetables you'll +pick up from the co-op, even though you've already paid for them. @smallexample 2008/10/16 * (2090) Bountiful Blessings Farm @@ -3533,8 +3637,8 @@ The power of Ledger comes from the incredible flexibility in its reporting commands, combined with formatting commands. Some options control what is included in the calculations, and formatting controls how it is displayed. The combinations are infinite. This chapter will -show you the basics of combining various options and commands. In the next -chapters you will find details about the specific commands and +show you the basics of combining various options and commands. In the +next chapters you will find details about the specific commands and options. @node Balance Reports, Typical queries, Introduction, Building Reports @@ -3548,11 +3652,15 @@ options. @node Controlling the Accounts and Payees, Controlling formatting, Balance Reports, Balance Reports @subsection Controlling the Accounts and Payees -The balance report is the most commonly used report. The simplest invocation is: +The balance report is the most commonly used report. The simplest +invocation is: + @smallexample ledger balance -f drewr3.dat @end smallexample -@noindent which will print the balances of every account in your journal. + +@noindent +which will print the balances of every account in your journal. @smallexample $ -3,804.00 Assets @@ -3577,9 +3685,10 @@ ledger balance -f drewr3.dat $ -243.60 @end smallexample -Most times this is more than you want. Limiting the results to specific -accounts is as easy as entering the names of the accounts after the -command. +Most times this is more than you want. Limiting the results to +specific accounts is as easy as entering the names of the accounts +after the command. + @smallexample 20:37:53 ~/ledger/test/input > ledger balance -f drewr3.dat Auto MasterCard $ 5,500.00 Expenses:Auto @@ -3588,10 +3697,14 @@ command. $ 5,480.00 20:39:21 ~/ledger/test/input > @end smallexample -@noindent note the implicit logical and between @code{Auto} and @code{Mastercard}. -If you want the entire contents of a branch of your account tree, use the -highest common name in the branch: +@noindent +note the implicit logical and between @code{Auto} and +@code{Mastercard}. + +If you want the entire contents of a branch of your account tree, use +the highest common name in the branch: + @smallexample 20:39:21 ~/ledger/test/input > ledger balance -f drewr3.dat Income $ -2,030.00 Income @@ -3602,7 +3715,9 @@ highest common name in the branch: 20:40:28 ~/ledger/test/input > @end smallexample -You can use general regular expressions in nearly anyplace Ledger needs a string: +You can use general regular expressions in nearly anyplace Ledger +needs a string: + @smallexample 20:40:28 ~/ledger/test/input > ledger balance -f drewr3.dat ^Bo 21:13:29 ~/ledger/test/input > ledger balance -f drewr3.dat Bo @@ -3614,20 +3729,25 @@ there are none. The second looks for any account with ``Bo'', which is @code{Expenses:Books}. @cindex limit by payees + If you want to know exactly how much you have spent in a particular account on a particular payee, the following are equivalent: + @smallexample > ledger balance Auto:Fuel and Chevron > ledger balance --limit "(account=~/Fuel/) & (payee=~/Chev/)" @end smallexample -@noindent will show you the amount expended on gasoline at Chevron. -The second example is the first example of the very power expression -language available to shape reports. The first example may be easier to + +@noindent +will show you the amount expended on gasoline at Chevron. The second +example is the first example of the very power expression language +available to shape reports. The first example may be easier to remember, but learning to use the second will open up far more possibilities. If you want to exclude specific accounts from the report, you can exclude multiple accounts with parentheses: + @smallexample ledger -s bal Expenses and not \(Expenses:Drinks or Expenses:Candy or Expenses:Gifts\) @end smallexample @@ -3649,9 +3769,10 @@ October, sorted by total: ledger -b "last oct" -s -S T bal ^expenses @end example -From left to right the options mean: Show transactions since last October; -show all sub-accounts; sort by the absolute value of the total; and -report the balance for all accounts that begin with ``expenses''. +From left to right the options mean: Show transactions since last +October; show all sub-accounts; sort by the absolute value of the +total; and report the balance for all accounts that begin with +``expenses''. @menu * Reporting monthly expenses:: @@ -3722,15 +3843,15 @@ asset classes you want to track. In our simple example we assume you want to apportion you assets into the general categories of domestic and international equities (stocks) -and a combined category of bonds and cash. For illustrative purposes we -will use several publicly available mutual funds from Vanguard. the -three funds we will track are the Vanguard 500 IDX FD Signal (VIFSX), -the Vanguard Target Retirement 2030 (VTHRX), and the Vanguard Short Term -Federal Fund (VSGBX). Each of these funds allocates assets to different -categories of the investment universe and in different proportions. -When you buy a share of VTHRX, that share is partially invested in -equities, and partially invested in bonds and cash. Below is the asset -allocation for each of the instruments listed above: +and a combined category of bonds and cash. For illustrative purposes +we will use several publicly available mutual funds from Vanguard. +the three funds we will track are the Vanguard 500 IDX FD Signal +(VIFSX), the Vanguard Target Retirement 2030 (VTHRX), and the Vanguard +Short Term Federal Fund (VSGBX). Each of these funds allocates assets +to different categories of the investment universe and in different +proportions. When you buy a share of VTHRX, that share is partially +invested in equities, and partially invested in bonds and cash. Below +is the asset allocation for each of the instruments listed above: @multitable @columnfractions .2 .2 .3 .3 @item @tab Domestic @tab Global @tab @@ -3772,11 +3893,11 @@ would look like: (Allocation:Bonds/Cash) 1.000 @end smallexample -How do these work? First the `=' sign at the beginning of the line tells -ledger this is an automatic transaction to be applied when the condition -following the `=' is true. After the `=' sign is a value expression -(@pxref{Value Expressions}) that returns true any time a posting -contains the commodity of interest. +How do these work? First the `=' sign at the beginning of the line +tells ledger this is an automatic transaction to be applied when the +condition following the `=' is true. After the `=' sign is a value +expression (@pxref{Value Expressions}) that returns true any time +a posting contains the commodity of interest. The following line gives the proportions (not percentages) of each unit of commodity that belongs to each asset class. Whenever Ledger sees a @@ -3785,7 +3906,9 @@ virtual accounts with that proportion of the number of shares moved. Now that Ledger understands how to distribute the commodities amongst the various asset classes how do we get a report that tells us our -current allocation? Using the balance command and some tricky formatting! +current allocation? Using the balance command and some tricky +formatting! + @smallexample ledger bal Allocation --current --format "\ %-17((depth_spacer)+(partial_account))\ @@ -3793,7 +3916,8 @@ ledger bal Allocation --current --format "\ %16(market(display_total))\n%/" @end smallexample -@noindent Which yields: +@noindent +Which yields: @smallexample Allocation 100.00% $100000.00 @@ -3815,11 +3939,11 @@ tree, using a special formatter. The magic is in the formatter. The second line simply tells Ledger to print the partial account name indented by its depth in the tree. The third line is where we calculate and display the percentages. The -@code{display_total} command give the values of the total calculated for -the account in this line. The @code{parent.total} command gives the -total for the next level up in the tree. @code{percent} formats their -ratio as a percentage. The fourth line tells ledger to display the -current market value of the line. The last two characters ``%/'' +@code{display_total} command give the values of the total calculated +for the account in this line. The @code{parent.total} command gives +the total for the next level up in the tree. @code{percent} formats +their ratio as a percentage. The fourth line tells ledger to display +the current market value of the line. The last two characters ``%/'' tell Ledger what to do for the last line, in this case, nothing. @node Visualizing with Gnuplot, , Asset Allocation, Advanced Reports @@ -3828,15 +3952,16 @@ tell Ledger what to do for the last line, in this case, nothing. @cindex plotting @cindex Gnuplot -If you have @command{Gnuplot} installed, you can graph any of the above -register reports. The script to do this is included in the ledger -distribution, and is named @file{contrib/report}. Install @file{report} -anywhere along your @env{PATH}, and then use @command{report} instead of -@command{ledger} when doing a register report. The only thing to keep -in mind is that you must specify @code{-j (--amount-data)} or -@code{-J (--total-data)} to indicate whether Gnuplot should plot the -amount, or the running total. For example, this command plots total -monthly expenses made on your MasterCard. +If you have @command{Gnuplot} installed, you can graph any of the +above register reports. The script to do this is included in the +ledger distribution, and is named @file{contrib/report}. Install +@file{report} anywhere along your @env{PATH}, and then use +@command{report} instead of @command{ledger} when doing a register +report. The only thing to keep in mind is that you must specify +@code{-j (--amount-data)} or @code{-J (--total-data)} to indicate +whether Gnuplot should plot the amount, or the running total. For +example, this command plots total monthly expenses made on your +MasterCard. @example report -j -M -r --display "account =~ /mastercard/" reg ^expenses @@ -3865,13 +3990,13 @@ report -J -l "Ua>=@{\$0.01@}" reg ^assets ^liab report -J -l "Ua>=@{\$0.01@}" -d "d>=[last feb]" reg ^assets ^liab @end smallexample -The last report uses both a calculation predicate (@code{-l}) and a -display predicate (@code{-d}). The calculation predicates limits -the report to postings whose amount is greater than $1 (which can -only happen if the posting amount is in dollars). The display -predicate limits the transactions @emph{displayed} to just those since last -February, even those transactions from before then will be computed as part -of the balance. +The last report uses both a calculation predicate (@code{-l}) and +a display predicate (@code{-d}). The calculation predicates limits +the report to postings whose amount is greater than $1 (which can only +happen if the posting amount is in dollars). The display predicate +limits the transactions @emph{displayed} to just those since last +February, even those transactions from before then will be computed as +part of the balance. @@ -3909,8 +4034,8 @@ separately. @subsection The @code{equity} Command The @command{equity} command prints out accounts balances as if they -were transactions. This makes it easy to establish the starting balances -for an account, such as when @ref{Archiving Previous Years}. +were transactions. This makes it easy to establish the starting +balances for an account, such as when @ref{Archiving Previous Years}. @node The register Command, The print Command, The equity Command, Primary Financial Reports @subsection The @code{register} Command @@ -3969,10 +4094,10 @@ file whose formatting has gotten out of hand. @node The csv command, The convert command, Comma Separated Variable files, Comma Separated Variable files @subsubsection The @code{csv} command -The @command{csv} command will output print out the desired ledger transactions in -a csv format suitable for import into other programs. You can specify -the transactions to print using all the normal limiting and searching -functions. +The @command{csv} command will output print out the desired ledger +transactions in a csv format suitable for import into other programs. +You can specify the transactions to print using all the normal +limiting and searching functions. @node The convert command, , The csv command, Comma Separated Variable files @subsubsection The @code{convert} command @@ -3980,20 +4105,21 @@ functions. @cindex reading csv @cindex comma separated variable file reading -The @code{convert} command parses a comma separated value -(csv) file and outputs Ledger transactions. Many banks offer csv file -downloads. Unfortunately, the file formats, aside the from commas, are -all different. The ledger @code{convert} command tries to help as much as it -can. +The @code{convert} command parses a comma separated value (csv) file +and outputs Ledger transactions. Many banks offer csv file downloads. +Unfortunately, the file formats, aside the from commas, are all +different. The ledger @code{convert} command tries to help as much as +it can. Your banks csv files will have fields in different orders from other -banks, so there must be a way to tell Ledger what to expect. Insert a -line at the beginning of the csv file that describes the fields to Ledger. +banks, so there must be a way to tell Ledger what to expect. Insert +a line at the beginning of the csv file that describes the fields to +Ledger. For example, this is a portion of a csv file downloaded from a credit union in the United States: -@smallexample +@smallexample Account Name: VALUFIRST CHECKING Account Number: 71 Date Range: 11/13/2011 - 12/13/2011 @@ -4013,12 +4139,15 @@ line of the file. The fields ledger can recognize are called @code{desc}'', ``@code{amount}'', ``@code{cost}'', ``@code{total}'', and ``@code{note}''. -Delete the account description lines at the top, and replace the first line in the data above with: +Delete the account description lines at the top, and replace the first +line in the data above with: + @smallexample ,date,payee,note,amount,,,code, @end smallexample Then execute ledger like this: + @smallexample ledger convert download.csv --input-date-format "%m/%d/%Y" @end smallexample @@ -4026,7 +4155,8 @@ ledger convert download.csv --input-date-format "%m/%d/%Y" Where the @code{--input-date-format} option tells ledger how to interpret the dates. -Importing csv files is a lot of work, and but is very amenable to scripting. +Importing csv files is a lot of work, and but is very amenable to +scripting. If there are columns in the bank data you would like to keep in your ledger data, besides the primary fields described above, you can name @@ -4040,23 +4170,23 @@ occurs in the first column of the data use: transid,date,payee,note,amount,,,code, @end smallexample -Ledger will include @code{; transid: 767718} in the first transaction is -from the file above. +Ledger will include @code{; transid: 767718} in the first transaction +is from the file above. The @code{convert} command accepts three options, the most important ones are @code{--invert} which inverts the amount field, and @code{--account NAME} which you can use to specify the account to -balance against and @code{--rich-data}. When using the rich-data switch -additional metadata is stored as tags. There is, for example, a UUID field. If -an entry with the same UUID tag is already included in the normal ledger -file (specified via @code{-f} or @code{$LEDGER_FILE}) this entry will not be printed -again. +balance against and @code{--rich-data}. When using the rich-data +switch additional metadata is stored as tags. There is, for example, +a UUID field. If an entry with the same UUID tag is already included +in the normal ledger file (specified via @code{-f} or +@code{$LEDGER_FILE}) this entry will not be printed again. You can also use @code{convert} with @code{payee} and @code{account} directives. First, you can use the @code{payee} and @code{alias} -directive to rewrite the @code{payee} field based on some rules. Then you can -use the account and its @code{payee} directive to specify the account. I use it -like this, for example: +directive to rewrite the @code{payee} field based on some rules. Then +you can use the account and its @code{payee} directive to specify the +account. I use it like this, for example: @smallexample payee Aldi @@ -4065,10 +4195,11 @@ account Aufwand:Einkauf:Lebensmittel payee ^(Aldi|Alnatura|Kaufland|REWE)$ @end smallexample -Note that it may be necessary for the output of @code{ledger convert} to be -passed through @code{ledger print} a second time if you want to match on the -new payee field. During the @code{ledger convert} run only the original payee -name as specified in the csv data seems to be used. +Note that it may be necessary for the output of @code{ledger convert} +to be passed through @code{ledger print} a second time if you want to +match on the new payee field. During the @code{ledger convert} run +only the original payee name as specified in the csv data seems to be +used. @node The lisp command, Emacs Org mode, Comma Separated Variable files, Reports in other Formats @subsection The @code{lisp} command @@ -4082,7 +4213,8 @@ directly by Emacs Lisp. The format of the @code{sexp} is: ...) ; list of transactions @end smallexample -@noindent @code{emacs} can also be used as a synonym for @code{lisp} +@noindent +@code{emacs} can also be used as a synonym for @code{lisp} @node Emacs Org mode, The pricemap Command, The lisp command, Reports in other Formats @subsection Emacs @code{org} Mode @@ -4093,16 +4225,16 @@ Emacs Org mode. More details on using Org mode can be found at Org mode has a sub-system known as Babel which allows for literate programming. This allows you to mix text and code within the same -document and automatically execute code which may generate results which -will then appear in the text. +document and automatically execute code which may generate results +which will then appear in the text. -One of the languages supported by @code{org+babel} is Ledger, so that you can -have ledger commands embedded in a text file and have the output of -ledger commands also appear in the text file. The output can be -updated whenever any new ledger entries are added. +One of the languages supported by @code{org+babel} is Ledger, so that +you can have ledger commands embedded in a text file and have the +output of ledger commands also appear in the text file. The output +can be updated whenever any new ledger entries are added. -For instance, the following Org mode text document snippet illustrates a -very naive but still useful of the @code{org+babel} system: +For instance, the following Org mode text document snippet illustrates +a very naive but still useful of the @code{org+babel} system: @smallexample * A simple test of ledger in an org file @@ -4148,16 +4280,18 @@ Using Babel, it is possible to record financial transactions conveniently in an org file and subsequently generate the financial reports required. -With a recent version of org (7.01+), Ledger support is provided. To use -it, enable Ledger support. Check the Babel documentation on Worg for -instructions on how to achieve this but I currently do this directly as -follows: +With a recent version of org (7.01+), Ledger support is provided. To +use it, enable Ledger support. Check the Babel documentation on Worg +for instructions on how to achieve this but I currently do this +directly as follows: + @smallexample (org-babel-do-load-languages 'org-babel-load-languages '((ledger . t) ;this is the important one for this tutorial )) @end smallexample + Once Ledger support in Babel has been enabled, we can use proceed to include Ledger entries within an org file. There are three ways (at least) in which these can be included: @@ -4165,8 +4299,8 @@ least) in which these can be included: @enumerate @item place all Ledger entries within one source block and execute - this block with different arguments to generate the appropriate - reports; + this block with different arguments to generate the + appropriate reports; @item place Ledger entries in more than one source block and use the noweb literary programming approach, supported by babel, to @@ -4298,19 +4432,20 @@ have been done individually. @subsubheading Financial Summaries Given the ledger entries defined above in the income and expenses code -blocks, we can now refer to these using the noweb expansion directives, -@code{<<name>>}. We can now define different code blocks to generate specific -reports for those transactions. Below are two examples, one to generate -a balance report and one to generate a register report of all -transactions. +blocks, we can now refer to these using the noweb expansion +directives, @code{<<name>>}. We can now define different code blocks +to generate specific reports for those transactions. Below are two +examples, one to generate a balance report and one to generate +a register report of all transactions. @subsubheading An overall balance summary The overall balance of your account and expenditure with a breakdown -according to category is specified by passing the :cmdline bal argument -to Ledger. This code block can now be evaluated (@code{C-c C-c}) and the -results generated by incorporating the transactions referred to by the -@code{<<income>>} and @code{<<expenses>>} lines. +according to category is specified by passing the :cmdline bal +argument to Ledger. This code block can now be evaluated (@code{C-c +C-c}) and the results generated by incorporating the transactions +referred to by the @code{<<income>>} and @code{<<expenses>>} lines. + @smallexample #+name: balance #+begin_src ledger :cmdline bal :noweb yes @@ -4325,8 +4460,9 @@ results generated by incorporating the transactions referred to by the @end smallexample If you want a more detailed breakdown of where your money is and where -it has been spent, you can specify the @code{-s} flag (i.e. @code{:cmdline -s bal}) to -tell Ledger to include sub-accounts in the report. +it has been spent, you can specify the @code{-s} flag +(i.e. @code{:cmdline -s bal}) to tell Ledger to include sub-accounts +in the report. @smallexample #+begin_src ledger :cmdline -s bal :noweb yes @@ -4349,10 +4485,11 @@ tell Ledger to include sub-accounts in the report. @subsubheading Generating a monthly register -You can also generate a monthly register (the reg command) by executing -the following src block. This presents a summary of transactions for -each monthly period (the @code{-M} argument) with a running total in the final -column (which should be 0 at the end if all the entries are correct). +You can also generate a monthly register (the reg command) by +executing the following src block. This presents a summary of +transactions for each monthly period (the @code{-M} argument) with +a running total in the final column (which should be 0 at the end if +all the entries are correct). @smallexample #+name: monthlyregister @@ -4402,8 +4539,8 @@ examples of more complex operations with a ledger. @node The pricemap Command, The xml Command, Emacs Org mode, Reports in other Formats @subsection The @code{pricemap} Command -If you have the @code{graphviz} graph visualization package installed, ledger -can generate a graph of the relationship between your various +If you have the @code{graphviz} graph visualization package installed, +ledger can generate a graph of the relationship between your various commodities. The output file is in the ``dot'' format. This is probably not very interesting, unless you have many different @@ -4523,8 +4660,8 @@ marker, and comma used as the decimal point. @end table The actual quantity for an amount is an integer of arbitrary size. -Ledger uses the GNU multiple precision arithmetic library to handle such -values. The XML format assumes the reader to be equally capable. +Ledger uses the GNU multiple precision arithmetic library to handle +such values. The XML format assumes the reader to be equally capable. Here is an example amount: @smallexample @@ -4570,9 +4707,9 @@ display the running average price, or @code{-D} to show each price's deviation from that average. There is also a @command{pricedb} command which outputs the same -information as @command{prices}, but does in a format that can be parsed -by Ledger. This is useful for generating and tidying up pricedb -database files. +information as @command{prices}, but does in a format that can be +parsed by Ledger. This is useful for generating and tidying up +pricedb database files. @node Reports about your Journals, , Reports in other Formats, Reporting Commands @@ -4590,15 +4727,17 @@ database files. @subsection @code{accounts} The @command{accounts} reports all of the accounts in the journal. -Following the command with a regular expression will limit the output to -accounts matching the regex. The output is sorted by name. Using the -@code{--count} option will tell you how many entries use each account. +Following the command with a regular expression will limit the output +to accounts matching the regex. The output is sorted by name. Using +the @code{--count} option will tell you how many entries use each +account. @node payees, commodities, accounts, Reports about your Journals @subsection @code{payees} -The @command{payees} reports all of the unique payees in the journal. To -filter the payees displayed you must use the prefix: +The @command{payees} reports all of the unique payees in the +journal. To filter the payees displayed you must use the prefix: + @smallexample macbook-2:$ ledger payees 'Tar.+t' El Dorade Restaurant @@ -4610,24 +4749,25 @@ macbook-2:$ @node commodities, tags, payees, Reports about your Journals @subsection @command{commodities} -Report all commodities present in the journals under consideration. The -output is sorted by name. Using the @code{--count} option will tell you -how many entries use each commodity. +Report all commodities present in the journals under consideration. +The output is sorted by name. Using the @code{--count} option will +tell you how many entries use each commodity. @node tags, entry and xact, commodities, Reports about your Journals @subsection @command{tags} The @command{tags} reports all of the tags in the journal. The output is sorted by name. Using the @code{--count} option will tell you how -many entries use each tag. Using the @code{--values} option will report -the values used by each tag. +many entries use each tag. Using the @code{--values} option will +report the values used by each tag. @node entry and xact, , tags, Reports about your Journals @subsection @command{draft}, @command{entry} and @command{xact} -The @code{draft}, @code{entry} and @command{xact} commands simplify the -creation of new transactions. It works on the principle that 80% of all -postings are variants of earlier postings. Here's how it works: +The @code{draft}, @code{entry} and @command{xact} commands simplify +the creation of new transactions. It works on the principle that 80% +of all postings are variants of earlier postings. Here's how it +works: Say you currently have this posting in your ledger file: @@ -4658,8 +4798,8 @@ This produces the following output: It works by finding a past posting matching the regular expression @code{viva}, and assuming that any accounts or amounts specified will be similar to that earlier posting. If Ledger does not succeed in -generating a new transaction, an error is printed and the exit code is set -to @code{1}. +generating a new transaction, an error is printed and the exit code is +set to @code{1}. Here are a few more examples of the @command{xact} command, assuming the above journal transaction: @@ -4712,16 +4852,19 @@ output to relate only to postings matching those regular expressions. For the @command{transaction} command, the arguments have a special meaning, described below. -The regular expressions arguments always match the account name that a -posting refers to. To match on the payee of the transaction instead, -precede the regular expression with @code{payee} or @@. For example, the -following balance command reports account totals for rent, food and -movies, but only those whose payee matches Freddie: +The regular expressions arguments always match the account name that +a posting refers to. To match on the payee of the transaction +instead, precede the regular expression with @code{payee} or @@. For +example, the following balance command reports account totals for +rent, food and movies, but only those whose payee matches Freddie: @smallexample ledger bal rent food movies payee freddie @end smallexample -@noindent or + +@noindent +or + @smallexample ledger bal rent food movies @@freddie @end smallexample @@ -4944,11 +5087,13 @@ their values and the source of those values, for example: -------------------- 0 @end smallexample -@noindent For the source column, a value starting with a @code{-} or -@code{--} indicated the source was a command line argument. It the -entry starts with a @code{$}, the source was an environment -variable. If the source is @code{?normalize} the value was set -internally by ledger, in a function called @code{normalize_options}. + +@noindent +For the source column, a value starting with a @code{-} or @code{--} +indicated the source was a command line argument. It the entry starts +with a @code{$}, the source was an environment variable. If the source +is @code{?normalize} the value was set internally by ledger, in +a function called @code{normalize_options}. @item --script <PATH> Execute a ledger script. @@ -4988,8 +5133,9 @@ Specify the input date format for journal entries. For example, ledger convert Export.csv --input-date-format "%m/%d/%Y" @end smallexample -Would convert the @file{Export.csv} file to ledger format, assuming the -dates in the CSV file are like 12/23/2009 (@pxref{Date and Time Format Codes}). +Would convert the @file{Export.csv} file to ledger format, assuming +the dates in the CSV file are like 12/23/2009 (@pxref{Date and Time +Format Codes}). @item --master-account <STRING> @@ -5022,19 +5168,20 @@ Prepend all account names with the argument. Specify the location of the price entry data file. @item --price-exp INTEGER_MINUTES -Set the expected freshness of price quotes, in minutes. That is, if the -last known quote for any commodity is older than this value, and if -@code{--download} is being used, then the Internet will be consulted again -for a newer price. Otherwise, the old price is still considered to be -fresh enough. +Set the expected freshness of price quotes, in minutes. That is, if +the last known quote for any commodity is older than this value, and +if @code{--download} is being used, then the Internet will be +consulted again for a newer price. Otherwise, the old price is still +considered to be fresh enough. @item --strict -Ledger normally silently accepts any account or commodity in a posting, -even if you have misspelled a common used one. The option +Ledger normally silently accepts any account or commodity in +a posting, even if you have misspelled a common used one. The option @code{--strict} changes that behavior. While running @code{--strict}, -Ledger interprets all cleared transactions as correct, and if it finds a -new account or commodity (same as a misspelled commodity or account) it -will issue a warning giving you the file and line number of the problem. +Ledger interprets all cleared transactions as correct, and if it finds +a new account or commodity (same as a misspelled commodity or account) +it will issue a warning giving you the file and line number of the +problem. @end table @node Report Options, Report Filtering, Session Options, Detailed Options Description @@ -5057,10 +5204,9 @@ than @code{account-width} then the account will be truncated on the left, with no shortening of the account names in order to fit into the desired width. @item --account <STR> -Prepend @code{<STR>} to all accounts -reported. That is, the option @code{--account Personal} would tack -@code{Personal:} to the beginning of every account reported in a balance -report or register report. +Prepend @code{<STR>} to all accounts reported. That is, the option +@code{--account Personal} would tack @code{Personal:} to the beginning +of every account reported in a balance report or register report. @item --account-width <INT> Set the width of the account column in @@ -5127,10 +5273,14 @@ value expression is true (@pxref{Value Expressions}). @smallexample ledger reg Expenses --begin Dec --bold-if "amount > 100" @end smallexample -@noindent list all transactions since the beginning of December and bold any posting greater than $100 + +@noindent +list all transactions since the beginning of December and bold any +posting greater than $100 @item --budget-format <FORMAT_STRING> -Specify the format to use for the @code{budget} report (@pxref{Format Strings}). The default is: +Specify the format to use for the @code{budget} report (@pxref{Format +Strings}). The default is: @smallexample "%(justify(scrub(display_total), 20, -1, true, color))" " %(!options.flat ? depth_spacer : \"\")" @@ -5223,9 +5373,9 @@ date column in the register report. ASK JOHN @item --dc -Display register or balance in debit/credit format -If you use @code{--dc} with either the register (reg) or balance (bal) commands, you -will now get extra columns. The register goes from this: +Display register or balance in debit/credit format If you use +@code{--dc} with either the register (reg) or balance (bal) commands, +you will now get extra columns. The register goes from this: @smallexample 12-Mar-10 Employer Assets:Cash $100 $100 Income:Employer $-100 0 @@ -5237,7 +5387,10 @@ will now get extra columns. The register goes from this: Expenses:Food $-5 $15 Assets:Cash $-15 0 @end smallexample -@noindent To this: + +@noindent +To this: + @smallexample 12-Mar-10 Employer Assets:Cash $100 0 $100 In:Employer 0 $100 0 @@ -5250,8 +5403,10 @@ will now get extra columns. The register goes from this: Assets:Cash 0 $15 0 @end smallexample -@noindent Where the first column is debits, the second is credits, and the third is the -running total. Only the running total may contain negative values. +@noindent +Where the first column is debits, the second is credits, and the third +is the running total. Only the running total may contain negative +values. For the balance report without @code{--dc}: @@ -5263,7 +5418,8 @@ For the balance report without @code{--dc}: 0 @end smallexample -@noindent And with @code{--dc} it becomes this: +@noindent +And with @code{--dc} it becomes this: @smallexample $105 $35 $70 Assets:Cash @@ -5275,11 +5431,11 @@ For the balance report without @code{--dc}: @item --depth <INT> -Limit the depth of the account tree. In a balance report, for example, -a @code{--depth 2} statement will print balances only for account with -two levels, i.e. @code{Expenses:Entertainment} but not -@code{Expenses:entertainemnt:Dining}. This is a display predicate, which -means it only affects display, not the total calculations. +Limit the depth of the account tree. In a balance report, for +example, a @code{--depth 2} statement will print balances only for +account with two levels, i.e. @code{Expenses:Entertainment} but not +@code{Expenses:entertainemnt:Dining}. This is a display predicate, +which means it only affects display, not the total calculations. @item --deviation Report each posting’s deviation from the average. It is only @@ -5301,7 +5457,9 @@ group transactions by the day of the week. @smallexample ledger reg Expenses --dow --collapse @end smallexample -@noindent will print all Expenses totaled for each day of the week. + +@noindent +will print all Expenses totaled for each day of the week. @item --effective Use effective dates for all calculations (@pxref{Effective Dates}). @@ -5349,8 +5507,8 @@ Use the given format string to print output. Report on gains using the latest available prices. @item --generated -Include auto-generated postings (such as those from automated transactions) -in the report, in cases where you normally wouldn't want +Include auto-generated postings (such as those from automated +transactions) in the report, in cases where you normally wouldn't want them. @item --group-by <EXPR> @@ -5360,9 +5518,9 @@ report. @code{EXPR} can be anything, although most common would be also useful here. @item --group-title-format -Set the format for the headers that -separate reports section of a grouped report. Only has effect with a -@code{--group-by} register report. +Set the format for the headers that separate reports section of +a grouped report. Only has effect with a @code{--group-by} register +report. @smallexample ledger reg Expenses --group-by "payee" --group-title-format "------------------------ %-20(value) ---------------------\n" ------------------------ 7-Eleven --------------------- @@ -5401,10 +5559,12 @@ Only transactions that satisfy the expression will be considered in the calculation. @item --lot-dates -Report the date on which each commodity in a balance report was purchased. +Report the date on which each commodity in a balance report was +purchased. @item --lot-prices -Report the price at which each commodity in a balance report was purchased. +Report the price at which each commodity in a balance report was +purchased. @item --lot-tags Report the tag attached to each commodity in a balance report. @@ -5413,16 +5573,19 @@ Report the tag attached to each commodity in a balance report. FIX THIS ENTRY @item --lots -Report the date and price at which each commodity was purchased in a balance report. +Report the date and price at which each commodity was purchased in +a balance report. @item --market Use the latest market value for all commodities. @item --meta <TAG> -In the register report, prepend the transaction with the value of the given tag. +In the register report, prepend the transaction with the value of the +given tag. @item --meta-width -Specify the width of the Meta column used for the @code{--meta} options. +Specify the width of the Meta column used for the @code{--meta} +options. @item --monthly Synonym for @code{--period "monthly"} @@ -5431,8 +5594,9 @@ Synonym for @code{--period "monthly"} suppress any color TTY output. @item --no-rounding -Don't output <Rounding> postings. Note that this will cause the running total -to often not add up! It's main use is for @code{-j} and @code{-J} reports. +Don't output <Rounding> postings. Note that this will cause the +running total to often not add up! It's main use is for @code{-j} and +@code{-J} reports. @item --no-titles Suppress the output of group titles @@ -5455,12 +5619,13 @@ Redirect the output of ledger to the file defined in @file{PATH}. Specify the pager program to use. @item --payee <VEXPR> -Sets a value expression for formatting the payee. In the register report -this prevents the second entry from having a date and payee for each -transaction +Sets a value expression for formatting the payee. In the register +report this prevents the second entry from having a date and payee for +each transaction @item --payee-width N -Set the number of columns dedicated to the payee in the register report. +Set the number of columns dedicated to the payee in the register +report. @item --pending Use only postings that are marked pending @@ -5480,7 +5645,8 @@ balances. Produce a balance pivot report ``around'' the given tag. For example, if you have multiple cars and track each fuel purchase in @code{Expenses:Auto:Fuel} and tag each fuel purchase with a tag -identifying which car the purchase was for @code{; Car: Prius}, then the command: +identifying which car the purchase was for @code{; Car: Prius}, then +the command: @smallexample ledger bal Fuel --pivot "Car" --period "this year" $ 3491.26 Car @@ -5495,10 +5661,12 @@ ledger bal Fuel --pivot "Car" --period "this year" @xref{Metadata values}. @item --plot-amount-format -Define the output format for an amount data plot. @xref{Visualizing with Gnuplot}. +Define the output format for an amount data plot. @xref{Visualizing +with Gnuplot}. @item --plot-total-format -Define the output format for a total data plot. @xref{Visualizing with Gnuplot}. +Define the output format for a total data plot. @xref{Visualizing with +Gnuplot}. @item --prepend-format STR Prepend STR to every line of the output @@ -5527,8 +5695,8 @@ transactions. @item --related-all -Show all postings in a transaction, similar to @code{--related} but show -both ``sides'' of each transaction. +Show all postings in a transaction, similar to @code{--related} but +show both ``sides'' of each transaction. @item --related In a register report show the related account. This is the other @@ -5544,7 +5712,8 @@ FIX THIS ENTRY FIX THIS ENTRY @item --seed -Set the random seed for the @code{generate} command. Used as part of development testing. +Set the random seed for the @code{generate} command. Used as part of +development testing. @item --sort-all FIX THIS ENTRY @@ -5564,7 +5733,8 @@ week. FIX THIS ENTRY @item --tail <INT> -Report only the last @code{INT} entries. Only useful on a register report. +Report only the last @code{INT} entries. Only useful on a register +report. @item --total-data FIX THIS ENTRY @@ -5598,7 +5768,8 @@ FIX THIS ENTRY FIX THIS ENTRY @item --unround -Perform all calculations without rounding and display results to full precision. +Perform all calculations without rounding and display results to full +precision. @item --weekly Synonym for @code{--period "weekly"} @@ -5617,8 +5788,8 @@ Synonym for @code{--period "yearly"} @subsection Basic options These are the most basic command options. Most likely, the user will -want to set them using environment variables (see @ref{Environment Variables}), -instead of using actual command-line options: +want to set them using environment variables (see @ref{Environment +Variables}), instead of using actual command-line options: @table @code @item --help @@ -5646,11 +5817,11 @@ goes to standard output. @item --init-file FILE @item -i FILE -Causes @code{FILE} to be read by ledger before any other ledger file. This -file may not contain any postings, but it may contain option settings. -To specify options in the init file, use the same syntax as the -command-line, but put each option on its own line. Here is an example -init file: +Causes @code{FILE} to be read by ledger before any other ledger file. +This file may not contain any postings, but it may contain option +settings. To specify options in the init file, use the same syntax as +the command-line, but put each option on its own line. Here is an +example init file: @smallexample --price-db ~/finance/.pricedb @@ -5703,9 +5874,9 @@ expressions, see @ref{Period Expressions}. @item --period-sort EXPR Sort the postings within each reporting period using the value -expression @var{EXPR}. This is most often useful when reporting monthly -expenses, in order to view the highest expense categories at the top of -each month: +expression @var{EXPR}. This is most often useful when reporting +monthly expenses, in order to view the highest expense categories at +the top of each month: @smallexample ledger -M --period-sort -At reg ^Expenses @@ -5734,11 +5905,12 @@ postings. @item --related @item -r -Display postings that are related to whichever postings would otherwise -have matched the filtering criteria. In the register report, this shows -where money went to, or the account it came from. In the balance -report, it shows all the accounts affected by transactions having a -related posting. For example, if a file had this transaction: +Display postings that are related to whichever postings would +otherwise have matched the filtering criteria. In the register +report, this shows where money went to, or the account it came from. +In the balance report, it shows all the accounts affected by +transactions having a related posting. For example, if a file had +this transaction: @smallexample 2004/03/20 Safeway @@ -5793,8 +5965,9 @@ Set the value expression used for the ``totals'' column in the @c ledger [OPTIONS] <COMMAND> <SEARCH-TERMS> @c @end smallexample -@c Where @code{COMMAND} is any command verb (@pxref{Reporting Commands}), @code{OPTIONS} can occur -@c anywhere, and @code{SEARCH-TERM} is one or more of the following: +@c Where @code{COMMAND} is any command verb (@pxref{Reporting +@c Commands}), @code{OPTIONS} can occur anywhere, and +@c @code{SEARCH-TERM} is one or more of the following: @c @smallexample @c word search for any account containing 'word' @@ -5818,9 +5991,9 @@ Set the value expression used for the ``totals'' column in the @c \( TERMS \) group terms; useful if using and/or/not @c @end smallexample -@c So, to list all transaction that charged to ``food'' but not ``dining'' -@c for any payee other than ``chang'' the following three commands would be -@c equivalent: +@c So, to list all transaction that charged to ``food'' but not +@c ``dining'' for any payee other than ``chang'' the following three +@c commands would be equivalent: @c @smallexample @c ledger reg food not dining @@chang @@ -5893,13 +6066,13 @@ Cause the default @command{register} report to assume 132 columns instead of 80. @item --head -Cause only the first @code{N} transactions to be printed. This is different -from using the command-line utility @command{head}, which would limit to -the first N postings. @code{--tail} outputs only the last @code{N} -transactions. Both options may be used simultaneously. If a negative -amount is given, it will invert the meaning of the flag (instead of the -first five transactions being printed, for example, it would print all -but the first five). +Cause only the first @code{N} transactions to be printed. This is +different from using the command-line utility @command{head}, which +would limit to the first N postings. @code{--tail} outputs only the +last @code{N} transactions. Both options may be used simultaneously. +If a negative amount is given, it will invert the meaning of the flag +(instead of the first five transactions being printed, for example, it +would print all but the first five). @item --pager Tell Ledger to pass its output to the given pager program; very useful @@ -5972,11 +6145,12 @@ initialization file @file{~/.ledgerrc} (or the file referred to by @item --format STR @item -F STR Set the reporting format for whatever report ledger is about to make. -@xref{Format Strings}. There are also specific format commands for each -report type: +@xref{Format Strings}. There are also specific format commands for +each report type: @item --balance-format STR -Define the output format for the @code{balance} report. The default (defined in @code{report.h} is: +Define the output format for the @code{balance} report. The default +(defined in @code{report.h} is: @smallexample "%(ansify_if( justify(scrub(display_total), 20, @@ -5990,6 +6164,7 @@ Define the output format for the @code{balance} report. The default (defined in %(prepend_width ? \" \" * int(prepend_width) : \"\") --------------------\n" @end smallexample + @item --cleared-format Define the format for the cleared report. The default is: @smallexample @@ -6003,8 +6178,10 @@ Define the format for the cleared report. The default is: %(prepend_width ? \" \" * int(prepend_width) : \"\") ---------------- ---------------- ---------\n" @end smallexample + @item --register-format STR -Define the output format for the @code{register} report. The default (defined in @code{report.h} is: +Define the output format for the @code{register} report. The default +(defined in @code{report.h} is: @smallexample "%(ansify_if( ansify_if(justify(format_date(date), int(date_width)), @@ -6050,16 +6227,21 @@ Set the format for @code{csv} reports. The default is: %(quoted(cleared ? \"*\" : (pending ? \"!\" : \"\"))), %(quoted(join(note | xact.note)))\n" @end smallexample + @item --plot-amount-format STR -Set the format for amount plots, using the @code{-j} option. The default is: +Set the format for amount plots, using the @code{-j} option. The +default is: @smallexample "%(format_date(date, \"%Y-%m-%d\")) %(quantity(scrub(display_amount)))\n" @end smallexample + @item --plot-total-format STR -Set the format for total plots, using the @code{-J} option. The default is: +Set the format for total plots, using the @code{-J} option. The +default is: @smallexample "%(format_date(date, \"%Y-%m-%d\")) %(quantity(scrub(display_total)))\n" @end smallexample + @item --pricedb-format STR Set the format expected for the historical price file. The default is @smallexample @@ -6072,6 +6254,7 @@ Set the format for the @command{prices} report. The default is: "%(date) %-8(display_account) %(justify(scrub(display_amount), 12, 2 + 9 + 8 + 12, true, color))\n" @end smallexample + @item --wide-register-format STR (-w @command{register}) @end table @@ -6095,9 +6278,10 @@ N $ N h @end smallexample -@noindent Note: Ledger NEVER writes output to files. You are responsible for -updating the price-db file. The best way is to have your price download -script maintain this file. +@noindent +Note: Ledger NEVER writes output to files. You are responsible for +updating the price-db file. The best way is to have your price +download script maintain this file. The format of the file can be changed by telling ledger to use the @code{--pricedb-format} you define. @@ -6154,8 +6338,8 @@ etc. When you specify @code{-V}, or @code{-X COMM}, you are requesting that some or all of the commodities be valuated as of today (or whatever @code{--now} is set to). But what does such a valuation mean? This -meaning is governed by the presence of a @code{VALUE} meta-data property, -whose content is an expression used to compute that value. +meaning is governed by the presence of a @code{VALUE} meta-data +property, whose content is an expression used to compute that value. If no VALUE property is specified, each posting is assumed to have a default, as if you'd specified a global, automated transaction as @@ -6183,8 +6367,8 @@ This says: If @code{--now} is some old date, use market prices as they were at that time; but if @code{--now} is past June 2008, use a fixed price for converting Deutsch Mark to Euro. -Or how about never re-valuating commodities used in Expenses, since they -cannot have a different future value: +Or how about never re-valuating commodities used in Expenses, since +they cannot have a different future value: @smallexample = /^Expenses:/ @@ -6228,10 +6412,10 @@ specific amounts and dates. Also, you should pass the amount along to the function 'market' so it can be further revalued if the user has asked for a specific currency. -Or, if it better suits your accounting, you can be less symbolic, which -allows you to report most everything in EUR if you use @code{-X EUR}, except -for certain accounts or postings which should always be valuated in -another currency. For example: +Or, if it better suits your accounting, you can be less symbolic, +which allows you to report most everything in EUR if you use @code{-X +EUR}, except for certain accounts or postings which should always be +valuated in another currency. For example: @smallexample = /^Assets:Brokerage:CAD$/ @@ -6249,26 +6433,26 @@ against itself. If @code{--lots} are not being displayed, then it will appear to balance against any lot of AAPL. @cindex adorned commodity -If you specify an adorned commodity, like AAPL @{$10.00@}, it will also -balance against itself, and against any AAPL if @code{--lots} is not -specified. But if you do specify @code{--lot-prices}, for example, then -it will balance against that specific price for AAPL. +If you specify an adorned commodity, like AAPL @{$10.00@}, it will +also balance against itself, and against any AAPL if @code{--lots} is +not specified. But if you do specify @code{--lot-prices}, for +example, then it will balance against that specific price for AAPL. -Normally when you use @code{-X <commodity>} to request that amounts be reported in a -specific commodity, Ledger uses these values: +Normally when you use @code{-X <commodity>} to request that amounts be +reported in a specific commodity, Ledger uses these values: @itemize @item Register Report - For the register report, use the value of that commodity on the date of - the posting being reported, with a <Revalued> posting added at the end of - today's value is different from the value of the last posting. +For the register report, use the value of that commodity on the date +of the posting being reported, with a <Revalued> posting added at the +end of today's value is different from the value of the last posting. @item Balance Report - For the balance report, use the value of that commodity as of today. +For the balance report, use the value of that commodity as of today. @end itemize -You can now specify @code{-H} to ask that all valuations for any amount be done -relative to the date that amount was encountered. +You can now specify @code{-H} to ask that all valuations for any +amount be done relative to the date that amount was encountered. You can also now use @code{-X} (and @code{-H}) in conjunction with @code{-B} and @code{-I}, to see valuation reports of just your basis @@ -6418,9 +6602,9 @@ payee. For example: Assets @end smallexample -These two period transactions give the usual monthly expenses, as well as -one typical yearly expense. For help on finding out what your average -monthly expense is for any category, use a command like: +These two period transactions give the usual monthly expenses, as well +as one typical yearly expense. For help on finding out what your +average monthly expense is for any category, use a command like: @example ledger -p "this year" --monthly --average --subtotal balance ^expenses @@ -6428,9 +6612,9 @@ ledger -p "this year" --monthly --average --subtotal balance ^expenses The reported totals are the current year's average for each account. -Once these period transactions are defined, creating a budget report is as -easy as adding @code{--budget} to the command-line. For example, a -typical monthly expense report would be: +Once these period transactions are defined, creating a budget report +is as easy as adding @code{--budget} to the command-line. For +example, a typical monthly expense report would be: @example ledger --monthly register ^expenses @@ -6458,8 +6642,8 @@ You can also use these flags with the @command{balance} command. Sometimes it's useful to know what your finances will look like in the future, such as determining when an account will reach zero. Ledger -makes this easy to do, using the same period transactions as are used for -budgeting. An example forecast report can be generated with: +makes this easy to do, using the same period transactions as are used +for budgeting. An example forecast report can be generated with: @example ledger --forecast "T>@{\$-500.00@}" register ^assets ^liabilities @@ -6487,22 +6671,24 @@ Ledger directly supports ``timelog'' entries, which have this form: o 2013/03/29 03:39:00 @end smallexample -This records a check-in to the given ACCOUNT, and a check-out. You can -be checked-in to multiple accounts at a time, if you wish, and they can -span multiple days (use @code{--day-break} to break them up in the -report). The number of seconds between is accumulated as time to that -ACCOUNT. If the checkout uses a capital ``O'', the transaction is marked -``cleared''. You can use an optional PAYEE for whatever meaning you like. +This records a check-in to the given ACCOUNT, and a check-out. You +can be checked-in to multiple accounts at a time, if you wish, and +they can span multiple days (use @code{--day-break} to break them up +in the report). The number of seconds between is accumulated as time +to that ACCOUNT. If the checkout uses a capital ``O'', the +transaction is marked ``cleared''. You can use an optional PAYEE for +whatever meaning you like. -Now, there are a few ways to generate this information. You can use the -@file{timeclock.el} package, which is part of Emacs. Or you can write a -simple script in whichever language you prefer to emit similar -information. Or you can use Org mode's time-clocking abilities and the -org2tc script developed by John Wiegley. +Now, there are a few ways to generate this information. You can use +the @file{timeclock.el} package, which is part of Emacs. Or you can +write a simple script in whichever language you prefer to emit similar +information. Or you can use Org mode's time-clocking abilities and +the org2tc script developed by John Wiegley. -These timelog entries can appear in a separate file, or directly in your -main ledger file. The initial ``i'' and ``o'' count as Ledger ``directives'', -and are accepted anywhere that ordinary transactions are. +These timelog entries can appear in a separate file, or directly in +your main ledger file. The initial ``i'' and ``o'' count as Ledger +``directives'', and are accepted anywhere that ordinary transactions +are. @@ -6527,9 +6713,8 @@ In the matching criteria used by automated postings. Value expressions support most simple math and logic operators, in addition to a set of functions and variables. -@c A function's -@c argument is whatever follows it. The following is a display predicate -@c that I use with the @command{balance} command: +@c A function's argument is whatever follows it. The following is +@c a display predicate that I use with the @command{balance} command: @c @smallexample @c ledger -d /^Liabilities/?T<0:UT>100 balance @@ -6762,8 +6947,8 @@ a posting, this will match against the account affected by the posting. @item c/REGEXP/ -A regular expression that matches against the transaction code (the text -that occurs between parentheses before the payee name). +A regular expression that matches against the transaction code (the +text that occurs between parentheses before the payee name). @item e/REGEXP/ A regular expression that matches against a posting's note, or @@ -6849,16 +7034,16 @@ Useful specifying a date in plain terms. For example, you could say @node Basics, Format String Structure, Format Strings, Format Strings @section Format String Basics -Format strings may be used to change the output format of reports. They -are specified by passing a formatting string to the @code{--format} -(@code{-F}) option. Within that string, constructs are allowed which -make it possible to display the various parts of an account or posting -in custom ways. +Format strings may be used to change the output format of reports. +They are specified by passing a formatting string to the +@code{--format} (@code{-F}) option. Within that string, constructs +are allowed which make it possible to display the various parts of an +account or posting in custom ways. -There are several additional flags that allow you to define formats for -specific reports. These are useful to define in your configuration file -and will allow you to run ledger reports from the command line without -having to enter a new format for each command. +There are several additional flags that allow you to define formats +for specific reports. These are useful to define in your +configuration file and will allow you to run ledger reports from the +command line without having to enter a new format for each command. @itemize @item @code{--balance-report} @@ -6950,10 +7135,10 @@ file. @item e Inserts the ending line of that transaction within the file. -@c @item D -@c By default, this is the same as @code{%[%Y/%m%/d]}. The date format -@c used can be changed at any time with the @code{-y} flag, however. Using -@c @code{%D} gives the user more control over the way dates are output. +@c @item D By default, this is the same as @code{%[%Y/%m%/d]}. The +@c date format used can be changed at any time with the @code{-y} +@c flag, however. Using @code{%D} gives the user more control over +@c the way dates are output. @item d Returns the date according to the default format. If the transaction @@ -6974,25 +7159,26 @@ parenthesis on the first line of the transaction. Inserts the payee related to a posting. @c @item a -@c Inserts the optimal short name for an account. This is normally used in -@c balance reports. It prints a parent account's name if that name has not -@c been printed yet, otherwise it just prints the account's name. +@c Inserts the optimal short name for an account. This is normally +@c used in balance reports. It prints a parent account's name if that +@c name has not been printed yet, otherwise it just prints the +@c account's name. @item A Inserts the full name of an account. @c @item W @c This is the same as @code{%A}, except that it first displays the -@c posting's state @emph{if the transaction's posting states are not all -@c the same}, followed by the full account name. This is offered as a -@c printing optimization, so that combined with @code{%Y}, only the minimum -@c amount of state detail is printed. +@c posting's state @emph{if the transaction's posting states are not +@c all the same}, followed by the full account name. This is offered +@c as a printing optimization, so that combined with @code{%Y}, only +@c the minimum amount of state detail is printed. @c @item o -@c Inserts the ``optimized'' form of a posting's amount. This is used by -@c the print report. In some cases, this inserts nothing; in others, it -@c inserts the posting amount and its cost. It's use is not recommended -@c unless you are modifying the print report. +@c Inserts the ``optimized'' form of a posting's amount. This is used +@c by the print report. In some cases, this inserts nothing; in +@c others, it inserts the posting amount and its cost. It's use is +@c not recommended unless you are modifying the print report. @item N @@ -7008,8 +7194,9 @@ same format string is used for all postings. @node --balance-format, Formatting codes, Format Expressions, Format Strings @section --balance-format -As an example of how flexible the @code{--format} strings can be, the default -balance format looks like this (the various functions are described later): +As an example of how flexible the @code{--format} strings can be, the +default balance format looks like this (the various functions are +described later): @smallexample "%(justify(scrub(display_total), 20, -1, true, color))" @@ -7144,7 +7331,9 @@ Two digit month Two digit date @end table -@noindent So @code{"%Y%m%d"} yields @code{20111214} which provides a date that is simple to sort on. +@noindent +So @code{"%Y%m%d"} yields @code{20111214} which provides a date that +is simple to sort on. @node Weekdays, Month, Days, Date and Time Format Codes @subsubsection Weekdays @@ -7160,7 +7349,8 @@ yields @code{02-10-2010 Wednesday} yields @code{Wednesday 02-10-2010} @end table -@noindent These are options you can select for weekday +@noindent +These are options you can select for weekday @table @code @item %a @@ -7182,7 +7372,8 @@ day of week starting with Sunday (0), i.e. @code{smtwtfs} 3 @node Month, Miscellaneous Date Codes, Date and Time Format Codes, Date and Time Format Codes @subsubsection Month -You can have additional month information in your date with @code{%B} as +You can have additional month information in your date with @code{%B} +as @table @code @item %m-%d-%Y %B @@ -7192,14 +7383,16 @@ yields @code{ 02-10-2010 February} yields @code{February 02-10-2010} @end table -@noindent These are options you can select for month +@noindent +These are options you can select for month @table @code @item %m @code{mm} month as two digits @item %b -Locale’s abbreviated month, for example @code{02} might be abbreviated as @code{Feb} +Locale’s abbreviated month, for example @code{02} might be abbreviated +as @code{Feb} @item %B Locale’s full month, variable length February @@ -7242,19 +7435,23 @@ The following format functions allow you limited formatting of text: @item ansify_if(value, color) Surrounds the string representing value with ANSI codes to give it @code{color} on an TTY display. Has no effect if directed to a file. + @item justify(value, first_width, latter_width, right_justify, colorize) Right or left justify the string representing @code{value}. The width of the field in the first line is given by @code{first_width}. For subsequent lines the width is given by @code{latterwidth}. If @code{latter_width=-1}, then @code{first_width} is use for all lines. -If @code{right_justify=true} then the field is right justify within the -width of the field. If it is @code{false}, then the field is left -justified and padded to the full width of the field. If @code{colorize} -is true then ledger will honor color settings. +If @code{right_justify=true} then the field is right justify within +the width of the field. If it is @code{false}, then the field is left +justified and padded to the full width of the field. If +@code{colorize} is true then ledger will honor color settings. + @item join(STR) Replaces line feeds in @code{STR} with @code{\n}. + @item quoted(STR) Return @code{STR} surrounded by double quotes, @code{"STR"}. + @item strip(value) Values can have numerous annotations, such as effective dates and lot prices. @code{strip} removes these annotations. @@ -7271,13 +7468,17 @@ generated the posting. @item filename name of ledger data file from whence posting came, abbreviated @code{S} @item beg_pos -character position in @code{filename} where entry for posting begins, abbreviated @code{B} +character position in @code{filename} where entry for posting begins, +abbreviated @code{B} @item end_pos -character position in @code{filename} where entry for posting ends, abbreviated @code{E} +character position in @code{filename} where entry for posting ends, +abbreviated @code{E} @item beg_line -line number in @code{filename} where entry for posting begins, abbreviated @code{b} +line number in @code{filename} where entry for posting begins, +abbreviated @code{b} @item end_line -line number in @code{filename} where posting's entry for posting ends, abbreviated @code{e} +line number in @code{filename} where posting's entry for posting ends, +abbreviated @code{e} @end table @@ -7285,9 +7486,9 @@ line number in @code{filename} where posting's entry for posting ends, abbreviat @node Extending with Python, Ledger for Developers, Format Strings, Top @chapter Extending with Python -Python can be used to extend your Ledger -experience. But first, a word must be said about Ledger's data model, so that -other things make sense later. +Python can be used to extend your Ledger experience. But first, +a word must be said about Ledger's data model, so that other things +make sense later. @menu * Basic data traversal:: @@ -7300,21 +7501,22 @@ other things make sense later. @node Basic data traversal, Raw vs. Cooked, Extending with Python, Extending with Python @section Basic data traversal -Every interaction with Ledger happens in the context of a Session. Even if -you don't create a session manually, one is created for you by the top-level -interface functions. The Session is where objects live like the Commodity's -that Amount's refer to. +Every interaction with Ledger happens in the context of a Session. +Even if you don't create a session manually, one is created for you by +the top-level interface functions. The Session is where objects live +like the Commodity's that Amount's refer to. -The make a Session useful, you must read a Journal into it, using the function -`@code{read_journal}`. This reads Ledger data from the given file, populates a -Journal object within the current Session, and returns a reference to that -Journal object. +The make a Session useful, you must read a Journal into it, using the +function `@code{read_journal}`. This reads Ledger data from the given +file, populates a Journal object within the current Session, and +returns a reference to that Journal object. -Within the Journal live all the Transaction's, Posting's, and other objects -related to your data. There are also AutomatedTransaction's and -PeriodicTransaction's, etc. +Within the Journal live all the Transaction's, Posting's, and other +objects related to your data. There are also AutomatedTransaction's +and PeriodicTransaction's, etc. Here is how you would traverse all the postings in your data file: + @smallexample import ledger @@ -7327,9 +7529,9 @@ Here is how you would traverse all the postings in your data file: @node Raw vs. Cooked, Queries, Basic data traversal, Extending with Python @section Raw vs. Cooked -Ledger data exists in one of two forms: raw and cooked. Raw objects are what -you get from a traversal like the above, and represent exactly what was seen -in the data file. Consider this journal: +Ledger data exists in one of two forms: raw and cooked. Raw objects +are what you get from a traversal like the above, and represent +exactly what was seen in the data file. Consider this journal: @smallexample = true @@ -7358,22 +7560,22 @@ While the @emph{cooked} form is: (Assets:Cash) $100 @end smallexample -So the easy way to think about raw vs. cooked is that raw is the unprocessed -data, and cooked has had all considerations applied. +So the easy way to think about raw vs. cooked is that raw is the +unprocessed data, and cooked has had all considerations applied. -When you traverse a Journal by iterating its transactions, you are generally -looking at raw data. In order to look at cooked data, you must generate a -report of some kind by querying the journal: +When you traverse a Journal by iterating its transactions, you are +generally looking at raw data. In order to look at cooked data, you +must generate a report of some kind by querying the journal: @smallexample for post in ledger.read_journal("sample.dat").query("food"): print "Transferring %s to/from %s" % (post.amount, post.account) @end smallexample -The reason why queries iterate over postings instead of transactions is that -queries often return only a ``slice'' of the transactions they apply to. You -can always get at a matching posting's transaction by looking at its ``xact'' -member: +The reason why queries iterate over postings instead of transactions +is that queries often return only a ``slice'' of the transactions they +apply to. You can always get at a matching posting's transaction by +looking at its ``xact'' member: @smallexample last_xact = None @@ -7385,19 +7587,21 @@ member: last_xact = post.xact @end smallexample -This query ends up reporting every cooked posting in the Journal, but does it -transaction-wise. It relies on the fact that an unsorted report returns -postings in the exact order they were parsed from the journal file. +This query ends up reporting every cooked posting in the Journal, but +does it transaction-wise. It relies on the fact that an unsorted +report returns postings in the exact order they were parsed from the +journal file. @node Queries, Embedded Python, Raw vs. Cooked, Extending with Python @section Queries -The Journal.query() method accepts every argument you can specify on the -command-line, including --options. +The Journal.query() method accepts every argument you can specify on +the command-line, including --options. -Since a query ``cooks'' the journal it applies to, only one query may be active -for that journal at a given time. Once the query object is gone (after the -for loop), then the data reverts back to its raw state. +Since a query ``cooks'' the journal it applies to, only one query may +be active for that journal at a given time. Once the query object is +gone (after the for loop), then the data reverts back to its raw +state. @node Embedded Python, Amounts, Queries, Extending with Python @section Embedded Python @@ -7420,16 +7624,17 @@ You can embed Python into your data files using the 'python' directive: Assets:Cash @end smallexample -Any Python functions you define this way become immediately available as -valexpr functions. +Any Python functions you define this way become immediately available +as valexpr functions. @node Amounts, , Embedded Python, Extending with Python @section Amounts -When numbers come from Ledger, like post.amount, the type of the value is -Amount. It can be used just like an ordinary number, except that addition -and subtraction are restricted to amounts with the same commodity. If you -need to create sums of multiple commodities, use a Balance. For example: +When numbers come from Ledger, like post.amount, the type of the value +is Amount. It can be used just like an ordinary number, except that +addition and subtraction are restricted to amounts with the same +commodity. If you need to create sums of multiple commodities, use +a Balance. For example: @smallexample total = Balance() @@ -7465,216 +7670,219 @@ Those tiers are: @itemize @item Utility code - There's lots of general utility in Ledger for doing time parsing, using - Boost.Regex, error handling, etc. It's all done in a way that can be - reused in other projects as needed. +There's lots of general utility in Ledger for doing time parsing, +using Boost.Regex, error handling, etc. It's all done in a way that +can be reused in other projects as needed. @item Commoditized Amounts (amount_t, commodity_t and friends) - An numerical abstraction combining multi-precision rational numbers (via - GMP) with commodities. These structures can be manipulated like regular - numbers in either C++ or Python (as Amount objects). +An numerical abstraction combining multi-precision rational numbers +(via GMP) with commodities. These structures can be manipulated like +regular numbers in either C++ or Python (as Amount objects). @item Commodity Pool - Commodities are all owned by a commodity pool, so that future parsing of - amounts can link to the same commodity and established a consistent price - history and record of formatting details. +Commodities are all owned by a commodity pool, so that future parsing +of amounts can link to the same commodity and established a consistent +price history and record of formatting details. @item Balances - Adds the concept of multiple amounts with varying commodities. Supports - simple arithmetic, and multiplication and division with non-commoditized - values. +Adds the concept of multiple amounts with varying commodities. +Supports simple arithmetic, and multiplication and division with +non-commoditized values. @item Price history - Amounts have prices, and these are kept in a data graph which the amount - code itself is only dimly aware of (there's three points of access so an - amount can query its revalued price on a given date). +Amounts have prices, and these are kept in a data graph which the +amount code itself is only dimly aware of (there's three points of +access so an amount can query its revalued price on a given date). @item Values - Often the higher layers in Ledger don't care if something is an amount or a - balance, they just want to add stuff to it or print it. For this, I - created a type-erasure class, value_t/Value, into which many things can be - stuffed and then operated on. They can contain amounts, balances, dates, - strings, etc. If you try to apply an operation between two values that - makes no sense (like dividing an amount by a balance), an error occurs at - runtime, rather than at compile-time (as would happen if you actually tried - to divide an @code{amount_t} by a @code{balance_t}). - - This is the core data type for the value expression language. - +Often the higher layers in Ledger don't care if something is an amount +or a balance, they just want to add stuff to it or print it. For +this, I created a type-erasure class, value_t/Value, into which many +things can be stuffed and then operated on. They can contain amounts, +balances, dates, strings, etc. If you try to apply an operation +between two values that makes no sense (like dividing an amount by +a balance), an error occurs at runtime, rather than at compile-time +(as would happen if you actually tried to divide an @code{amount_t} by +a @code{balance_t}). +This is the core data type for the value expression language. @item Value expressions - The next layer up adds functions and operators around the Value concept. - This lets you apply transformations and tests to Values at runtime without - having to bake it into C++. The set of functions available is defined by - each object type in Ledger (posts, accounts, transactions, etc.), though - the core engine knows nothing about these. At its base, it only knows how - to apply operators to values, and how to pass them to and receive them from - functions. +The next layer up adds functions and operators around the Value +concept. This lets you apply transformations and tests to Values at +runtime without having to bake it into C++. The set of functions +available is defined by each object type in Ledger (posts, accounts, +transactions, etc.), though the core engine knows nothing about these. +At its base, it only knows how to apply operators to values, and how +to pass them to and receive them from functions. @item Query expressions - Expressions can be onerous to type at the command-line, so there's a - shorthand for reporting called ``query expressions''. These add no - functionality of their own, but are purely translated from the input string - (cash) down to the corresponding value expression @code{(account =~ /cash/)}. - This is a convenience layer. +Expressions can be onerous to type at the command-line, so there's +a shorthand for reporting called ``query expressions''. These add no +functionality of their own, but are purely translated from the input +string (cash) down to the corresponding value expression +@code{(account =~ /cash/)}. This is a convenience layer. @item Format strings - Format strings let you interpolate value expressions into string, with the - requirement that any interpolated value have a string representation. - Really all this does is calculate the value expression in the current - report context, call the resulting value's @code{to_string()} method, and stuffs - the result into the output string. It also provides printf-like behavior, - such as min/max width, right/left justification, etc. +Format strings let you interpolate value expressions into string, with +the requirement that any interpolated value have a string +representation. Really all this does is calculate the value +expression in the current report context, call the resulting value's +@code{to_string()} method, and stuffs the result into the output +string. It also provides printf-like behavior, such as min/max width, +right/left justification, etc. @item Journal items - Next is a base type shared by anything that can appear in a journal: an - item_t. It contains details common to all such parsed entities, like what - file and line it was found on, etc. +Next is a base type shared by anything that can appear in a journal: +an item_t. It contains details common to all such parsed entities, +like what file and line it was found on, etc. @item Journal posts - The most numerous object found in a Journal, postings are a type of item - that contain an account, an amount, a cost, and metadata. There are some - other complications, like the account can be marked virtual, the amount - could be an expression, etc. +The most numerous object found in a Journal, postings are a type of +item that contain an account, an amount, a cost, and metadata. There +are some other complications, like the account can be marked virtual, +the amount could be an expression, etc. @item Journal transactions - Postings are owned by transactions, always. This subclass of item_t knows - about the date, the payee, etc. If a date or metadata tag is requested - from a posting and it doesn't have that information, the transaction is - queried to see if it can provide it. +Postings are owned by transactions, always. This subclass of item_t +knows about the date, the payee, etc. If a date or metadata tag is +requested from a posting and it doesn't have that information, the +transaction is queried to see if it can provide it. @item Journal accounts - Postings are also shared by accounts, though the actual memory is managed - by the transaction. Each account knows all the postings within it, but - contains relatively little information of its own. +Postings are also shared by accounts, though the actual memory is +managed by the transaction. Each account knows all the postings +within it, but contains relatively little information of its own. @item The Journal object - Finally, all transactions with their postings, and all accounts, are owned - by a @code{journal_t} object. This is the go-to object for querying ad reporting - on your data. +Finally, all transactions with their postings, and all accounts, are +owned by a @code{journal_t} object. This is the go-to object for +querying ad reporting on your data. @item Textual journal parser - There is a textual parser, wholly contained in textual.cc, which knows how - to parse text into journal objects, which then get ``finalized'' and added to - the journal. Finalization is the step that enforces the double-entry - guarantee. +There is a textual parser, wholly contained in textual.cc, which knows +how to parse text into journal objects, which then get ``finalized'' +and added to the journal. Finalization is the step that enforces the +double-entry guarantee. @item Iterators - Every journal object is ``iterable'', and these iterators are defined in - iterators.h and iterators.cc. This iteration logic is kept out of the - basic journal objects themselves for the sake of modularity. +Every journal object is ``iterable'', and these iterators are defined +in iterators.h and iterators.cc. This iteration logic is kept out of +the basic journal objects themselves for the sake of modularity. @item Comparators - Another abstraction isolated to its own layer, this class encapsulating the - comparison of journal objects, based on whatever value expression the user - passed to @code{--sort}. +Another abstraction isolated to its own layer, this class +encapsulating the comparison of journal objects, based on whatever +value expression the user passed to @code{--sort}. @item Temporaries - Many reports bring pseudo-journal objects into existence, like postings - which report totals in a @code{<Total>} account. These objects are created and - managed by a temporaries_t object, which gets used in many places by the - reporting filters. +Many reports bring pseudo-journal objects into existence, like +postings which report totals in a @code{<Total>} account. These +objects are created and managed by a temporaries_t object, which gets +used in many places by the reporting filters. @item Option handling - There is an option handling subsystem used by many of the layers further - down. It makes it relatively easy for me to add new options, and to have - those option settings immediately accessible to value expressions. +There is an option handling subsystem used by many of the layers +further down. It makes it relatively easy for me to add new options, +and to have those option settings immediately accessible to value +expressions. @item Session objects - Every journal object is owned by a session, with the session providing - support for that object. In GUI terms, this is the Controller object for - the journal Data object, where every document window would be a separate - session. They are all owned by the global scope. +Every journal object is owned by a session, with the session providing +support for that object. In GUI terms, this is the Controller object +for the journal Data object, where every document window would be +a separate session. They are all owned by the global scope. @item Report objects - Every time you create report output, a report object is created to - determine what you want to see. In the Ledger REPL, a new report object is - created every time a command is executed. In CLI mode, only one report - object ever comes into being, as Ledger immediately exits after displaying - the results. +Every time you create report output, a report object is created to +determine what you want to see. In the Ledger REPL, a new report +object is created every time a command is executed. In CLI mode, only +one report object ever comes into being, as Ledger immediately exits +after displaying the results. @item Reporting filters - The way Ledger generates data is this: it asks the session for the current - journal, and then creates an iterator applied to that journal. The kind of - iterator depends on the type of report. +The way Ledger generates data is this: it asks the session for the +current journal, and then creates an iterator applied to that journal. +The kind of iterator depends on the type of report. - This iterator is then walked, and every object yielded from the iterator is - passed to an ``item handler'', whose type is directly related to the type of - the iterator. +This iterator is then walked, and every object yielded from the +iterator is passed to an ``item handler'', whose type is directly +related to the type of the iterator. - There are many, many item handlers, which can be chained together. Each - one receives an item (post, account, xact, etc.), performs some action on - it, and then passes it down to the next handler in the chain. There are - filters which compute the running totals; that queue and sort all the input - items before playing them back out in a new order; that filter out items - which fail to match a predicate, etc. Almost every reporting feature in - Ledger is related to one or more filters. Looking at @code{filters.h}, I see over - 25 of them defined currently. +There are many, many item handlers, which can be chained together. +Each one receives an item (post, account, xact, etc.), performs some +action on it, and then passes it down to the next handler in the +chain. There are filters which compute the running totals; that queue +and sort all the input items before playing them back out in a new +order; that filter out items which fail to match a predicate, etc. +Almost every reporting feature in Ledger is related to one or more +filters. Looking at @code{filters.h}, I see over 25 of them defined +currently. @item The filter chain - How filters get wired up, and in what order, is a complex process based on - all the various options specified by the user. This is the job of the - chain logic, found entirely in @code{chain.cc}. It took a really long time to get - this logic exactly write, which is why I haven't exposed this layer to the - Python bridge yet. +How filters get wired up, and in what order, is a complex process +based on all the various options specified by the user. This is the +job of the chain logic, found entirely in @code{chain.cc}. It took +a really long time to get this logic exactly write, which is why +I haven't exposed this layer to the Python bridge yet. @item Output modules - Although filters are great and all, in the end you want to see stuff. This - is the job of special ``leaf'' filters call output modules. They are - implemented just like a regular filter, but they don't have a ``next'' filter - to pass the time on down to. Instead, they are the end of the line and - must do something with the item that results in the user seeing something - on their screen or in a file. +Although filters are great and all, in the end you want to see stuff. +This is the job of special ``leaf'' filters call output modules. They +are implemented just like a regular filter, but they don't have +a ``next'' filter to pass the time on down to. Instead, they are the +end of the line and must do something with the item that results in +the user seeing something on their screen or in a file. @item Select queries - Select queries know a lot about everything, even though they implement - their logic by implementing the user's query in terms of all the other - features thus presented. Select queries have no functionality of their - own, they are simple a shorthand to provide access to much of Ledger's - functionality via a cleaner, more consistent syntax. +Select queries know a lot about everything, even though they implement +their logic by implementing the user's query in terms of all the other +features thus presented. Select queries have no functionality of +their own, they are simple a shorthand to provide access to much of +Ledger's functionality via a cleaner, more consistent syntax. @item The Global Scope - There is a master object which owns every other objects, and this is - Ledger's global scope. It creates the other objects, provides REPL - behavior for the command-line utility, etc. In GUI terms, this is the - Application object. +There is a master object which owns every other objects, and this is +Ledger's global scope. It creates the other objects, provides REPL +behavior for the command-line utility, etc. In GUI terms, this is the +Application object. @item The Main Driver - This creates the global scope object, performs error reporting, and handles - command-line options which must precede even the creation of the global - scope, such as @code{--debug}. +This creates the global scope object, performs error reporting, and +handles command-line options which must precede even the creation of +the global scope, such as @code{--debug}. @end itemize -And that's Ledger in a nutshell. All the rest are details, such as which -value expressions each journal item exposes, how many filters currently exist, -which options the report and session scopes define, etc. +And that's Ledger in a nutshell. All the rest are details, such as +which value expressions each journal item exposes, how many filters +currently exist, which options the report and session scopes define, +etc. @node Journal File Format, Developer Commands, Internal Design, Ledger for Developers @section Journal File Format for Developers @@ -7735,9 +7943,9 @@ amount of the first posting is typically positive. Consider: @subsection Comments and meta-data Comments are generally started using a @code{;}. However, in order to -increase compatibility with other text manipulation programs and methods -three additional comment characters are valid if used at the beginning -of a line: @code{#}, @code{|}, and @code{*}. +increase compatibility with other text manipulation programs and +methods three additional comment characters are valid if used at the +beginning of a line: @code{#}, @code{|}, and @code{*}. @node Specifying Amounts, Posting costs, Comments and meta-data, Journal File Format @subsection Specifying Amounts @@ -7845,17 +8053,18 @@ in the same form as parsed. If you specify dollar amounts using @code{$100.000}. You may even use decimal commas, such as @code{$100,00}, or thousand-marks, as in @code{$10,000.00}. -These display characteristics become associated with the commodity, with -the result being that all amounts of the same commodity are reported -consistently. Where this is most noticeable is the @dfn{display -precision}, which is determined by the most precise value seen for a -given commodity---in most cases. +These display characteristics become associated with the commodity, +with the result being that all amounts of the same commodity are +reported consistently. Where this is most noticeable is the +@dfn{display precision}, which is determined by the most precise value +seen for a given commodity---in most cases. -Ledger makes a distinction between @dfn{observed amounts} and unobserved -amounts. An observed amount is critiqued by Ledger to determine how -amounts using that commodity should be displayed; unobserved amounts are -significant in their value only---no matter how they are specified, it -does not change how other amounts in that commodity will be displayed. +Ledger makes a distinction between @dfn{observed amounts} and +unobserved amounts. An observed amount is critiqued by Ledger to +determine how amounts using that commodity should be displayed; +unobserved amounts are significant in their value only---no matter how +they are specified, it does not change how other amounts in that +commodity will be displayed. An example of this is found in cost expressions, covered next. @@ -7992,8 +8201,9 @@ slowdown. When combined with @code{--debug} ledger will produce memory trace information. @item --debug "argument" -If Ledger has been built with debug options this will provide extra data -during the run. The following are the available arguments to debug: +If Ledger has been built with debug options this will provide extra +data during the run. The following are the available arguments to +debug: @multitable @columnfractions .32 .43 .27 @item @code{account.display} @tab @code{expr.calc.when} @tab @code{org.next_amount} @@ -8075,8 +8285,8 @@ it against a model transaction. Print details of how ledger uses the given formatting description and apply it against a model transaction. @item generate -Randomly generates syntactically valid Ledger data from a seed. Used by the -GenerateTests harness for development testing +Randomly generates syntactically valid Ledger data from a seed. Used +by the GenerateTests harness for development testing @item parse <VALUE EXPR> Print details of how ledger uses the given value expression description and apply it against a model transaction. @@ -8100,9 +8310,10 @@ END_REACHED: <EOF> --- Sample dates in range (max. 20) --- 1: 11-Jan-01 @end smallexample + @item query -Evaluate the given query and report how Ledger interprets it against the -model transaction: +Evaluate the given query and report how Ledger interprets it against +the model transaction: @smallexample 20:25:42 ~/ledger (next)> ledger query "/Book/" @@ -8140,8 +8351,8 @@ model transaction: true @end smallexample @item template -Shows the insertion template that a @code{draft} or @code{xact} sub-command generates. -This is a debugging command. +Shows the insertion template that a @code{draft} or @code{xact} +sub-command generates. This is a debugging command. @end table @node Ledger Development Environment, , Developer Commands, Ledger for Developers @@ -8164,8 +8375,8 @@ individually with @code{ctest}. All tests can be run using @code{make check} or @code{ninja check} depending on which build tool you prefer. Once built, the ledger executable resides under the @file{build} -subdirectory in the source tree. Tests are built and stored in the test -subdirectory for the build. For example, +subdirectory in the source tree. Tests are built and stored in the +test subdirectory for the build. For example, @file{~/ledger/build/ledger/opt/test}. @menu @@ -8180,17 +8391,18 @@ subdirectory for the build. For example, The complete test sweet can be run from the build directory using the check option for the build tool you use. For example, @code{make check}. The entire test suit lasts around a minute for the optimized -built and many times longer for the debug version. While developing and -debugging, running individual tests can save a great deal of time. +built and many times longer for the debug version. While developing +and debugging, running individual tests can save a great deal of time. Individual tests can be run from the @file{test} subdirectory of the build location. To execute a single test use @code{ctest -V -R regex}, where the regex matches the name of the test you want to build. There are nearly 300 tests stored under the @file{test} subdirectory -in main source distribution. They are broken into two broad categories, -baseline and regression. To run the @file{5FBF2ED8} test, for example, -issue @code{ctest -V -R "5FB"}. +in main source distribution. They are broken into two broad +categories, baseline and regression. To run the @file{5FBF2ED8} test, +for example, issue @code{ctest -V -R "5FB"}. + @node Writing Tests, , Running Tests, Testing Framework @subsubsection Writing Tests @@ -8280,7 +8492,8 @@ features, include automatic and virtual transactions, @node Miscellaneous Notes, Concept Index, Example Data File, Top @appendix Miscellaneous Notes -Various notes from the discussion list that I haven't incorporated in to the main body of the documentation. +Various notes from the discussion list that I haven't incorporated in +to the main body of the documentation. @menu * Cookbook:: @@ -8303,6 +8516,7 @@ ledger register Checking --sort d -d 'd>[2011/04/01]' until 2011/05/25 @node Ledger Files, , Cookbook, Cookbook @subsection Ledger Files + @smallexample = /^Income:Taxable/ (Liabilities:Tithe Owed) -0.1 |