*Multiple calc commands with orgbabel@ 2021-05-05 5:46 pietru2021-05-05 6:33 ` Eric S Fraga 2021-05-05 7:12 ` Multiple calc commands with orgbabel Dr. Arne Babenhauserheide 0 siblings, 2 replies; 25+ messages in thread From: pietru @ 2021-05-05 5:46 UTC (permalink / raw) To: help Emacs Orgmode Have been trying to execute multiple calc commands, but when I evaluate the calc expressions, I get just one result. -------- This does not work #+begin_src calc fsolve(x*2+x=4,x) fsolve([x + y = a, x - y = b],[x,y]) #+end_src -------- But this works #+begin_src calc fsolve(x*2+x=4,x) #+end_src #+begin_src calc fsolve([x + y = a, x - y = b],[x,y]) #+end_src> ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 5:46 Multiple calc commands with orgbabel pietru@ 2021-05-05 6:33 ` Eric S Fraga2021-05-05 6:40 ` pietru 2021-05-05 15:11 ` Matt Price 2021-05-05 7:12 ` Multiple calc commands with orgbabel Dr. Arne Babenhauserheide 1 sibling, 2 replies; 25+ messages in thread From: Eric S Fraga @ 2021-05-05 6:33 UTC (permalink / raw) To: pietru;+Cc:help Emacs Orgmode On Wednesday, 5 May 2021 at 07:46, pietru@caramail.com wrote: > Have been trying to execute multiple calc commands, but when I > evaluate the calc expressions, I get just one result. ob-calc returns the top element of the stack when finished and this will be the result of the last operation in the src block. I don't think there's any way around this. I use embedded Calc for this reason. You could rewrite your equations as simple lines (separated by empty lines from the surroundings) and evaluate each in turn with "C-x * u": fsolve(x 2 + x = 4, x) => x = 1.33333333333 fsolve([x + y = a, x - y = b], [x, y]) => [x = a + (b - a) / 2, y = (a - b) / 2] I added the "=>" at the end of each expression so that the result is shown to the right instead of replacing the expression itself (default embedded Calc behaviour). -- : Eric S Fraga via Emacs 28.0.50, Org release_9.4.5-395-g82fbdd ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 6:33 ` Eric S Fraga@ 2021-05-05 6:40 ` pietru2021-05-05 6:41 ` Eric S Fraga 2021-05-05 15:11 ` Matt Price 1 sibling, 1 reply; 25+ messages in thread From: pietru @ 2021-05-05 6:40 UTC (permalink / raw) To: Eric S Fraga;+Cc:help Emacs Orgmode > Sent: Wednesday, May 05, 2021 at 6:33 PM > From: "Eric S Fraga" <e.fraga@ucl.ac.uk> > To: pietru@caramail.com > Cc: "help Emacs Orgmode" <emacs-orgmode@gnu.org> > Subject: Re: Multiple calc commands with orgbabel > > On Wednesday, 5 May 2021 at 07:46, pietru@caramail.com wrote: > > Have been trying to execute multiple calc commands, but when I > > evaluate the calc expressions, I get just one result. > > ob-calc returns the top element of the stack when finished and this will > be the result of the last operation in the src block. I don't think > there's any way around this. Is the top stack element just with ob-calc? > I use embedded Calc for this reason. You could rewrite your equations > as simple lines (separated by empty lines from the surroundings) and > evaluate each in turn with "C-x * u": > > fsolve(x 2 + x = 4, x) => x = 1.33333333333 > > fsolve([x + y = a, x - y = b], [x, y]) => [x = a + (b - a) / 2, y = (a - b) / 2] > > I added the "=>" at the end of each expression so that the result is > shown to the right instead of replacing the expression itself (default > embedded Calc behaviour). Will check it out, thanks. > -- > : Eric S Fraga via Emacs 28.0.50, Org release_9.4.5-395-g82fbdd > > ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 6:40 ` pietru@ 2021-05-05 6:41 ` Eric S Fraga2021-05-05 6:45 ` pietru 0 siblings, 1 reply; 25+ messages in thread From: Eric S Fraga @ 2021-05-05 6:41 UTC (permalink / raw) To: pietru;+Cc:help Emacs Orgmode On Wednesday, 5 May 2021 at 08:40, pietru@caramail.com wrote: >> ob-calc returns the top element of the stack when finished and this will >> be the result of the last operation in the src block. I don't think >> there's any way around this. > > Is the top stack element just with ob-calc? I am not sure what you are asking here. Other languages do not have the concept of a stack necessarily. However, for other languages, there is often the option to have the results be "output" instead of "value". -- : Eric S Fraga via Emacs 28.0.50, Org release_9.4.5-395-g82fbdd ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 6:41 ` Eric S Fraga@ 2021-05-05 6:45 ` pietru0 siblings, 0 replies; 25+ messages in thread From: pietru @ 2021-05-05 6:45 UTC (permalink / raw) To: Eric S Fraga;+Cc:help Emacs Orgmode > Sent: Wednesday, May 05, 2021 at 6:41 PM > From: "Eric S Fraga" <e.fraga@ucl.ac.uk> > To: pietru@caramail.com > Cc: "help Emacs Orgmode" <emacs-orgmode@gnu.org> > Subject: Re: Multiple calc commands with orgbabel > > On Wednesday, 5 May 2021 at 08:40, pietru@caramail.com wrote: > >> ob-calc returns the top element of the stack when finished and this will > >> be the result of the last operation in the src block. I don't think > >> there's any way around this. > > > > Is the top stack element just with ob-calc? > > I am not sure what you are asking here. Other languages do not have the > concept of a stack necessarily. However, for other languages, there is > often the option to have the results be "output" instead of "value". I understand, thank you. > > -- > : Eric S Fraga via Emacs 28.0.50, Org release_9.4.5-395-g82fbdd > > ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 5:46 Multiple calc commands with orgbabel pietru 2021-05-05 6:33 ` Eric S Fraga@ 2021-05-05 7:12 ` Dr. Arne Babenhauserheide2021-05-05 7:20 ` pietru 2021-05-05 7:23 ` Eric S Fraga 1 sibling, 2 replies; 25+ messages in thread From: Dr. Arne Babenhauserheide @ 2021-05-05 7:12 UTC (permalink / raw) To: pietru;+Cc:emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 288 bytes --] pietru@caramail.com writes: > Have been trying to execute multiple calc commands, but when I evaluate the calc > expressions, I get just one result. could you try the header :results output? Best wishes, Arne -- Unpolitisch sein heißt politisch sein ohne es zu merken [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 1125 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 7:12 ` Multiple calc commands with orgbabel Dr. Arne Babenhauserheide@ 2021-05-05 7:20 ` pietru2021-05-05 7:23 ` Eric S Fraga 1 sibling, 0 replies; 25+ messages in thread From: pietru @ 2021-05-05 7:20 UTC (permalink / raw) To: Dr. Arne Babenhauserheide;+Cc:emacs-orgmode I still get the lost result #+begin_src calc :results output fsolve(x*2+x=4,x) fsolve([x + y = a, x - y = b],[x,y]) #+end_src #+RESULTS: : [x = a + (b - a) / 2, y = (a - b) / 2] > Sent: Wednesday, May 05, 2021 at 7:12 PM > From: "Dr. Arne Babenhauserheide" <arne_bab@web.de> > To: pietru@caramail.com > Cc: emacs-orgmode@gnu.org > Subject: Re: Multiple calc commands with orgbabel > > > pietru@caramail.com writes: > > > Have been trying to execute multiple calc commands, but when I evaluate the calc > > expressions, I get just one result. > > could you try the header :results output? > > Best wishes, > Arne > -- > Unpolitisch sein > heißt politisch sein > ohne es zu merken > ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 7:12 ` Multiple calc commands with orgbabel Dr. Arne Babenhauserheide 2021-05-05 7:20 ` pietru@ 2021-05-05 7:23 ` Eric S Fraga2021-05-05 7:26 ` pietru 1 sibling, 1 reply; 25+ messages in thread From: Eric S Fraga @ 2021-05-05 7:23 UTC (permalink / raw) To: Dr. Arne Babenhauserheide;+Cc:pietru, emacs-orgmode On Wednesday, 5 May 2021 at 09:12, Dr. Arne Babenhauserheide wrote: > could you try the header :results output? Doesn't make any difference as Calc itself does not actually output anything. All results are put on the stack. -- : Eric S Fraga via Emacs 28.0.50, Org release_9.4.5-503-g501b2a ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 7:23 ` Eric S Fraga@ 2021-05-05 7:26 ` pietru2021-05-05 7:59 ` Eric S Fraga 0 siblings, 1 reply; 25+ messages in thread From: pietru @ 2021-05-05 7:26 UTC (permalink / raw) To: Eric S Fraga;+Cc:Dr. Arne Babenhauserheide, emacs-orgmode Does anybody has some experience using calc for factoring, matrix computation and taking derivatives. The manual overwhelmed me. > Sent: Wednesday, May 05, 2021 at 7:23 PM > From: "Eric S Fraga" <e.fraga@ucl.ac.uk> > To: "Dr. Arne Babenhauserheide" <arne_bab@web.de> > Cc: pietru@caramail.com, emacs-orgmode@gnu.org > Subject: Re: Multiple calc commands with orgbabel > > On Wednesday, 5 May 2021 at 09:12, Dr. Arne Babenhauserheide wrote: > > could you try the header :results output? > > Doesn't make any difference as Calc itself does not actually output > anything. All results are put on the stack. > > -- > : Eric S Fraga via Emacs 28.0.50, Org release_9.4.5-503-g501b2a > ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 7:26 ` pietru@ 2021-05-05 7:59 ` Eric S Fraga2021-05-05 8:00 ` pietru 0 siblings, 1 reply; 25+ messages in thread From: Eric S Fraga @ 2021-05-05 7:59 UTC (permalink / raw) To: pietru;+Cc:emacs-orgmode On Wednesday, 5 May 2021 at 09:26, pietru@caramail.com wrote: > Does anybody has some experience using calc for factoring, matrix > computation and taking derivatives. The manual overwhelmed me. You might be better off asking on the Emacs help list as this is rather off-topic for the org mailing list. -- : Eric S Fraga via Emacs 28.0.50, Org release_9.4.5-503-g501b2a ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 7:59 ` Eric S Fraga@ 2021-05-05 8:00 ` pietru0 siblings, 0 replies; 25+ messages in thread From: pietru @ 2021-05-05 8:00 UTC (permalink / raw) To: Eric S Fraga;+Cc:emacs-orgmode > Sent: Wednesday, May 05, 2021 at 7:59 PM > From: "Eric S Fraga" <e.fraga@ucl.ac.uk> > To: pietru@caramail.com > Cc: emacs-orgmode@gnu.org > Subject: Re: Multiple calc commands with orgbabel > > On Wednesday, 5 May 2021 at 09:26, pietru@caramail.com wrote: > > Does anybody has some experience using calc for factoring, matrix > > computation and taking derivatives. The manual overwhelmed me. > > You might be better off asking on the Emacs help list as this is rather > off-topic for the org mailing list. Fair enough. > -- > : Eric S Fraga via Emacs 28.0.50, Org release_9.4.5-503-g501b2a > ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 6:33 ` Eric S Fraga 2021-05-05 6:40 ` pietru@ 2021-05-05 15:11 ` Matt Price2021-05-05 15:29 ` pietru 2021-05-05 16:39 ` Eric S Fraga 1 sibling, 2 replies; 25+ messages in thread From: Matt Price @ 2021-05-05 15:11 UTC (permalink / raw) To: Org Mode List;+Cc:pietru [-- Attachment #1: Type: text/plain, Size: 1173 bytes --] Can you explain how you get calc embedded mode working in org? I have never used it and it sounds interesting, but I don't understand what hte delimiters are. On Wed, May 5, 2021 at 2:35 AM Eric S Fraga <e.fraga@ucl.ac.uk> wrote: > On Wednesday, 5 May 2021 at 07:46, pietru@caramail.com wrote: > > Have been trying to execute multiple calc commands, but when I > > evaluate the calc expressions, I get just one result. > > ob-calc returns the top element of the stack when finished and this will > be the result of the last operation in the src block. I don't think > there's any way around this. > > I use embedded Calc for this reason. You could rewrite your equations > as simple lines (separated by empty lines from the surroundings) and > evaluate each in turn with "C-x * u": > > fsolve(x 2 + x = 4, x) => x = 1.33333333333 > > fsolve([x + y = a, x - y = b], [x, y]) => [x = a + (b - a) / 2, y = (a - > b) / 2] > > I added the "=>" at the end of each expression so that the result is > shown to the right instead of replacing the expression itself (default > embedded Calc behaviour). > > -- > : Eric S Fraga via Emacs 28.0.50, Org release_9.4.5-395-g82fbdd > > [-- Attachment #2: Type: text/html, Size: 1637 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 15:11 ` Matt Price@ 2021-05-05 15:29 ` pietru2021-05-05 16:19 ` Tom Gillespie 2021-05-05 16:39 ` Eric S Fraga 1 sibling, 1 reply; 25+ messages in thread From: pietru @ 2021-05-05 15:29 UTC (permalink / raw) To: Matt Price;+Cc:Org Mode List [-- Attachment #1: Type: text/html, Size: 3443 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 15:29 ` pietru@ 2021-05-05 16:19 ` Tom Gillespie0 siblings, 0 replies; 25+ messages in thread From: Tom Gillespie @ 2021-05-05 16:19 UTC (permalink / raw) To: pietru;+Cc:Org Mode List Looking at ob-calc there is a call to calc-push-list. Knowing the length of that list (i.e. the number of arguments) it should be possible to inspect calc-stack to retrieve the other values on the stack from the current block. You can see this if you run M-: calc-stack. This would probably need a specialized result type if it were implemented. Best, Tom On Wed, May 5, 2021 at 8:33 AM <pietru@caramail.com> wrote: > > > Example > > (require 'ob-calc) > (org-babel-do-load-languages > 'org-babel-load-languages > '( (calc . t) ) > > -------- calc.org -------- > > # To execute, place cursor point on a line, then hit "C-c * u" hard with no harm. > > #+name: Simplifying Formulas > #+begin_src calc > > simplify((x + y) (x + y)) => > > simplify(a x^2 b / (c x^3 d)) => > > simplify((4 x + 6) / (8 x)) => > > simplify((1 + 2 i) (3 + 4 i)) => > > simplify(5 + i^2 + i - 8 i) => > > simplify((1, 2) + (3, 4)) => > > simplify((1, 2) (3, 4)) => > > #+end_src > > > > Sent: Thursday, May 06, 2021 at 3:11 AM > From: "Matt Price" <moptop99@gmail.com> > To: "Org Mode List" <emacs-orgmode@gnu.org> > Cc: pietru@caramail.com > Subject: Re: Multiple calc commands with orgbabel > Can you explain how you get calc embedded mode working in org? I have never used it and it sounds interesting, but I don't understand what hte delimiters are. > > On Wed, May 5, 2021 at 2:35 AM Eric S Fraga <e.fraga@ucl.ac.uk> wrote: >> >> On Wednesday, 5 May 2021 at 07:46, pietru@caramail.com wrote: >> > Have been trying to execute multiple calc commands, but when I >> > evaluate the calc expressions, I get just one result. >> >> ob-calc returns the top element of the stack when finished and this will >> be the result of the last operation in the src block. I don't think >> there's any way around this. >> >> I use embedded Calc for this reason. You could rewrite your equations >> as simple lines (separated by empty lines from the surroundings) and >> evaluate each in turn with "C-x * u": >> >> fsolve(x 2 + x = 4, x) => x = 1.33333333333 >> >> fsolve([x + y = a, x - y = b], [x, y]) => [x = a + (b - a) / 2, y = (a - b) / 2] >> >> I added the "=>" at the end of each expression so that the result is >> shown to the right instead of replacing the expression itself (default >> embedded Calc behaviour). >> >> -- >> : Eric S Fraga via Emacs 28.0.50, Org release_9.4.5-395-g82fbdd >> ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 15:11 ` Matt Price 2021-05-05 15:29 ` pietru@ 2021-05-05 16:39 ` Eric S Fraga2021-05-05 17:03 ` Tom Gillespie ` (3 more replies) 1 sibling, 4 replies; 25+ messages in thread From: Eric S Fraga @ 2021-05-05 16:39 UTC (permalink / raw) To: Matt Price;+Cc:pietru, Org Mode List On Wednesday, 5 May 2021 at 11:11, Matt Price wrote: > Can you explain how you get calc embedded mode working in org? I have > never used it and it sounds interesting, but I don't understand what > hte delimiters are. Sure. Here is a mini-tutorial! :-) I recently gave an interactive talk on embedded Calc... The out-of-the-box settings for Emacs embedded mode are such that any line surrounded by empty lines (i.e. couple of blank lines before and after) can be interpreted as an expression to evaluate by Calc using "C-x * u". You do not need to place these expressions in any src block. The detection can be somewhat fragile so extra blank lines are sometimes necessary for some reason. For instance, copy the following few lines to a text buffer and type "C-x * u" on each line in turn: --8<---------------cut here---------------start------------->8--- x := 180 => y := sin(x / 4) => z := 2 y^2 => --8<---------------cut here---------------end--------------->8--- The general format for an embedded calc expression is var := expression => value where only "expression" is required. If you don't have "=>", evaluating the expression will replace the expression with its value. If you have lines as above, with assignments and values after the actual expression, you can then go back to the first line and change the value, say to 90, type "C-x *u" on that line again and all of them should update. The calculations can involve calculus (derivatives, integration), linear algebra, and units. Calc is actually an incredibly powerful (and relatively unknown) computer algebra system hiding within Emacs. The variables that could be customised to have org specific recognition would be calc-embedded-open-formula and calc-embedded-close-formula. It might be useful for the community to think about whether org should have org specific settings for these variables. I actually define settings for org so that only lines that look like this: #+calc: expression are interpreted (without requiring empty lines around such lines) [1]. I then have code for processing these lines on export to LaTeX to present the equations and results in a more accessible way as I use embedded calc a lot for teaching (beamer slides). Final note: the info manual for embedded Calc mode emphasises editing the expressions and interacting with Calc while doing so. I find that method of working rather confusing, tiring, and unproductive (for my use case) so I write the calc lines using normal editing and only "update" the expressions to get the results. YMMV, of course. Let me know if this helped at all, eric Footnotes: [1] it would be nice to have some generic way to hijack C-c C-c on such lines to do what I want, e.g. calc-embedded-update-formula. -- : Eric S Fraga via Emacs 28.0.50, Org release_9.4.5-395-g82fbdd ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 16:39 ` Eric S Fraga@ 2021-05-05 17:03 ` Tom Gillespie2021-05-06 11:16 ` Bastien 2021-05-05 20:24 ` pietru ` (2 subsequent siblings) 3 siblings, 1 reply; 25+ messages in thread From: Tom Gillespie @ 2021-05-05 17:03 UTC (permalink / raw) To: pietru;+Cc:Org Mode List [-- Attachment #1: Type: text/plain, Size: 584 bytes --] Here is a quick and dirty implementation that more or less does what you want (I think). The if t would probably need to be replaced by a value that corresponded to an option that indicated that ob-calc should resolve all expressions on the stack. This isn't really an issue of return value, it is due to the fact that ob-calc makes stateful modifications to calc. If you want a stateless (idempotent?) ob-calc block you would need to do something like this as well, and then you would need an option to discard the additional values instead of retruning them as I do here. Best! Tom [-- Attachment #2: ob-calc-multi-return.patch --] [-- Type: text/x-patch, Size: 1606 bytes --] diff --git a/lisp/ob-calc.el b/lisp/ob-calc.el index 39ebce100..e2102feca 100644 --- a/lisp/ob-calc.el +++ b/lisp/ob-calc.el @@ -48,6 +48,7 @@ "Execute a block of calc code with Babel." (unless (get-buffer "*Calculator*") (save-window-excursion (calc) (calc-quit))) + (let ((unpopped 0)) (let* ((vars (org-babel--get-vars params)) (org--var-syms (mapcar #'car vars)) (var-names (mapcar #'symbol-name org--var-syms))) @@ -58,12 +59,14 @@ vars) (mapc (lambda (line) + (setq unpopped (1+ unpopped)) ; ICK (when (> (length line) 0) (cond ;; simple variable name ((member line var-names) (calc-recall (intern line))) ;; stack operation ((string= "'" (substring line 0 1)) + (setq unpopped (- unpopped 2)) (funcall (lookup-key calc-mode-map (substring line 1)) nil)) ;; complex expression (t @@ -89,9 +92,17 @@ (split-string (org-babel-expand-body:calc body params) "[\n\r]")))) (save-excursion (with-current-buffer (get-buffer "*Calculator*") - (prog1 - (calc-eval (calc-top 1)) - (calc-pop 1))))) + (if t + (let ((out + (cl-loop for i from 1 to unpopped + do (message "%S %S" unpopped calc-stack) + collect (calc-eval (calc-top 1)) + do (calc-pop 1)))) + (message "%S" out) + (mapcar #'list (reverse out))) + (prog1 + (calc-eval (calc-top 1)) + (calc-pop 1))))))) (defun org-babel-calc-maybe-resolve-var (el) (if (consp el) ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 16:39 ` Eric S Fraga 2021-05-05 17:03 ` Tom Gillespie@ 2021-05-05 20:24 ` pietru2021-05-05 23:09 ` ob-fortran behaviour Christopher Dimech 2021-05-06 2:24 ` ob-fortran fixes to column position 6 and subroutine keywords pietru 3 siblings, 0 replies; 25+ messages in thread From: pietru @ 2021-05-05 20:24 UTC (permalink / raw) To: Eric S Fraga;+Cc:Org Mode List > Sent: Thursday, May 06, 2021 at 4:39 AM > From: "Eric S Fraga" <e.fraga@ucl.ac.uk> > To: "Matt Price" <moptop99@gmail.com> > Cc: pietru@caramail.com, "Org Mode List" <emacs-orgmode@gnu.org> > Subject: Re: Multiple calc commands with orgbabel > > On Wednesday, 5 May 2021 at 11:11, Matt Price wrote: > > Can you explain how you get calc embedded mode working in org? I have > > never used it and it sounds interesting, but I don't understand what > > hte delimiters are. > > Sure. Here is a mini-tutorial! :-) I recently gave an interactive talk > on embedded Calc... > > The out-of-the-box settings for Emacs embedded mode are such that any > line surrounded by empty lines (i.e. couple of blank lines before and > after) can be interpreted as an expression to evaluate by Calc using > "C-x * u". You do not need to place these expressions in any src block. > > The detection can be somewhat fragile so extra blank lines are sometimes > necessary for some reason. > > For instance, copy the following few lines to a text buffer and type > "C-x * u" on each line in turn: > > --8<---------------cut here---------------start------------->8--- > > > x := 180 => > > > y := sin(x / 4) => > > > z := 2 y^2 => > > > --8<---------------cut here---------------end--------------->8--- > > The general format for an embedded calc expression is > > var := expression => value > > where only "expression" is required. If you don't have "=>", evaluating > the expression will replace the expression with its value. > > If you have lines as above, with assignments and values after the actual > expression, you can then go back to the first line and change the value, > say to 90, type "C-x *u" on that line again and all of them should > update. > > The calculations can involve calculus (derivatives, integration), linear > algebra, and units. Calc is actually an incredibly powerful (and > relatively unknown) computer algebra system hiding within Emacs. Calc is a great piece of work. Has it been long that work was done on it? > The variables that could be customised to have org specific recognition > would be calc-embedded-open-formula and calc-embedded-close-formula. It > might be useful for the community to think about whether org should have > org specific settings for these variables. I actually define settings > for org so that only lines that look like this: > > #+calc: expression > > are interpreted (without requiring empty lines around such lines) > [1]. I then have code for processing these lines on export to LaTeX to > present the equations and results in a more accessible way as I use > embedded calc a lot for teaching (beamer slides). > > Final note: the info manual for embedded Calc mode emphasises editing > the expressions and interacting with Calc while doing so. I find that > method of working rather confusing, tiring, and unproductive (for my use > case) so I write the calc lines using normal editing and only "update" > the expressions to get the results. YMMV, of course. > > Let me know if this helped at all, > eric > > > Footnotes: > [1] it would be nice to have some generic way to hijack C-c C-c on such > lines to do what I want, e.g. calc-embedded-update-formula. > > -- > : Eric S Fraga via Emacs 28.0.50, Org release_9.4.5-395-g82fbdd > > ^ permalink raw reply [flat|nested] 25+ messages in thread

