emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Eric Schulte" <schulte.eric@gmail.com>
To: Matthew Oesting <oestingm@me.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Possible Calc support for Org-Babel?
Date: Tue, 26 Oct 2010 12:37:35 -0600	[thread overview]
Message-ID: <87mxq0ajgw.fsf@gmail.com> (raw)
In-Reply-To: <7CDB7386-9B39-46CB-94E8-C6B5CBD59C4F@me.com> (Matthew Oesting's message of "Fri, 22 Oct 2010 13:17:28 -0400")

Hi Matthew,

Matthew Oesting <oestingm@me.com> writes:

> A few of us at my institution have started using CALC in our documents
> (not embedded, which is far too clumsy for most of us, but C-x * u and
> simple embedded phrases, often to the tune of several pages) to use
> Emacs text files rather like Maple and Mathematica files.  We're
> starting to use GIT and OrgMode together to format the work and save
> versions and forks; while there are many CAS packages that can be used
> to write out memos and reports, the power of Elisp/Emacs was simply
> too good to pass up.
>
> It appears that Calc syntax can be used to assign formulas to
> spreadsheets, but the result is difficult to read, and unsuitable for
> a sequence of several dozen lines.  Similarly, using embedded
> Ruby-symbolic code in the text produces excellent results, but we lose
> the ability to take advantage of Calc, which is significantly stronger
> for our purposes.  Other symbolic packages require more time to learn
> and are difficult to implement across all of our various platforms,
> whereas Calc is a universal and extremely flexible tool for this work.
>
> My questions are these:
>   * Has there been implemented, or would it be at all difficult to
>   implement, a 'calc' language functionality for Org-Babel allowing
>   the following manner of text:
>

A Calc language has not yet been implemented, however (although I'd have
to look at Calc's support for running series of commands) I do not think
it would be difficult to implement such functionality.  In fact I think
this is a very good idea.

If you're feeling brave, it may make sense to look at a couple of the
shorter examples of languages supported by Babel (e.g. ob-dot.el) and
try to adapt their functions for working with Calc as you describe below
(see below for more information on implementing a calc interface).

>
>> #+begin_src calc :results output 
>> Fish = 2
>> Dog = 2 * Fish
>> 
>> sqrt( Dog ) =>
>> sqrt( 4 ) =>
>> #+end_src
>> 
>> #+results:
>> : sqrt( Dog ) => 2
>> : sqrt( 4 ) = 2
>
> The goal of this exercise would simply be to cut out the text from the
> code block, feed it to a buffer, run the Emacs Calc mode on it, and
> then output the appropriate results where => occurs.
>

Although I'm not familiar with using Calc as anything more than a 1-off
calculator in the bottom of the frame (i.e. M-x calc) this sounds like a
good approach to using calc to execute code blocks.

>
>  * Has there been implemented, or would it be at all difficult to
>  implement, a 'running tag' approach to the Calc mode, essentially a
>  #+CALC directive allowing the following manner of text, preferably
>  with auto-update:
>
>> This is a discussion.
>>
>> #+CALC: Fish = 2
>>
>> Fish deserves significant commentary; however, we expect that there
>> is some command that would allow us to update the entire buffer's
>> #+CALC sequence.  Thus:
>> 
>> #+CALC: Dog = 2 * Fish
>> #+CALC: sqrt( Dog ) =>
>> #+results:
>> : sqrt( Dog ) => 2
>>
>> If you need a different result, tweak the 'Fish =' line, above, and
>> request a re-sequencing, either via C-c C-c or via some M-x command,
>> resulting in behavior functionally similar to C-x * u.
>

I believe this may be much more easily implemented using the "session"
features of Org-mode code blocks, possibly in combination with the
inline code block syntax.  Please see [1] for much more information on
working with code blocks in Org-mode.

>
> The goal of this exercise would be, upon updating, to strip all lines
> beginning with #+CALC and feed them to a buffer, inserting the results
> of => statements where the respective line occurs.  The benefit of
> this method over the previous is that it allows for assignments (:=)
> enduring across entire files (though the same could be accomplished if
> one SRC_BEGIN block could somehow call another.)
>

It is currently possible for one source block to call another, see the
chapter of the manual linked above for details.

>
> In conclusion, it seems to me that I cannot possibly be the first
> person to have done research in OrgMode, and that these problems were
> likely solved long ago.  When searching the manual, however, I find
> nothing that produces a distinctly clear and encapsulated Calc embed
> in OrgMode.

You are certainly not the first to use Org-mode as a research platform,
however you may be the first calc power-user to attempt to combine calc
with Org-mode.

> Do these exist, and if not, would it require mere hours of time to
> implement them, or weeks?  Is there a tutorial on writing OrgMode
> extensions?
>

Using the Babel code block support I would anticipate that this would
take more on the order of hours rather than weeks (assuming some elisp
fluency).  See the existing template file for adding support for a new
language to Org-mode.

http://repo.or.cz/w/Worg.git/blob/HEAD:/org-contrib/babel/ob-template.el

This process should be significantly simplified by the fact that Calc is
an Emacs command (rather than an external utility).

I would be happy to help you in implementing an ob-calc.el file, and if
I find time I may take a stab at it myself.

Best -- Eric

>
> - M
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

Footnotes: 
[1]  http://orgmode.org/manual/Working-With-Source-Code.html#Working-With-Source-Code

  reply	other threads:[~2010-10-26 18:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-22 17:17 Possible Calc support for Org-Babel? Matthew Oesting
2010-10-26 18:37 ` Eric Schulte [this message]
2010-10-29  6:42   ` Eric Schulte
2010-10-29  7:13     ` Carsten Dominik
2010-10-29 11:14     ` Eric S Fraga
2010-10-29 14:43       ` Eric Schulte
2010-10-29 16:22         ` Eric Schulte
2010-10-29 19:53         ` Eric S Fraga
2010-10-29 20:26           ` Eric Schulte
     [not found]             ` <87hbg4pooh.fsf@ucl.ac.uk>
     [not found]               ` <871v7879x5.fsf@gmail.com>
2010-10-30 20:54                 ` Eric S Fraga
2010-11-03 20:10                   ` Eric Schulte
2010-10-29 11:27     ` Sébastien Vauban
2010-10-29 14:46       ` Eric Schulte
  -- strict thread matches above, loose matches on Subject: below --
2010-11-03 22:42 Eric S Fraga
2010-11-04 13:24 ` Eric Schulte
2010-11-04 14:13   ` Eric S Fraga
2010-11-04 14:42   ` Sébastien Vauban
2010-11-04 15:33     ` Eric Schulte
2010-11-04 16:02       ` Sébastien Vauban
2011-01-27  0:39   ` Christopher Allan Webber
2011-02-23  4:35     ` Eric Schulte
2011-02-24 10:13       ` Eric S Fraga
2011-02-27 21:32         ` Eric Schulte
2011-02-28 18:16           ` Eric S Fraga
2011-03-01 17:34             ` Eric Schulte
2011-03-01 20:10               ` Eric S Fraga
2011-03-07  9:16               ` Eric S Fraga
2011-03-01 20:48 orgmode

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=87mxq0ajgw.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=oestingm@me.com \
    /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).