From mboxrd@z Thu Jan 1 00:00:00 1970 From: Uwe Brauer Subject: Re: workflow, matlab+latex in org file Date: Fri, 10 Mar 2017 16:08:45 +0000 Message-ID: <87pohpcdwy.fsf@mat.ucm.es> References: <8760sc8ids.fsf@mat.ucm.es> <87shvg6z9i.fsf@mat.ucm.es> Reply-To: Uwe Brauer Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmN68-00072n-1v for emacs-orgmode@gnu.org; Fri, 10 Mar 2017 11:08:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmN64-0003Tg-1W for emacs-orgmode@gnu.org; Fri, 10 Mar 2017 11:08:56 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34129) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cmN63-0003SV-K8 for emacs-orgmode@gnu.org; Fri, 10 Mar 2017 11:08:51 -0500 Received: by mail-wm0-x241.google.com with SMTP id u132so3002969wmg.1 for ; Fri, 10 Mar 2017 08:08:50 -0800 (PST) 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: John Kitchin Cc: Uwe Brauer , emacs-orgmode@gnu.org >>> "John" == John Kitchin writes: Hi John, Quite some time ago you send me this code of yours. It somehow disappeared in my mail and only by now I tried it out, great, really Only one question I copied your code in a org file, executed the src sections and obtained: > #+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 How do I suppose to continue now? Because if I export this to a latex file the latex equations are not exported! I admit that I only use org files this way export them to latex and continue working. What do I miss? Thanks Uwe Your mail: >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 >