*ob-fortran behaviour2021-05-05 16:39 ` Eric S Fraga 2021-05-05 17:03 ` Tom Gillespie 2021-05-05 20:24 ` pietru@ 2021-05-05 23:09 ` Christopher Dimech2021-05-05 23:29 ` Christopher Dimech 2021-05-06 2:24 ` ob-fortran fixes to column position 6 and subroutine keywords pietru 3 siblings, 1 reply; 25+ messages in thread From: Christopher Dimech @ 2021-05-05 23:09 UTC (permalink / raw) To: Eric S Fraga;+Cc:Org Mode List Fortran is behaving in a weird way #+BEGIN_SRC fortran program matrx_vectr_mult implicit none integer :: m, n, i, j, k real :: a(5,3), u(3), v(5), rsum m = 5; n = 3 a = 0.0; u = 0.0; v = 0.0 k = 0 do j = 1, n do i = 1, m k = i + j a(i,j) = real(k) u(i) = real(3*i) end do end do do i = 1, m rsum = 0.0 do j = 1, n rsum = (a(i,j) * u(j)) + rsum end do v(i) = rsum end do write (*,*) "a * *", " * ", "u", " * ", "v" write (*,*) a(1,:), "*", u(1), "*", v(1) write (*,*) a(2,:), "*", u(2), "*", v(2) write (*,*) a(3,:), "*", u(3), "*", v(3) write (*,*) a(4,:), "* * *", v(4) write (*,*) a(5,:), "* * *", v(5) print *, "---" write (*,*) a end program #+END_SRC #+RESULTS: | a | * | * | * | u | * | v | | | | | | | | | | 12.0 | 3.0 | 4.0 | * | 3.0 | * | 90.0 | | | | | | | | | | 15.0 | 4.0 | 5.0 | * | 6.0 | * | 114.0 | | | | | | | | | | 4.0 | 5.0 | 6.0 | * | 9.0 | * | 96.0 | | | | | | | | | | 5.0 | 6.0 | 7.0 | * | * | * | 114.0 | | | | | | | | | | 6.0 | 7.0 | 8.0 | * | * | * | 132.0 | | | | | | | | | | --- | | | | | | | | | | | | | | | | 12.0 | 15.0 | 4.0 | 5.0 | 6.0 | 3.0 | 4.0 | 5.0 | 6.0 | 7.0 | 4.0 | 5.0 | 6.0 | 7.0 | 8.0 | --------------------- Christopher Dimech General Administrator - Naiad Informatics - GNU Project (Geocomputation) - Geophysical Simulation - Geological Subsurface Mapping - Disaster Preparedness and Mitigation - Natural Resource Exploration and Production - Free Software Advocacy ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: ob-fortran behaviour2021-05-05 23:09 ` ob-fortran behaviour Christopher Dimech@ 2021-05-05 23:29 ` Christopher Dimech0 siblings, 0 replies; 25+ messages in thread From: Christopher Dimech @ 2021-05-05 23:29 UTC (permalink / raw) To: Christopher Dimech;+Cc:Org Mode List, Eric S Fraga There exists no problem with fortran. My brain was not open because u(i) gets beyond its bounds. > Sent: Thursday, May 06, 2021 at 11:09 AM > From: "Christopher Dimech" <dimech@gmx.com> > To: "Eric S Fraga" <e.fraga@ucl.ac.uk> > Cc: "Org Mode List" <emacs-orgmode@gnu.org> > Subject: ob-fortran behaviour > > Fortran is behaving in a weird way > > #+BEGIN_SRC fortran > program matrx_vectr_mult > implicit none > > integer :: m, n, i, j, k > real :: a(5,3), u(3), v(5), rsum > > m = 5; n = 3 > a = 0.0; u = 0.0; v = 0.0 > > k = 0 > do j = 1, n > do i = 1, m > k = i + j > a(i,j) = real(k) > u(i) = real(3*i) > end do > end do > > do i = 1, m > rsum = 0.0 > do j = 1, n > rsum = (a(i,j) * u(j)) + rsum > end do > v(i) = rsum > end do > > write (*,*) "a * *", " * ", "u", " * ", "v" > write (*,*) a(1,:), "*", u(1), "*", v(1) > write (*,*) a(2,:), "*", u(2), "*", v(2) > write (*,*) a(3,:), "*", u(3), "*", v(3) > write (*,*) a(4,:), "* * *", v(4) > write (*,*) a(5,:), "* * *", v(5) > > print *, "---" > write (*,*) a > > end program > #+END_SRC > > #+RESULTS: > | a | * | * | * | u | * | v | | | | | | | | | > | 12.0 | 3.0 | 4.0 | * | 3.0 | * | 90.0 | | | | | | | | | > | 15.0 | 4.0 | 5.0 | * | 6.0 | * | 114.0 | | | | | | | | | > | 4.0 | 5.0 | 6.0 | * | 9.0 | * | 96.0 | | | | | | | | | > | 5.0 | 6.0 | 7.0 | * | * | * | 114.0 | | | | | | | | | > | 6.0 | 7.0 | 8.0 | * | * | * | 132.0 | | | | | | | | | > | --- | | | | | | | | | | | | | | | > | 12.0 | 15.0 | 4.0 | 5.0 | 6.0 | 3.0 | 4.0 | 5.0 | 6.0 | 7.0 | 4.0 | 5.0 | 6.0 | 7.0 | 8.0 | > > > --------------------- > Christopher Dimech > General Administrator - Naiad Informatics - GNU Project (Geocomputation) > - Geophysical Simulation > - Geological Subsurface Mapping > - Disaster Preparedness and Mitigation > - Natural Resource Exploration and Production > - Free Software Advocacy > > ^ permalink raw reply [flat|nested] 25+ messages in thread

