emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Litvinov Sergey <slitvinov@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [BABEL][PATCH] construct a table from the output of maxima code block
Date: Sat, 01 Oct 2011 22:37:14 +0200	[thread overview]
Message-ID: <87ehywh2it.fsf@gmail.com> (raw)

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

Please consider a patch to construct a table from the output of maxima
code block.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-maxima-Construct-a-table-from-the-output-of-the-c.patch --]
[-- Type: text/x-diff, Size: 7408 bytes --]

From a0305117f4e793c93d7d10bc7aab04f96bd62e9c Mon Sep 17 00:00:00 2001
From: Litvinov Sergey <slitvinov@gmail.com>
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


             reply	other threads:[~2011-10-01 20:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-01 20:37 Litvinov Sergey [this message]
2011-10-04 15:50 ` [BABEL][PATCH] construct a table from the output of maxima code block Eric S Fraga
2011-10-04 17:57   ` Sergey Litvinov
2011-10-06 14:51     ` Eric Schulte
2011-10-10  9:36     ` Eric S Fraga

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=87ehywh2it.fsf@gmail.com \
    --to=slitvinov@gmail.com \
    --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).