From mboxrd@z Thu Jan 1 00:00:00 1970 From: Litvinov Sergey Subject: [BABEL][PATCH] construct a table from the output of maxima code block Date: Sat, 01 Oct 2011 22:37:14 +0200 Message-ID: <87ehywh2it.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:43167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RA6JO-0006np-6a for emacs-orgmode@gnu.org; Sat, 01 Oct 2011 16:37:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RA6JM-0000HR-Cb for emacs-orgmode@gnu.org; Sat, 01 Oct 2011 16:37:30 -0400 Received: from lo.gmane.org ([80.91.229.12]:43326) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RA6JL-0000HL-RQ for emacs-orgmode@gnu.org; Sat, 01 Oct 2011 16:37:28 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RA6JJ-0001UB-3x for emacs-orgmode@gnu.org; Sat, 01 Oct 2011 22:37:25 +0200 Received: from e181024187.adsl.alicedsl.de ([85.181.24.187]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 01 Oct 2011 22:37:25 +0200 Received: from slitvinov by e181024187.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 01 Oct 2011 22:37:25 +0200 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 Please consider a patch to construct a table from the output of maxima code block. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ob-maxima-Construct-a-table-from-the-output-of-the-c.patch >From a0305117f4e793c93d7d10bc7aab04f96bd62e9c Mon Sep 17 00:00:00 2001 From: Litvinov Sergey Date: Sat, 1 Oct 2011 22:29:18 +0200 Subject: [PATCH] [ob-maxima] Construct a table from the output of the code block. Add ert tests. --- lisp/ob-maxima.el | 8 +++- testing/README.org | 1 + testing/examples/ob-maxima-test.org | 64 +++++++++++++++++++-------- testing/lisp/test-ob-maxima.el | 82 +++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 19 deletions(-) create mode 100644 testing/lisp/test-ob-maxima.el diff --git a/lisp/ob-maxima.el b/lisp/ob-maxima.el index 3b4f6a0..9c39a5f 100644 --- a/lisp/ob-maxima.el +++ b/lisp/ob-maxima.el @@ -84,7 +84,13 @@ called by `org-babel-execute-src-block'." (org-babel-eval cmd ""))))) (if (org-babel-maxima-graphical-output-file params) nil - result))) + (if (or (member "scalar" result-params) + (member "verbatim" result-params) + (member "output" result-params)) + result + (let ((tmp-file (org-babel-temp-file "maxima-res-"))) + (with-temp-file tmp-file (insert result)) + (org-babel-import-elisp-from-file tmp-file)))))) (defun org-babel-prep-session:maxima (session params) diff --git a/testing/README.org b/testing/README.org index 2f16a55..eba147f 100644 --- a/testing/README.org +++ b/testing/README.org @@ -80,6 +80,7 @@ First tangle this file out to your desktop. (concat org-dir "/testing/examples/normal.org") (concat org-dir "/testing/examples/ob-awk-test.org") (concat org-dir "/testing/examples/ob-fortran-test.org") + (concat org-dir "/testing/examples/ob-maxima-test.org") (concat org-dir "/testing/examples/link-in-heading.org") (concat org-dir "/testing/examples/links.org"))) diff --git a/testing/examples/ob-maxima-test.org b/testing/examples/ob-maxima-test.org index 23c76e7..ad5fc80 100644 --- a/testing/examples/ob-maxima-test.org +++ b/testing/examples/ob-maxima-test.org @@ -1,13 +1,20 @@ -* Test org maxima file +#+Title: a collection of examples for ob-maxima tests +#+OPTIONS: ^:nil + +* Simple tests + :PROPERTIES: + :ID: b5842ed4-8e8b-4b18-a1c9-cef006b6a6c8 + :END: #+begin_src maxima :var s=4 :results silent print(s); #+end_src Pass a string #+begin_src maxima :var fun="sin(x)" :var q=2 :results silent -print(diff(fun, x, q)); +print(diff(fun, x, q))$ #+end_src +* Graphic output Graphic output #+begin_src maxima :var a=0.5 :results graphics :file maxima-test-sin.png plot2d(sin(a*x), [x, 0, 2*%pi])$ @@ -16,21 +23,28 @@ plot2d(sin(a*x), [x, 0, 2*%pi])$ #+begin_src maxima :results graphics :file maxima-test-3d.png plot3d (2^(-u^2 + v^2), [u, -3, 3], [v, -2, 2])$ #+end_src - +* Output to a file Output to a file #+begin_src maxima :file maxima-test-ouput.out for i:1 thru 10 do print(i)$ #+end_src - -List as input -#+begin_src maxima :var a=(list 1 2 3) -print(a+1); +* List input + :PROPERTIES: + :ID: b5561c6a-73cd-453a-ba5e-62ad84844de6 + :END: +Simple list as an input +#+begin_src maxima :var a=(list 1 2 3) :results silent :results verbatim +print(a)$ #+end_src -#+begin_src maxima :var a=(list 1 (list 1 2) 3) +#+begin_src maxima :var a=(list 1 (list 1 2) 3) :results silent :results verbatim print(a+1); #+end_src +* Table input + :PROPERTIES: + :ID: 400ee228-6b12-44fd-8097-7986f0f0db43 + :END: #+tblname: test_tbl_col | 1.0 | | 2.0 | @@ -38,26 +52,40 @@ print(a+1); #+tblname: test_tbl_row | 1.0 | 2.0 | -Extra bracket? TODO: -#+begin_src maxima :var s=test_tbl_col +#+begin_src maxima :var s=test_tbl_col :results silent :results verbatim print(s+1.0); #+end_src -#+begin_src maxima :var s=test_tbl_row +#+begin_src maxima :var s=test_tbl_row :results silent :results verbatim print(s+1.0); #+end_src Matrix -#+tblname: test_tbl_mtr +#+tblname: test_tbl_mtr | 1.0 | 1.0 | -| 0.0 | 4.0 | -#+begin_src maxima :var s=test_tbl_mtr +#+begin_src maxima :var s=test_tbl_mtr :results silent :results verbatim ms: apply(matrix, s); -print(ms^^2); +print(ms); #+end_src -#+begin_src maxima :var s=test_tbl_mtr -ms: apply(matrix, s); -print(ms^^2); +* Construct a table from the output + :PROPERTIES: + :ID: cc158527-b867-4b1d-8ae0-b8c713a90fd7 + :END: +#+begin_src maxima :var s=test_tbl_mtr :results silent +m: genmatrix (lambda([i,j], i+j-1), 3, 3)$ +write_data(m, "/dev/stdout")$ #+end_src + +* Latex output +#+begin_src maxima :exports both :results latex :results verbatim +assume(x>0); +tex(ratsimp(diff(%e^(a*x), x))); +#+end_src + +#+results: +#+BEGIN_LaTeX +$$a\,e^{a\,x}$$ +#+END_LaTeX + diff --git a/testing/lisp/test-ob-maxima.el b/testing/lisp/test-ob-maxima.el new file mode 100644 index 0000000..dff4033 --- /dev/null +++ b/testing/lisp/test-ob-maxima.el @@ -0,0 +1,82 @@ +;;; test-ob-maxima.el --- tests for ob-maxima.el + +;; Copyright (c) 2010 Sergey Litvinov +;; Authors: Sergey Litvinov + +;; Released under the GNU General Public License version 3 +;; see: http://www.gnu.org/licenses/gpl-3.0.html + +(org-test-for-executable "maxima") + +(let ((load-path (cons (expand-file-name + ".." (file-name-directory + (or load-file-name buffer-file-name))) + load-path))) + (require 'org-test) + (require 'org-test-ob-consts)) + +(let ((load-path (cons (expand-file-name + "langs" + (expand-file-name + "babel" + (expand-file-name + "contrib" + (expand-file-name + ".." + (expand-file-name + ".." + (file-name-directory + (or load-file-name buffer-file-name))))))) + load-path))) + + (require 'ob-maxima)) + +(ert-deftest ob-maxima/assert () + (should t)) + +(ert-deftest ob-maxima/integer-input () + "Test of integer input" + (org-test-at-id "b5842ed4-8e8b-4b18-a1c9-cef006b6a6c8" + (org-babel-next-src-block) + (should (equal 4 (org-babel-execute-src-block))))) + +(ert-deftest ob-maxima/string-input () + "Test of string input" + (org-test-at-id "b5842ed4-8e8b-4b18-a1c9-cef006b6a6c8" + (org-babel-next-src-block 2) + (should (equal "- sin(x)" (org-babel-execute-src-block))))) + +(ert-deftest ob-maxima/simple-list-input () + "Test of flat list input" + (org-test-at-id "b5561c6a-73cd-453a-ba5e-62ad84844de6" + (org-babel-next-src-block) + (should (equal "[1, 2, 3] " (org-babel-execute-src-block))))) + +(ert-deftest ob-maxima/list-input () + "Test of list input" + (org-test-at-id "b5561c6a-73cd-453a-ba5e-62ad84844de6" + (org-babel-next-src-block 2) + (should (equal "[2, [2, 3], 4] " (org-babel-execute-src-block))))) + +(ert-deftest ob-maxima/table-input1 () + "Test of table input" + (org-test-at-id "400ee228-6b12-44fd-8097-7986f0f0db43" + (org-babel-next-src-block) + (should (equal "[[2.0], [3.0]] " (org-babel-execute-src-block))))) + +(ert-deftest ob-maxima/table-input2 () + "Test of table input" + (org-test-at-id "400ee228-6b12-44fd-8097-7986f0f0db43" + (org-babel-next-src-block 2) + (should (equal "[[2.0, 3.0]] " (org-babel-execute-src-block))))) + +(ert-deftest ob-maxima/matrix-output () + "Test of table output" + (org-test-at-id "cc158527-b867-4b1d-8ae0-b8c713a90fd7" + (org-babel-next-src-block) + (should (equal '((1 2 3) (2 3 4) (3 4 5)) (org-babel-execute-src-block))))) + +(provide 'test-ob-maxima) + +;;; test-ob-maxima.el ends here + -- 1.7.4.1 --=-=-=--