From mboxrd@z Thu Jan 1 00:00:00 1970 From: Scott Randby Subject: Re: workflow, matlab+latex in org file Date: Fri, 10 Mar 2017 12:51:37 -0500 Message-ID: <71b17ad2-04a9-c5fe-e431-7bd5e7804949@gmail.com> References: <8760sc8ids.fsf@mat.ucm.es> <87shvg6z9i.fsf@mat.ucm.es> <87pohpcdwy.fsf@mat.ucm.es> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmOhd-0001SP-3Z for emacs-orgmode@gnu.org; Fri, 10 Mar 2017 12:51:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmOhZ-0003Ar-35 for emacs-orgmode@gnu.org; Fri, 10 Mar 2017 12:51:45 -0500 Received: from mail-io0-x232.google.com ([2607:f8b0:4001:c06::232]:35206) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cmOhY-0003A9-Rj for emacs-orgmode@gnu.org; Fri, 10 Mar 2017 12:51:40 -0500 Received: by mail-io0-x232.google.com with SMTP id z13so53311700iof.2 for ; Fri, 10 Mar 2017 09:51:39 -0800 (PST) In-Reply-To: <87pohpcdwy.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 , emacs-orgmode@gnu.org On 03/10/2017 11:08 AM, Uwe Brauer wrote: >>>> "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. You need to change "#+BEGIN_LaTeX" to "#+begin_export latex" and "#+END_LaTeX" to "#+end_export" for Org 9.0 and above. Scott Randby > > 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 >> > >