Skip to Content

Quick and dirty PDF reports for Plain Text Accounting

Say you want to hand out financial reports (such as a balance sheet and an income statement) to a non-techie someone. Most likely that means handing out the statements on paper. Given that I’m doing Plain Text Accounting, what is an easy way to generate decent looking output on paper?

hledger has two convenient commands to generate a balance sheet and an income statement. Let’s use the demo.journal from the hledger web site as an example for this:

$ hledger balancesheet -f demo.journal --empty --value
Balance Sheet 2017/12/31-2020/03/06

                   ||    2020/03/06
===================++===============
 Assets            ||
-------------------++---------------
 Asset             || 52,661.92 USD
   Cash            ||    300.00 USD
   Bank            || 25,336.71 USD
     JP Morgan     || 22,651.48 USD
     Weels Fargo   ||  2,275.23 USD
     Wells Fargo   ||    410.00 USD
   Online Account  ||    125.21 USD
     Apple Pay     ||     41.97 USD
     Paypal        ||     83.24 USD
   Stocks          || 26,900.00 USD
     JP Morgan     || 26,900.00 USD
-------------------++---------------
                   || 52,661.92 USD
===================++===============
 Liabilities       ||
-------------------++---------------
 Liabilities       ||             0
   Credit Card     ||             0
     Visa Platinum ||             0
-------------------++---------------
                   ||             0
===================++===============
 Net:              || 52,661.92 USD

And similarly for the income statement

$ hledger incomestatement -f demo.journal
Income Statement 2017/12/31-2020/03/06

                                || 2017/12/31-2020/03/06
================================++=======================
 Revenues                       ||
--------------------------------++-----------------------
 Revenue:Capital Gain in stocks ||            300.00 USD
 Revenue:Fx Revenue             ||            213.00 USD
 Revenue:Riding App             ||            300.00 USD
 Revenue:Salary                 ||         21,600.00 USD
--------------------------------++-----------------------
                                ||         22,413.00 USD
================================++=======================
 Expenses                       ||
--------------------------------++-----------------------
 Expenses:Car:Gas               ||             78.37 USD
 Expenses:Clothing              ||         -1,944.00 USD
 Expenses:Housing:Maintenance   ||           -110.00 USD
 Expenses:Housing:Property Tax  ||            300.00 USD
 Expenses:Housing:Rental        ||          5,850.00 USD
 Expenses:Leisure:Events        ||            275.00 USD
 Expenses:Leisure:Travel        ||          2,678.00 USD
 Expenses:Products:Clothing     ||             80.00 USD
 Expenses:Products:Food         ||          1,148.33 USD
--------------------------------++-----------------------
                                ||          8,355.70 USD
================================++=======================
 Net:                           ||         14,057.30 USD

This is all fine and dandy, but how do I get this to print out nicely?

Export the report as CSV (using the -O csv option) and then perform some magic to convert this to LaTeX? People have apparently done this using the pgfplotstable package.

Another method would be to generate HTML with the -O html option, style the result and hope that it prints out half decently.

Yet another quick hack involves pandoc to convert the tables to LaTeX:

$ hledger balancesheet -f demo.journal -O html | pandoc -f html -t latex

Unfortunately pandoc doesn’t seem to recognize the table in the html output and doesn’t convert them to LaTeX tables.

Instead I propose a simpler and admittedly dirtier method: Create an org-mode file that contains the auxiliary text around the reports. Then generate the reports using an org-mode source code block. The csv output is converted to an org-mode table which in the end will be exported to a neatly formatted LaTeX table.

#+BEGIN_SRC shell :exports results
hledger balancesheet -f demo.journal -O csv --empty --value
#+END_SRC

Make sure you use the booktabs package for good looking LaTeX tables and optionally the siunitx package to align the numbers nicely1.

Then use the org-mode export facilities to generate a LaTeX file2. Enhance the result as you wish, for example you most likely will add some horizontal lines using \toprule, \midrule and \bottomrule, possibly you will remove some superfluous lines from the csv export, maybe you’ll change the names of some of the top-level accounts to your locale and quite likely you’ll trim the empty columns3.

I admit this approach is hackish and bites you if you do the conversion often. However if you consider that you’ll probably be doing the financial reports only once a year, IMHO this doesn’t justify the effort to pack this up into a script.

For more details have a look at the complete org-mode file, the generated LaTeX file and the drop dead gorgeous PDF output.


  1. siunitx comes with a new column type, the S column. That lets you do things like \begin{tabular}{lS} and have the numbers align on the decimal point. For me this worked great as long as no currencies were involved. As the output does contain currencies and I didn’t want to remove them I dropped the use of siunitx. ↩︎

  2. by typing C-c C-e l l (in case your muscle memory is failing you). ↩︎

  3. The csv export has a small bug in that it creates a few empty columns that need to be cleaned. Thanks to Simon Michael the bug has been fixed in master. ↩︎