* [babel] maxima support? @ 2011-02-23 9:32 Litvinov Sergey 2011-02-24 10:25 ` Eric S Fraga 0 siblings, 1 reply; 14+ messages in thread From: Litvinov Sergey @ 2011-02-23 9:32 UTC (permalink / raw) To: emacs-orgmode I have not found (i)maxima on this page. http://orgmode.org/worg/org-contrib/babel/languages.html (Babel: Languages) Has someone implemented it? ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-02-23 9:32 [babel] maxima support? Litvinov Sergey @ 2011-02-24 10:25 ` Eric S Fraga 2011-02-24 10:28 ` Eric S Fraga ` (2 more replies) 0 siblings, 3 replies; 14+ messages in thread From: Eric S Fraga @ 2011-02-24 10:25 UTC (permalink / raw) To: Litvinov Sergey; +Cc: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 706 bytes --] Litvinov Sergey <slitvinov@gmail.com> writes: > I have not found (i)maxima on this page. > http://orgmode.org/worg/org-contrib/babel/languages.html > (Babel: Languages) > > Has someone implemented it? I have implemented a very basic interface (attached). Example: #+begin-src org * maxima test *** simple test #+begin_src maxima programmode: false; eq: x**2-1 = 0; solution: solve(eq, x); print(solution); #+end_src #+results: : [x = - 1, x = 1] #+end_src However, please note that this is rather linux (maybe Unix) specific in that it post-processes the output of maxima using a sequence of shell commands to get rid of unnecessary (to my mind) output. Maxima is a bit verbose... [-- Attachment #2: org babel maxima interface --] [-- Type: application/emacs-lisp, Size: 2703 bytes --] [-- Attachment #3: Type: text/plain, Size: 120 bytes --] -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 : using Org-mode version 7.4 (release_7.4.529.gb23d) [-- Attachment #4: Type: text/plain, Size: 201 bytes --] _______________________________________________ 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-02-24 10:25 ` Eric S Fraga @ 2011-02-24 10:28 ` Eric S Fraga 2011-02-25 9:17 ` Litvinov Sergey 2011-02-25 23:58 ` Eric Schulte 2 siblings, 0 replies; 14+ messages in thread From: Eric S Fraga @ 2011-02-24 10:28 UTC (permalink / raw) To: Litvinov Sergey; +Cc: emacs-orgmode Eric S Fraga <e.fraga@ucl.ac.uk> writes: > Litvinov Sergey <slitvinov@gmail.com> writes: > >> I have not found (i)maxima on this page. >> http://orgmode.org/worg/org-contrib/babel/languages.html >> (Babel: Languages) >> >> Has someone implemented it? > > I have implemented a very basic interface (attached). Example: > > #+begin-src org > * maxima test > *** simple test > #+begin_src maxima > programmode: false; > eq: x**2-1 = 0; > solution: solve(eq, x); > print(solution); > #+end_src > > > #+results: > : [x = - 1, x = 1] > #+end_src > > However, please note that this is rather linux (maybe Unix) specific in > that it post-processes the output of maxima using a sequence of shell > commands to get rid of unnecessary (to my mind) output. Maxima is a bit > verbose... I hit C-c C-c too quickly (got confused as to which buffer I was in). Please delete the "programmode: false;" line in the source code block above to get the desired behaviour... <blush> -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 : using Org-mode version 7.4 (release_7.4.529.gb23d) ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-02-24 10:25 ` Eric S Fraga 2011-02-24 10:28 ` Eric S Fraga @ 2011-02-25 9:17 ` Litvinov Sergey 2011-02-25 23:58 ` Eric Schulte 2 siblings, 0 replies; 14+ messages in thread From: Litvinov Sergey @ 2011-02-25 9:17 UTC (permalink / raw) To: emacs-orgmode Thanks. Works like a charm. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-02-24 10:25 ` Eric S Fraga 2011-02-24 10:28 ` Eric S Fraga 2011-02-25 9:17 ` Litvinov Sergey @ 2011-02-25 23:58 ` Eric Schulte 2011-02-28 16:15 ` Eric S Fraga 2 siblings, 1 reply; 14+ messages in thread From: Eric Schulte @ 2011-02-25 23:58 UTC (permalink / raw) To: Eric S Fraga; +Cc: Litvinov Sergey, emacs-orgmode Great, Thanks for sharing! Why don't we replace the shell-script munging with some elisp munging and add this to the core? I can help with the translation to elisp (although I may be busy through the weekend/week). Best -- Eric Eric S Fraga <e.fraga@ucl.ac.uk> writes: > Litvinov Sergey <slitvinov@gmail.com> writes: > >> I have not found (i)maxima on this page. >> http://orgmode.org/worg/org-contrib/babel/languages.html >> (Babel: Languages) >> >> Has someone implemented it? > > I have implemented a very basic interface (attached). Example: > > #+begin-src org > * maxima test > *** simple test > #+begin_src maxima > programmode: false; > eq: x**2-1 = 0; > solution: solve(eq, x); > print(solution); > #+end_src > > #+results: > : [x = - 1, x = 1] > #+end_src > > However, please note that this is rather linux (maybe Unix) specific in > that it post-processes the output of maxima using a sequence of shell > commands to get rid of unnecessary (to my mind) output. Maxima is a bit > verbose... ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-02-25 23:58 ` Eric Schulte @ 2011-02-28 16:15 ` Eric S Fraga 2011-03-14 21:26 ` Eric Schulte 0 siblings, 1 reply; 14+ messages in thread From: Eric S Fraga @ 2011-02-28 16:15 UTC (permalink / raw) To: Eric Schulte; +Cc: Litvinov Sergey, emacs-orgmode "Eric Schulte" <schulte.eric@gmail.com> writes: > Great, Thanks for sharing! > > Why don't we replace the shell-script munging with some elisp munging > and add this to the core? > > I can help with the translation to elisp (although I may be busy through > the weekend/week). > > Best -- Eric I'd be very happy to have the code made more portable, and integrated properly within org-babel. I, unfortunately, don't have any of the elisp skills that would be necessary... my upbringing in the early days of Unix are showing here: I solve everything with concatenation of targeted shell commands ;-) Given that I use a sequence of regex based commands (grep and sed), I imagine it would be trivial for somebody with more elisp expertise to translate my sequence of commands into elisp code? -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 : using Org-mode version 7.4 (release_7.4.529.gb23d.dirty) ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-02-28 16:15 ` Eric S Fraga @ 2011-03-14 21:26 ` Eric Schulte 2011-03-15 10:47 ` Eric S Fraga 0 siblings, 1 reply; 14+ messages in thread From: Eric Schulte @ 2011-03-14 21:26 UTC (permalink / raw) To: Eric S Fraga; +Cc: Litvinov Sergey, emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 492 bytes --] Hi Eric, I've gone through your ob-maxima.el, and tried to re-work it to the point where it can be included into Org-mode -- mainly just switching to a couple of Babel "best practices", and replacing some shell script munging with elisp munging. Please try out the attached version (packaged as a patch against the current Org-mode head) and let me know if it works --- i.e., If I haven't broken it too badly. If it works I think we can fold it into Org-mode immediately. Cheers -- Eric [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-adding-support-for-Maxima-code-blocks-thanks-to-Eric.patch --] [-- Type: text/x-diff, Size: 3653 bytes --] From 8c8f85e2a98430cc147749b8fa67dbba53c0ccb3 Mon Sep 17 00:00:00 2001 From: Eric Schulte <schulte.eric@gmail.com> Date: Mon, 14 Mar 2011 15:20:05 -0600 Subject: [PATCH] adding support for Maxima code blocks -- thanks to Eric Fraga --- lisp/ob-maxima.el | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lisp/org.el | 1 + 2 files changed, 79 insertions(+), 0 deletions(-) create mode 100644 lisp/ob-maxima.el diff --git a/lisp/ob-maxima.el b/lisp/ob-maxima.el new file mode 100644 index 0000000..c775f92 --- /dev/null +++ b/lisp/ob-maxima.el @@ -0,0 +1,78 @@ +;;; org-babel-maxima.el --- org-babel functions for maxima evaluation + +;; Copyright (c) 2009, 2010, 2011 Eric S Fraga, Eric Schulte + +;; Author: Eric S Fraga, Eric Schulte +;; Keywords: literate programming, reproducible research, maxima +;; Homepage: http://orgmode.org +;; Version: 0.01 + +;;; License: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; Org-Babel support for evaluating maxima entries. +;; +;; This differs from most standard languages in that +;; +;; 1) there is no such thing as a "session" in maxima +;; +;; 2) we are generally only going to return output from maxima +;; +;; 3) we are adding the "cmdline" header argument +;; +;; 4) there are no variables + +;;; Code: +(require 'ob) + +(defvar org-babel-default-header-args:maxima '()) + +(defun org-babel-maxima-expand (body params) + "Expand a block of Maxima code according to its header arguments." + body) + +(defun org-babel-execute:maxima (body params) + "Execute a block of Maxima entries with org-babel. This function is +called by `org-babel-execute-src-block'." + (message "executing Maxima source code block") + (let ((result-params (split-string (or (cdr (assoc :results params)) ""))) + (cmdline (cdr (assoc :cmdline params))) + (in-file (org-babel-temp-file "maxima-")) + (cmd (format "maxima --very-quiet -r 'batchload(%S)$' %s" + in-file cmdline))) + (with-temp-file in-file (insert body)) + (message cmd) + ((lambda (raw) ;; " | grep -v batch | grep -v 'replaced' | sed '/^$/d' " + (delq nil + (mapcar (lambda (line) + (unless (or (string-match "batch" line) + (string-match "replaced" line) + (= 0 (length line))) + line)) + (split-string raw)))) + (org-babel-eval cmd "")))) + +(defun org-babel-prep-session:maxima (session params) + (error "Maxima does not support sessions")) + +(provide 'ob-maxima) + +;; arch-tag: d86c97ac-7eab-4349-8d8b-302dd09779a8 + +;;; org-babel-maxima.el ends here diff --git a/lisp/org.el b/lisp/org.el index 96ad8ff..ae0ef5e 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -164,6 +164,7 @@ requirements) is loaded." (const :tag "Javascript" js) (const :tag "Latex" latex) (const :tag "Ledger" ledger) + (const :tag "Maxima" maxima) (const :tag "Matlab" matlab) (const :tag "Mscgen" mscgen) (const :tag "Ocaml" ocaml) -- 1.7.1 [-- Attachment #3: Type: text/plain, Size: 866 bytes --] Eric S Fraga <e.fraga@ucl.ac.uk> writes: > "Eric Schulte" <schulte.eric@gmail.com> writes: > >> Great, Thanks for sharing! >> >> Why don't we replace the shell-script munging with some elisp munging >> and add this to the core? >> >> I can help with the translation to elisp (although I may be busy through >> the weekend/week). >> >> Best -- Eric > > I'd be very happy to have the code made more portable, and integrated > properly within org-babel. I, unfortunately, don't have any of the > elisp skills that would be necessary... my upbringing in the early days > of Unix are showing here: I solve everything with concatenation of > targeted shell commands ;-) Given that I use a sequence of regex based > commands (grep and sed), I imagine it would be trivial for somebody with > more elisp expertise to translate my sequence of commands into elisp > code? ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-03-14 21:26 ` Eric Schulte @ 2011-03-15 10:47 ` Eric S Fraga 2011-03-15 13:17 ` Eric Schulte 0 siblings, 1 reply; 14+ messages in thread From: Eric S Fraga @ 2011-03-15 10:47 UTC (permalink / raw) To: Eric Schulte; +Cc: Litvinov Sergey, emacs-orgmode "Eric Schulte" <schulte.eric@gmail.com> writes: > Hi Eric, > > I've gone through your ob-maxima.el, and tried to re-work it to the > point where it can be included into Org-mode -- mainly just switching to > a couple of Babel "best practices", and replacing some shell script > munging with elisp munging. > > Please try out the attached version (packaged as a patch against the > current Org-mode head) and let me know if it works --- i.e., If I > haven't broken it too badly. If it works I think we can fold it into > Org-mode immediately. > > Cheers -- Eric I've tried this but cannot get it to execute my maxima code: --8<---------------cut here---------------start------------->8--- #+begin_src maxima programmode: false; eq: x**2-1 = 0; solution: solve(eq, x); print(solution); #+end_src --8<---------------cut here---------------end--------------->8--- I get the following error: --8<---------------cut here---------------start------------->8--- Debugger entered--Lisp error: (void-variable in-file) (format "maxima --very-quiet -r 'batchload(%S)$' %s" in-file cmdline) (let ((result-params (split-string (or (cdr (assoc :results params)) ""))) (cmdline (cdr (assoc :cmdline params))) (in-file (org-babel-temp-file "maxima-")) (cmd (format "maxima --very-quiet -r 'batchload(%S)$' %s" in-file cmdline))) (with-temp-file in-file (insert body)) (message cmd) ((lambda (raw) (delq nil (mapcar (lambda (line) (unless (or ... ... ...) line)) (split-string raw)))) (org-babel-eval cmd ""))) org-babel-execute:maxima("programmode: false;\neq: x**2-1 = 0;\nsolution: solve(eq, x);\nprint(solution);\n" ((:colname-names) (:rowname-names) (:result-params "replace") (:result-type . value) (:comments . "") (:shebang . "") (:cache . "no") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace") (:hlines . "no") (:session . "none"))) org-babel-execute-src-block(nil ("maxima" "programmode: false;\neq: x**2-1 = 0;\nsolution: solve(eq, x);\nprint(solution);\n" ((:colname-names) (:rowname-names) (:result-params "replace") (:result-type . value) (:comments . "") (:shebang . "") (:cache . "no") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace") (:hlines . "no") (:session . "none")) "" nil 4)) org-babel-execute-src-block-maybe() org-babel-execute-maybe() org-babel-execute-safely-maybe() run-hook-with-args-until-success(org-babel-execute-safely-maybe) org-ctrl-c-ctrl-c(nil) call-interactively(org-ctrl-c-ctrl-c nil nil) --8<---------------cut here---------------end--------------->8--- This was with a freshly invoked emacs (with my own ob-maxima.el moved out of the way). Any suggestions? thanks, eric -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 : using Org-mode version 7.5 (release_7.5.38.gf8c6.dirty) ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-03-15 10:47 ` Eric S Fraga @ 2011-03-15 13:17 ` Eric Schulte 2011-03-15 14:27 ` Eric S Fraga 0 siblings, 1 reply; 14+ messages in thread From: Eric Schulte @ 2011-03-15 13:17 UTC (permalink / raw) To: Eric S Fraga; +Cc: Litvinov Sergey, emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 1031 bytes --] Eric S Fraga <e.fraga@ucl.ac.uk> writes: > "Eric Schulte" <schulte.eric@gmail.com> writes: > >> Hi Eric, >> >> I've gone through your ob-maxima.el, and tried to re-work it to the >> point where it can be included into Org-mode -- mainly just switching to >> a couple of Babel "best practices", and replacing some shell script >> munging with elisp munging. >> >> Please try out the attached version (packaged as a patch against the >> current Org-mode head) and let me know if it works --- i.e., If I >> haven't broken it too badly. If it works I think we can fold it into >> Org-mode immediately. >> >> Cheers -- Eric > > I've tried this but cannot get it to execute my maxima code: > > #+begin_src maxima > programmode: false; > eq: x**2-1 = 0; > solution: solve(eq, x); > print(solution); > #+end_src > > I get the following error: > Ah, I see the problem, I used let instead of let*. Please try this updated version of the patch. Sorry I would test this myself, but I don't have Maxima installed. Thanks -- Eric [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-adding-support-for-Maxima-code-blocks-thanks-to-Eric.patch --] [-- Type: text/x-diff, Size: 3651 bytes --] From 69c60518f17ac1d59864cbb42717733da74cb024 Mon Sep 17 00:00:00 2001 From: Eric Schulte <schulte.eric@gmail.com> Date: Mon, 14 Mar 2011 15:20:05 -0600 Subject: [PATCH] adding support for Maxima code blocks -- thanks to Eric Fraga --- lisp/ob-maxima.el | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lisp/org.el | 1 + 2 files changed, 79 insertions(+), 0 deletions(-) create mode 100644 lisp/ob-maxima.el diff --git a/lisp/ob-maxima.el b/lisp/ob-maxima.el new file mode 100644 index 0000000..f72567f --- /dev/null +++ b/lisp/ob-maxima.el @@ -0,0 +1,78 @@ +;;; org-babel-maxima.el --- org-babel functions for maxima evaluation + +;; Copyright (c) 2009, 2010, 2011 Eric S Fraga, Eric Schulte + +;; Author: Eric S Fraga, Eric Schulte +;; Keywords: literate programming, reproducible research, maxima +;; Homepage: http://orgmode.org +;; Version: 0.01 + +;;; License: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; Org-Babel support for evaluating maxima entries. +;; +;; This differs from most standard languages in that +;; +;; 1) there is no such thing as a "session" in maxima +;; +;; 2) we are generally only going to return output from maxima +;; +;; 3) we are adding the "cmdline" header argument +;; +;; 4) there are no variables + +;;; Code: +(require 'ob) + +(defvar org-babel-default-header-args:maxima '()) + +(defun org-babel-maxima-expand (body params) + "Expand a block of Maxima code according to its header arguments." + body) + +(defun org-babel-execute:maxima (body params) + "Execute a block of Maxima entries with org-babel. This function is +called by `org-babel-execute-src-block'." + (message "executing Maxima source code block") + (let* ((result-params (split-string (or (cdr (assoc :results params)) ""))) + (cmdline (cdr (assoc :cmdline params))) + (in-file (org-babel-temp-file "maxima-")) + (cmd (format "maxima --very-quiet -r 'batchload(%S)$' %s" + in-file cmdline))) + (with-temp-file in-file (insert body)) + (message cmd) + ((lambda (raw) ;; " | grep -v batch | grep -v 'replaced' | sed '/^$/d' " + (delq nil + (mapcar (lambda (line) + (unless (or (string-match "batch" line) + (string-match "replaced" line) + (= 0 (length line))) + line)) + (split-string raw)))) + (org-babel-eval cmd "")))) + +(defun org-babel-prep-session:maxima (session params) + (error "Maxima does not support sessions")) + +(provide 'ob-maxima) + +;; arch-tag: d86c97ac-7eab-4349-8d8b-302dd09779a8 + +;;; org-babel-maxima.el ends here diff --git a/lisp/org.el b/lisp/org.el index 96ad8ff..ae0ef5e 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -164,6 +164,7 @@ requirements) is loaded." (const :tag "Javascript" js) (const :tag "Latex" latex) (const :tag "Ledger" ledger) + (const :tag "Maxima" maxima) (const :tag "Matlab" matlab) (const :tag "Mscgen" mscgen) (const :tag "Ocaml" ocaml) -- 1.7.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-03-15 13:17 ` Eric Schulte @ 2011-03-15 14:27 ` Eric S Fraga 2011-03-15 15:32 ` Eric Schulte 0 siblings, 1 reply; 14+ messages in thread From: Eric S Fraga @ 2011-03-15 14:27 UTC (permalink / raw) To: Eric Schulte; +Cc: Litvinov Sergey, emacs-orgmode "Eric Schulte" <schulte.eric@gmail.com> writes: [...] > > Ah, I see the problem, I used let instead of let*. Please try this > updated version of the patch. Sorry I would test this myself, but I > don't have Maxima installed. No problem at all! I'm happy to test this as many times as necessary. In any case, this works fine in that maxima is indeed evaluated and output is returned. However, two problems arise: 1. lines of the form "rat: replaced XXX by YYY = ZZZ" are not deleted (as used to be by the grep -v replaced hack I had in the original ob-maxima). Essentially, we need to ignore output lines that match the regex "^rat: replaced .*$" (I think this should do it...). 2. The output is converted to an org table: --8<---------------cut here---------------start------------->8--- *** simple test #+begin_src maxima :results value programmode: false; eq: x**2-1 = 0; solution: solve(eq, x); print(solution); #+end_src #+results: | solve: | solution: | x | = | - | 1 | x | = | 1 | [%t1, | %t2] | --8<---------------cut here---------------end--------------->8--- This isn't necessary appropriate in this case... but I guess this is now a matter of adding all the normal frills given that the basic functionality is there? Thanks! -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 : using Org-mode version 7.5 (release_7.5.38.gf8c6.dirty) ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-03-15 14:27 ` Eric S Fraga @ 2011-03-15 15:32 ` Eric Schulte 2011-03-15 16:39 ` Eric S Fraga 0 siblings, 1 reply; 14+ messages in thread From: Eric Schulte @ 2011-03-15 15:32 UTC (permalink / raw) To: Eric S Fraga; +Cc: Litvinov Sergey, emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 919 bytes --] Eric S Fraga <e.fraga@ucl.ac.uk> writes: > "Eric Schulte" <schulte.eric@gmail.com> writes: > > [...] > >> >> Ah, I see the problem, I used let instead of let*. Please try this >> updated version of the patch. Sorry I would test this myself, but I >> don't have Maxima installed. > > No problem at all! I'm happy to test this as many times as necessary. > > In any case, this works fine in that maxima is indeed evaluated and > output is returned. However, two problems arise: > > 1. lines of the form "rat: replaced XXX by YYY = ZZZ" are not deleted > (as used to be by the grep -v replaced hack I had in the original > ob-maxima). Essentially, we need to ignore output lines that match > the regex "^rat: replaced .*$" (I think this should do it...). > > 2. The output is converted to an org table: > The attached should fix both of these problems. Please let me know how this works. Thanks -- Eric [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-adding-support-for-Maxima-code-blocks-thanks-to-Eric.patch --] [-- Type: text/x-diff, Size: 3690 bytes --] From 839612902cc1a0887f4e12cf408f3c8594b01599 Mon Sep 17 00:00:00 2001 From: Eric Schulte <schulte.eric@gmail.com> Date: Mon, 14 Mar 2011 15:20:05 -0600 Subject: [PATCH] adding support for Maxima code blocks -- thanks to Eric Fraga --- lisp/ob-maxima.el | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lisp/org.el | 1 + 2 files changed, 81 insertions(+), 0 deletions(-) create mode 100644 lisp/ob-maxima.el diff --git a/lisp/ob-maxima.el b/lisp/ob-maxima.el new file mode 100644 index 0000000..e8b2df4 --- /dev/null +++ b/lisp/ob-maxima.el @@ -0,0 +1,80 @@ +;;; org-babel-maxima.el --- org-babel functions for maxima evaluation + +;; Copyright (c) 2009, 2010, 2011 Eric S Fraga, Eric Schulte + +;; Author: Eric S Fraga, Eric Schulte +;; Keywords: literate programming, reproducible research, maxima +;; Homepage: http://orgmode.org +;; Version: 0.01 + +;;; License: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; Org-Babel support for evaluating maxima entries. +;; +;; This differs from most standard languages in that +;; +;; 1) there is no such thing as a "session" in maxima +;; +;; 2) we are generally only going to return output from maxima +;; +;; 3) we are adding the "cmdline" header argument +;; +;; 4) there are no variables + +;;; Code: +(require 'ob) + +(defvar org-babel-default-header-args:maxima '()) + +(defun org-babel-maxima-expand (body params) + "Expand a block of Maxima code according to its header arguments." + body) + +(defun org-babel-execute:maxima (body params) + "Execute a block of Maxima entries with org-babel. This function is +called by `org-babel-execute-src-block'." + (message "executing Maxima source code block") + (let* ((result-params (split-string (or (cdr (assoc :results params)) ""))) + (cmdline (cdr (assoc :cmdline params))) + (in-file (org-babel-temp-file "maxima-")) + (cmd (format "maxima --very-quiet -r 'batchload(%S)$' %s" + in-file cmdline))) + (with-temp-file in-file (insert body)) + (message cmd) + ((lambda (raw) ;; " | grep -v batch | grep -v 'replaced' | sed '/^$/d' " + (mapconcat + identity + (delq nil + (mapcar (lambda (line) + (unless (or (string-match "batch" line) + (string-match "^rat: replaced .*$" line) + (= 0 (length line))) + line)) + (split-string raw))) "\n")) + (org-babel-eval cmd "")))) + +(defun org-babel-prep-session:maxima (session params) + (error "Maxima does not support sessions")) + +(provide 'ob-maxima) + +;; arch-tag: d86c97ac-7eab-4349-8d8b-302dd09779a8 + +;;; org-babel-maxima.el ends here diff --git a/lisp/org.el b/lisp/org.el index 96ad8ff..ae0ef5e 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -164,6 +164,7 @@ requirements) is loaded." (const :tag "Javascript" js) (const :tag "Latex" latex) (const :tag "Ledger" ledger) + (const :tag "Maxima" maxima) (const :tag "Matlab" matlab) (const :tag "Mscgen" mscgen) (const :tag "Ocaml" ocaml) -- 1.7.1 [-- Attachment #3: Type: text/plain, Size: 433 bytes --] > > *** simple test > #+begin_src maxima :results value > programmode: false; > eq: x**2-1 = 0; > solution: solve(eq, x); > print(solution); > #+end_src > > #+results: > | solve: | solution: | x | = | - | 1 | x | = | 1 | [%t1, | %t2] | > > This isn't necessary appropriate in this case... but I guess this is > now a matter of adding all the normal frills given that the basic > functionality is there? > > Thanks! ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-03-15 15:32 ` Eric Schulte @ 2011-03-15 16:39 ` Eric S Fraga 2011-03-15 17:27 ` Eric Schulte 0 siblings, 1 reply; 14+ messages in thread From: Eric S Fraga @ 2011-03-15 16:39 UTC (permalink / raw) To: Eric Schulte; +Cc: Litvinov Sergey, emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 1740 bytes --] "Eric Schulte" <schulte.eric@gmail.com> writes: > Eric S Fraga <e.fraga@ucl.ac.uk> writes: > >> "Eric Schulte" <schulte.eric@gmail.com> writes: >> >> [...] >> >>> >>> Ah, I see the problem, I used let instead of let*. Please try this >>> updated version of the patch. Sorry I would test this myself, but I >>> don't have Maxima installed. >> >> No problem at all! I'm happy to test this as many times as necessary. >> >> In any case, this works fine in that maxima is indeed evaluated and >> output is returned. However, two problems arise: >> >> 1. lines of the form "rat: replaced XXX by YYY = ZZZ" are not deleted >> (as used to be by the grep -v replaced hack I had in the original >> ob-maxima). Essentially, we need to ignore output lines that match >> the regex "^rat: replaced .*$" (I think this should do it...). >> >> 2. The output is converted to an org table: >> > > The attached should fix both of these problems. Please let me know how > this works. Eric, Well, it didn't work :(. However, I think I managed to fix it. I think you have an ulterior motive: to make me learn elisp properly once and for all... ;-). Attached is the updated ob-maxima.el file with two changes: 1. quoted =identity= in the =mapconcat= sexp. 2. asked =split-string= to split on newlines so that (a) the regex for the rat line would match *and* (b) so that the output is faithful to what maxima generates. I hope these make sense! I've gone through the code and I think I understand it. More importantly, the output is now essentially the same as I was getting before which makes me quite happy. I'll do some more testing but the various tests I have tried should cover most aspects that I ever use. Thanks, eric [-- Attachment #2: modified ob-maximal file --] [-- Type: application/emacs-lisp, Size: 2722 bytes --] [-- Attachment #3: Type: text/plain, Size: 125 bytes --] -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 : using Org-mode version 7.5 (release_7.5.38.gf8c6.dirty) ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-03-15 16:39 ` Eric S Fraga @ 2011-03-15 17:27 ` Eric Schulte 2011-03-15 18:32 ` Eric S Fraga 0 siblings, 1 reply; 14+ messages in thread From: Eric Schulte @ 2011-03-15 17:27 UTC (permalink / raw) To: Eric S Fraga; +Cc: Litvinov Sergey, emacs-orgmode Eric S Fraga <e.fraga@ucl.ac.uk> writes: > "Eric Schulte" <schulte.eric@gmail.com> writes: > >> Eric S Fraga <e.fraga@ucl.ac.uk> writes: >> >>> "Eric Schulte" <schulte.eric@gmail.com> writes: >>> >>> [...] >>> >>>> >>>> Ah, I see the problem, I used let instead of let*. Please try this >>>> updated version of the patch. Sorry I would test this myself, but I >>>> don't have Maxima installed. >>> >>> No problem at all! I'm happy to test this as many times as necessary. >>> >>> In any case, this works fine in that maxima is indeed evaluated and >>> output is returned. However, two problems arise: >>> >>> 1. lines of the form "rat: replaced XXX by YYY = ZZZ" are not deleted >>> (as used to be by the grep -v replaced hack I had in the original >>> ob-maxima). Essentially, we need to ignore output lines that match >>> the regex "^rat: replaced .*$" (I think this should do it...). >>> >>> 2. The output is converted to an org table: >>> >> >> The attached should fix both of these problems. Please let me know how >> this works. > > Eric, > > Well, it didn't work :(. > > However, I think I managed to fix it. I think you have an ulterior > motive: to make me learn elisp properly once and for all... ;-). > sure... that must be the reason I've put all these bugs in the code /looking around suspiciously/ > > Attached is the updated ob-maxima.el file with two changes: > > 1. quoted =identity= in the =mapconcat= sexp. > 2. asked =split-string= to split on newlines so that (a) the regex for > the rat line would match *and* (b) so that the output is faithful to > what maxima generates. > > I hope these make sense! I've gone through the code and I think I > understand it. More importantly, the output is now essentially the same > as I was getting before which makes me quite happy. > Great, these changes look good, I've just push this up to the org-mode repository. Thanks for contributing support for a new language! -- Eric > > I'll do some more testing but the various tests I have tried should > cover most aspects that I ever use. > > Thanks, > eric ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [babel] maxima support? 2011-03-15 17:27 ` Eric Schulte @ 2011-03-15 18:32 ` Eric S Fraga 0 siblings, 0 replies; 14+ messages in thread From: Eric S Fraga @ 2011-03-15 18:32 UTC (permalink / raw) To: Eric Schulte; +Cc: Litvinov Sergey, emacs-orgmode "Eric Schulte" <schulte.eric@gmail.com> writes: > Eric S Fraga <e.fraga@ucl.ac.uk> writes: >> However, I think I managed to fix it. I think you have an ulterior >> motive: to make me learn elisp properly once and for all... ;-). >> > > sure... that must be the reason I've put all these bugs in the code > /looking around suspiciously/ :-) [...] > Great, these changes look good, I've just push this up to the org-mode > repository. Thanks! -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 : using Org-mode version 7.5 (release_7.5.52.g0dc16.dirty) ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2011-03-15 18:32 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-02-23 9:32 [babel] maxima support? Litvinov Sergey 2011-02-24 10:25 ` Eric S Fraga 2011-02-24 10:28 ` Eric S Fraga 2011-02-25 9:17 ` Litvinov Sergey 2011-02-25 23:58 ` Eric Schulte 2011-02-28 16:15 ` Eric S Fraga 2011-03-14 21:26 ` Eric Schulte 2011-03-15 10:47 ` Eric S Fraga 2011-03-15 13:17 ` Eric Schulte 2011-03-15 14:27 ` Eric S Fraga 2011-03-15 15:32 ` Eric Schulte 2011-03-15 16:39 ` Eric S Fraga 2011-03-15 17:27 ` Eric Schulte 2011-03-15 18:32 ` Eric S Fraga
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).