emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] workflow, matlab+latex in org file


From: Uwe Brauer
Subject: Re: [O] workflow, matlab+latex in org file
Date: Fri, 10 Mar 2017 16:08:45 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

>>> "John" == John Kitchin <address@hidden> 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 <address@hidden> 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
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]