From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: [PATCH] getting calc-units working in table formulas Date: Sun, 21 Dec 2014 12:22:54 +0800 Message-ID: <871tntein5.fsf@ericabrahamsen.net> References: <87oar4ql5t.fsf@ericabrahamsen.net> <87egrznl9e.fsf@ericabrahamsen.net> <87d27ioj1j.fsf@ericabrahamsen.net> <87vbl9qnin.fsf_-_@ericabrahamsen.net> <87r3vuz3g8.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2XxL-0007lL-87 for emacs-orgmode@gnu.org; Sat, 20 Dec 2014 23:17:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y2XxF-0002vG-OE for emacs-orgmode@gnu.org; Sat, 20 Dec 2014 23:17:23 -0500 Received: from plane.gmane.org ([80.91.229.3]:35743) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2XxF-0002vA-GP for emacs-orgmode@gnu.org; Sat, 20 Dec 2014 23:17:17 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Y2XxD-0007Ut-CX for emacs-orgmode@gnu.org; Sun, 21 Dec 2014 05:17:15 +0100 Received: from 123.123.16.212 ([123.123.16.212]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Dec 2014 05:17:15 +0100 Received: from eric by 123.123.16.212 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Dec 2014 05:17:15 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Nicolas Goaziou writes: > Hello, > > Eric Abrahamsen writes: > >> Here's the doc patch, hope all is in order. > > Thanks. Some comments follow. > >> +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 > > "eg" -> "e.g.," > >> +@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: > > Ditto. > >> +@example >> +(defmath uconv (expr target-units &optional pure) >> + (math-convert-units expr target-units pure)) >> +@end example > > I think you should use @lisp instead of @example here. > >> +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 > > @code{pure} instead of 'pure Thanks for the notes -- here's another version. Eric --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Mention-calc-units-in-the-spreadsheet-documentation.patch >From e8979feb063868c3b91b384072e2b790917e6054 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen 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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/doc/org.texi b/doc/org.texi index 33a6a0d..d8a5785 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -2758,6 +2758,27 @@ 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, e.g., @samp{2 ft} is equivalent to +@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 table formulas, @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}, +e.g.: + +@lisp +(defmath uconv (expr target-units &optional pure) + (math-convert-units expr target-units pure)) +@end lisp + +Which would allow you to use @samp{uconv($1, ft)} in table formulas to, for +example, convert a distance specified in cell @samp{$1} into feet. The +optional @code{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.1 --=-=-=--