From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: workflow, matlab+latex in org file Date: Mon, 11 Jul 2016 11:55:40 -0400 Message-ID: References: <8760sc8ids.fsf@mat.ucm.es> <87shvg6z9i.fsf@mat.ucm.es> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMdYh-0001pm-7y for emacs-orgmode@gnu.org; Mon, 11 Jul 2016 11:55:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMdYe-00078L-4S for emacs-orgmode@gnu.org; Mon, 11 Jul 2016 11:55:47 -0400 Received: from mail-qk0-x236.google.com ([2607:f8b0:400d:c09::236]:33668) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMdYd-000788-VK for emacs-orgmode@gnu.org; Mon, 11 Jul 2016 11:55:44 -0400 Received: by mail-qk0-x236.google.com with SMTP id p74so61889700qka.0 for ; Mon, 11 Jul 2016 08:55:43 -0700 (PDT) In-reply-to: <87shvg6z9i.fsf@mat.ucm.es> 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" To: Uwe Brauer Cc: emacs-orgmode@gnu.org You might consider the alternative, no-frills approach below. I defined a new execute function that strips the header and >> out of the output. It won't support any kind of session or header variables, but if you don't use those it might work for you. #+BEGIN_SRC emacs-lisp (defun org-babel-execute:matlab (body params) (interactive "P") (let* ((current-file (buffer-file-name)) (code (org-element-property :value (org-element-context))) (result-params (cdr (assoc :result-params params))) m-file md5-hash) (with-temp-buffer (insert code) (setq md5-hash (md5 (buffer-string)) mbuffer (format "*m-%s*" md5-hash) m-file (format "m-%s.m" md5-hash))) ;; create the file to run (with-temp-file m-file (insert code)) (let ((results (shell-command-to-string (concat "/Applications/MATLAB_R2013a.app/bin/matlab " "-nodesktop -nojvm -nosplash -nodisplay <" m-file)))) (delete-file m-file) (when results ;; strip out >> (setq results (replace-regexp-in-string ">> " "" results)) ;; remove first 10 lines that are the header. (setq results (mapconcat 'identity (nthcdr 10 (split-string results "\n")) "\n"))) (org-babel-result-cond result-params results)))) #+END_SRC #+begin_src matlab :results output latex clear all; syms e p R g w K K2; phi=[(e + (e+p)*R^2)^((g-1)/2);((e+p)*R*sqrt(1+R^2))/(e+(e+p)*R^2)]; jac=jacobian(phi,[e,p]); ltxjac=latex(jac); disp(ltxjac) #+end_src #+RESULTS: #+BEGIN_LaTeX \left(\begin{array}{cc} {\left(\left(e + p\right)\, R^2 + e\right)}^{\frac{g}{2} - \frac{3}{2}}\, \left(R^2 + 1\right)\, \left(\frac{g}{2} - \frac{1}{2}\right) & R^2\, {\left(\left(e + p\right)\, R^2 + e\right)}^{\frac{g}{2} - \frac{3}{2}}\, \left(\frac{g}{2} - \frac{1}{2}\right)\\ \frac{R\, \sqrt{R^2 + 1}}{\left(e + p\right)\, R^2 + e} - \frac{R\, {\left(R^2 + 1\right)}^{\frac{3}{2}}\, \left(e + p\right)}{{\left(\left(e + p\right)\, R^2 + e\right)}^2} & \frac{R\, \sqrt{R^2 + 1}}{\left(e + p\right)\, R^2 + e} - \frac{R^3\, \sqrt{R^2 + 1}\, \left(e + p\right)}{{\left(\left(e + p\right)\, R^2 + e\right)}^2} \end{array}\right) #+END_LaTeX Uwe Brauer writes: >>>> "John" == John Kitchin writes: > > > Here is an example using sympy. I think you will have to wrap the matlab > > output in $$ yourself if that is what you want. > > Right. Using your example I obtain: > ,---- > | > | > | < M A T L A B (R) > > | Copyright 1984-2010 The MathWorks, Inc. > | Version 7.10.0.499 (R2010a) 32-bit (glnx86) > | February 5, 2010 > | > | > | To get started, type one of these: helpwin, helpdesk, or demo. > | For product information, visit www.mathworks.com. > | > | >> >> >> >> >> >> > | ltxjac = > | > | \left(\begin{array}{cc} {\left(\left(e + p\right)\, R^2 + e\right)}^{\frac{g}{2} - \frac{3}{2}}\, \left(R^2 + 1\right)\, \left(\frac{g}{2} - \frac{1}{2}\right) & R^2\, {\left(\left(e + p\right)\, R^2 + e\right)}^{\frac{g}{2} - \frac{3}{2}}\, \left(\frac{g}{2} - \frac{1}{2}\right)\\ \frac{R\, \sqrt{R^2 + 1}}{\left(e + p\right)\, R^2 + e} - \frac{R\, {\left(R^2 + 1\right)}^{\frac{3}{2}}\, \left(e + p\right)}{{\left(\left(e + p\right)\, R^2 + e\right)}^2} & \frac{R\, \sqrt{R^2 + 1}}{\left(e + p\right)\, R^2 + e} - \frac{R^3\, \sqrt{R^2 + 1}\, \left(e + p\right)}{{\left(\left(e + p\right)\, R^2 + e\right)}^2} \end{array}\right) > | > | >> > `---- > > That is not perfect but much better than the original solutions, thanks > > Uwe -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu