emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] getting calc-units working in table formulas
Date: Sun, 21 Dec 2014 12:22:54 +0800	[thread overview]
Message-ID: <871tntein5.fsf@ericabrahamsen.net> (raw)
In-Reply-To: 87r3vuz3g8.fsf@nicolasgoaziou.fr

[-- Attachment #1: Type: text/plain, Size: 1373 bytes --]

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> Eric Abrahamsen <eric@ericabrahamsen.net> 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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Mention-calc-units-in-the-spreadsheet-documentation.patch --]
[-- Type: text/x-diff, Size: 1909 bytes --]

From e8979feb063868c3b91b384072e2b790917e6054 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@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 | 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


      reply	other threads:[~2014-12-21  4:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-16  4:21 getting calc-units working in table formulas Eric Abrahamsen
2014-12-16  6:33 ` Eric Abrahamsen
2014-12-16 13:06 ` Michael Brand
2014-12-17  1:09   ` Eric Abrahamsen
2014-12-17  6:39     ` Michael Brand
2014-12-17  7:02       ` Eric Abrahamsen
2014-12-18 10:07         ` [PATCH] " Eric Abrahamsen
2014-12-20 16:33           ` Nicolas Goaziou
2014-12-21  4:22             ` Eric Abrahamsen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871tntein5.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).