*2021-05-05 16:39 ` Eric S Fraga ` (2 preceding siblings ...) 2021-05-05 23:09 ` ob-fortran behaviour Christopher Dimechob-fortran fixes to column position 6 and subroutine keywords@ 2021-05-06 2:24 ` pietru3 siblings, 0 replies; 25+ messages in thread From: pietru @ 2021-05-06 2:24 UTC (permalink / raw) To: Eric S Fraga;+Cc:Org Mode List ob-fortran treats code highlighting as "fortran 77" code, starting highlighting from column position 6. Can this be changed to use free format? Also the following call fails, meaning that currently you cannot use keywords. call system_clock(cnt_mx=count_max, cnt_rt=count_rate) ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-05 17:03 ` Tom Gillespie@ 2021-05-06 11:16 ` Bastien2021-05-06 15:21 ` Tom Gillespie 0 siblings, 1 reply; 25+ messages in thread From: Bastien @ 2021-05-06 11:16 UTC (permalink / raw) To: Tom Gillespie;+Cc:pietru, Org Mode List Hi Tom, Tom Gillespie <tgbugs@gmail.com> writes: > Here is a quick and dirty implementation that more or less does what > you want (I think). Mandatory question: would you like to be ob-calc.el maintainer? -- Bastien ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-06 11:16 ` Bastien@ 2021-05-06 15:21 ` Tom Gillespie2021-05-07 4:04 ` Bastien 0 siblings, 1 reply; 25+ messages in thread From: Tom Gillespie @ 2021-05-06 15:21 UTC (permalink / raw) To: Bastien;+Cc:pietru, Org Mode List Hi Bastien, Given the short length of the file, the fact that I now have a fairly good idea of how it works, and the fact that I share a last name with the original author of calc, I would be happy to. I'll hunt down the steps you mentioned for becoming an ob- maintainer and ping back when they are done. Best! Tom ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-06 15:21 ` Tom Gillespie@ 2021-05-07 4:04 ` Bastien2021-05-07 7:01 ` Tom Gillespie 0 siblings, 1 reply; 25+ messages in thread From: Bastien @ 2021-05-07 4:04 UTC (permalink / raw) To: Tom Gillespie;+Cc:pietru, Org Mode List Hi Tom, that's really kind of you! Thanks a lot. If other people share the last name of original authors of ob-* files, please raise your voice and ask for your share :) Best, -- Bastien ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-07 4:04 ` Bastien@ 2021-05-07 7:01 ` Tom Gillespie2021-05-07 7:31 ` Bastien 0 siblings, 1 reply; 25+ messages in thread From: Tom Gillespie @ 2021-05-07 7:01 UTC (permalink / raw) To: Bastien;+Cc:pietru, Org Mode List [-- Attachment #1: Type: text/plain, Size: 59 bytes --] Hi Bastien, Here's a patch to make it official. :) Tom [-- Attachment #2: 0001-lisp-ob-calc.el-Add-Tom-Gillespie-as-the-maintainer.patch --] [-- Type: text/x-patch, Size: 716 bytes --] From 3a61289e8fa4442f6d340138dcb67b950e980212 Mon Sep 17 00:00:00 2001 From: Tom Gillespie <tgbugs@gmail.com> Date: Thu, 6 May 2021 23:52:21 -0700 Subject: [PATCH] lisp/ob-calc.el: Add Tom Gillespie as the maintainer * lisp/ob-calc.el: Add Tom Gillespie as the maintainer. --- lisp/ob-calc.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/ob-calc.el b/lisp/ob-calc.el index 39ebce100..520f39145 100644 --- a/lisp/ob-calc.el +++ b/lisp/ob-calc.el @@ -3,6 +3,7 @@ ;; Copyright (C) 2010-2021 Free Software Foundation, Inc. ;; Author: Eric Schulte +;; Maintainer: Tom Gillespie <tgbugs@gmail.com> ;; Keywords: literate programming, reproducible research ;; Homepage: https://orgmode.org -- 2.26.3 ^ permalink raw reply [flat|nested] 25+ messages in thread

*Re: Multiple calc commands with orgbabel2021-05-07 7:01 ` Tom Gillespie@ 2021-05-07 7:31 ` Bastien0 siblings, 0 replies; 25+ messages in thread From: Bastien @ 2021-05-07 7:31 UTC (permalink / raw) To: Tom Gillespie;+Cc:pietru, Org Mode List Tom Gillespie <tgbugs@gmail.com> writes: > Here's a patch to make it official. :) Applied in master, thanks! -- Bastien ^ permalink raw reply [flat|nested] 25+ messages in thread

end of thread, other threads:[~2021-05-07 7:32 UTC | newest]Thread overview:25+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-05-05 5:46 Multiple calc commands with orgbabel pietru 2021-05-05 6:33 ` Eric S Fraga 2021-05-05 6:40 ` pietru 2021-05-05 6:41 ` Eric S Fraga 2021-05-05 6:45 ` pietru 2021-05-05 15:11 ` Matt Price 2021-05-05 15:29 ` pietru 2021-05-05 16:19 ` Tom Gillespie 2021-05-05 16:39 ` Eric S Fraga 2021-05-05 17:03 ` Tom Gillespie 2021-05-06 11:16 ` Bastien 2021-05-06 15:21 ` Tom Gillespie 2021-05-07 4:04 ` Bastien 2021-05-07 7:01 ` Tom Gillespie 2021-05-07 7:31 ` Bastien 2021-05-05 20:24 ` pietru 2021-05-05 23:09 ` ob-fortran behaviour Christopher Dimech 2021-05-05 23:29 ` Christopher Dimech 2021-05-06 2:24 ` ob-fortran fixes to column position 6 and subroutine keywords pietru 2021-05-05 7:12 ` Multiple calc commands with orgbabel Dr. Arne Babenhauserheide 2021-05-05 7:20 ` pietru 2021-05-05 7:23 ` Eric S Fraga 2021-05-05 7:26 ` pietru 2021-05-05 7:59 ` Eric S Fraga 2021-05-05 8:00 ` pietru

Code repositories for project(s) associated with this 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 NNTP newsgroup(s).