Eric Abrahamsen <e...@ericabrahamsen.net> writes:

> Michael Brand <michael.ch.br...@gmail.com> writes:
>
>> Hi Eric
>>
>> On Wed, Dec 17, 2014 at 2:09 AM, Eric Abrahamsen
>> <e...@ericabrahamsen.net> wrote:
>>> Lastly, is there a way to both use output formatting, and retain the
>>> unit name (if desired)? Right now I get this:
>>>
>>> | km    | units | conversion |
>>> |-------+-------+------------|
>>> | 2.5km | ft    |    8202.10 |
>>> #+TBLFM: $3=uconvert($1, $2); %.2f
>>>
>>> Ie, the "ft" falls off the results when I add the "%.2f". Is it possible
>>> to retain that and have formatting?
>>
>> Yes, see
>> "org-spreadsheet: formatting chops off units"
>> http://thread.gmane.org/gmane.emacs.orgmode/59928
>
> I'm certainly late to this party! My only excuse is that it's far from
> obvious, given the current manual, that all this is available (even
> after your documentation patch in the referenced thread).
>
> Just to note, the second of the two formatting solutions you mentioned
> (manually adding the units as a string) seems to no longer work. The
> first does, however.
>
> I'll work up a slightly longer documentation patch in the next couple of
> days -- I really think people should be alerted to what's possible with
> units. The "uconvert" defmath could even just be an example in the
> manual, rather than code that ships with Org.

Here's the doc patch, hope all is in order.

Eric

>From da8e9914d4f63cb3bfa6e7beacd8ee762044b2e6 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <e...@ericabrahamsen.net>
Date: Thu, 18 Dec 2014 18:04:00 +0800
Subject: [PATCH] Mention calc-units in the spreadsheet documentation

* doc/org.texi: Outline using units in tables, link to appropriate
  part of the Calc manual.
---
 doc/org.texi | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/doc/org.texi b/doc/org.texi
index 7c464ca..aae0537 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -2756,6 +2756,26 @@ should be padded with 0 to the full size.
 You can add your own Calc functions defined in Emacs Lisp with @code{defmath}
 and use them in formula syntax for Calc.
 
+Calc also comes with support for unit calculations, via the @code{calc-units}
+package.  For a complete list of recognized units, call
+@code{calc-view-units-table}.  Units can be specified with or without a space
+between the number and the unit name, eg @samp{2 ft} is the same as
+@samp{2ft}.  Rates are handled automatically: multiplying @samp{3 m/s} by two
+will give @samp{6 m / s}.  By default, @code{calc-units} only defines one
+units-related function for use in tables, @code{usimplify}, which can take an
+expression such as @samp{42 km / 2.5 h} and return @samp{16.8 km / hr}.
+Another useful function to define might be @code{math-convert-units}, eg:
+
+@example
+(defmath uconv (expr target-units &optional pure)
+  (math-convert-units expr target-units pure))
+@end example
+
+Which would allow you to use @samp{uconv($1, ft)} to, for example, convert a
+distance specified in the cell @samp{$1} into feet.  The optional 'pure
+argument strips the units designator from the number in the results.
+@xref{Units, Operating on Units,,calc}.
+
 @node Formula syntax for Lisp
 @subsection Emacs Lisp forms as formulas
 @cindex Lisp forms, as table formulas
-- 
2.2.0

Reply via email to