all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* workflow, matlab+latex in org file
@ 2016-07-11 12:32 Uwe Brauer
  2016-07-11 14:05 ` John Kitchin
  0 siblings, 1 reply; 27+ messages in thread
From: Uwe Brauer @ 2016-07-11 12:32 UTC (permalink / raw)
  To: emacs-orgmode

Hello

I want in a org file, to include matlab code and run it (that I know how
to do)

Then I want certain results, which are symbolic variables, expressed in
latex, we I achieve  using matlab's latex command.

Like
#+begin_src matlab :results output
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)
#+end_src


This result should of course also be included in the orgfile.

But then I want to export the org file to latex, such that only the
results, which have been converted to latex are exported and all the
matlab command should be ignored, that is in that case:
ltxjac but nicely surrounded by say $.

Anybody has an idea how to do this efficiently?

thanks

regards



Uwe Brauer 

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
       [not found] <m2eg709w4s.fsf@gmail.com>
@ 2016-07-11 13:55 ` Uwe Brauer
  0 siblings, 0 replies; 27+ messages in thread
From: Uwe Brauer @ 2016-07-11 13:55 UTC (permalink / raw)
  To: Ken Mankoff; +Cc: emacs-orgmode

>>> "Ken" == Ken Mankoff <mankoff@gmail.com> writes:

   > I can't execute your code,

Why not
   >  but what does ":results output latex" show?
   > And what if you add the ";" to each line so it is not printed, except
   > the last, which is perhaps explicitly printed?


You are right! Thanks.

So I tried

#+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)
#+end_src

Problem is when I export that to a latex file, the exporter always uses
the verbatim environment, but this is not what I want, I want directly
the result of ltxjac=latex(jac) interpreted as latex not as source code.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2016-07-11 12:32 Uwe Brauer
@ 2016-07-11 14:05 ` John Kitchin
  2016-07-11 14:11   ` Uwe Brauer
  0 siblings, 1 reply; 27+ messages in thread
From: John Kitchin @ 2016-07-11 14:05 UTC (permalink / raw)
  To: Uwe Brauer; +Cc: emacs-orgmode

Here is an example using sympy. I think you will have to wrap the matlab
output in $$ yourself if that is what you want. Otherwise, the :exports 
header below specifies to only export the results, and the :results
header wraps the output in a latex environment.

#+BEGIN_SRC python :results output latex :exports results
from sympy import Integral, sqrt, symbols, latex

x = symbols('x')
 
print(latex(Integral(sqrt(1/x), x), mode='equation'))
#+END_SRC

#+RESULTS:
#+BEGIN_LaTeX
\begin{equation}\int \sqrt{\frac{1}{x}}\, dx\end{equation}
#+END_LaTeX




Uwe Brauer writes:

> Hello
>
> I want in a org file, to include matlab code and run it (that I know how
> to do)
>
> Then I want certain results, which are symbolic variables, expressed in
> latex, we I achieve  using matlab's latex command.
>
> Like
> #+begin_src matlab :results output
> 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)
> #+end_src
>
>
> This result should of course also be included in the orgfile.
>
> But then I want to export the org file to latex, such that only the
> results, which have been converted to latex are exported and all the
> matlab command should be ignored, that is in that case:
> ltxjac but nicely surrounded by say $.
>
> Anybody has an idea how to do this efficiently?
>
> thanks
>
> regards
>
>
>
> Uwe Brauer 


-- 
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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2016-07-11 14:05 ` John Kitchin
@ 2016-07-11 14:11   ` Uwe Brauer
  2016-07-11 15:55     ` John Kitchin
  0 siblings, 1 reply; 27+ messages in thread
From: Uwe Brauer @ 2016-07-11 14:11 UTC (permalink / raw)
  To: emacs-orgmode

>>> "John" == John Kitchin <jkitchin@andrew.cmu.edu> 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 

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2016-07-11 14:11   ` Uwe Brauer
@ 2016-07-11 15:55     ` John Kitchin
  2016-07-11 16:12       ` Uwe Brauer
                         ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: John Kitchin @ 2016-07-11 15:55 UTC (permalink / raw)
  To: Uwe Brauer; +Cc: emacs-orgmode

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 <jkitchin@andrew.cmu.edu> 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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2016-07-11 15:55     ` John Kitchin
@ 2016-07-11 16:12       ` Uwe Brauer
  2017-03-10 16:08       ` Uwe Brauer
       [not found]       ` <5e1e71e3698e415ca51a0b9e3cab5dac@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
  2 siblings, 0 replies; 27+ messages in thread
From: Uwe Brauer @ 2016-07-11 16:12 UTC (permalink / raw)
  To: emacs-orgmode

>>> "John" == John Kitchin <jkitchin@andrew.cmu.edu> writes:

   > 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.

Great, I had to modify your call of the matlab bin, but then it works
like charm, thanks very much.

Maybe to add it to the org-addons somewhere?

Uwe 

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
       [not found] <c0b96d809e4b41529f81beaa685a9fd0@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
@ 2016-07-11 16:42 ` Eric S Fraga
  2016-07-12 12:44   ` Uwe Brauer
  0 siblings, 1 reply; 27+ messages in thread
From: Eric S Fraga @ 2016-07-11 16:42 UTC (permalink / raw)
  To: emacs-orgmode

On Monday, 11 Jul 2016 at 12:32, Uwe Brauer wrote:
> Hello
>
> I want in a org file, to include matlab code and run it (that I know how
> to do)
>
> Then I want certain results, which are symbolic variables, expressed in
> latex, we I achieve  using matlab's latex command.
>
> Like
>
> #+begin_src matlab :results output
> 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)
> #+end_src

A bit of a kludge but, if you don't want to modify the ob-matlab code,
you can explicitly generate LaTeX into a file and use it directly:

--8<---------------cut here---------------start------------->8---
#+begin_src octave :exports none :results output
  clear all
  pkg load symbolic
  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);
  fid = fopen("jacobian.tex","w");
  fprintf(fid, "%s\n", ltxjac);
  fclose(fid);
  ltxjac
#+end_src

\begin{equation}
\input{jacobian}
\end{equation}
--8<---------------cut here---------------end--------------->8---

I don't have MATLAB so have tested with octave instead...

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.94.1, Org release_8.3.4-869-gf2c421

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2016-07-11 16:42 ` Eric S Fraga
@ 2016-07-12 12:44   ` Uwe Brauer
  0 siblings, 0 replies; 27+ messages in thread
From: Uwe Brauer @ 2016-07-12 12:44 UTC (permalink / raw)
  To: emacs-orgmode

>>> "Eric" == Eric S Fraga <e.fraga@ucl.ac.uk> writes:

   > On Monday, 11 Jul 2016 at 12:32, Uwe Brauer wrote:
   >> Hello
   >> 
   >> I want in a org file, to include matlab code and run it (that I know how
   >> to do)
   >> 
   >> Then I want certain results, which are symbolic variables, expressed in
   >> latex, we I achieve  using matlab's latex command.
   >> 
   >> Like
   >> 
   >> #+begin_src matlab :results output
   >> 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)
   >> #+end_src

   > A bit of a kludge but, if you don't want to modify the ob-matlab code,
   > you can explicitly generate LaTeX into a file and use it directly:

   > #+begin_src octave :exports none :results output
   >   clear all
   >   pkg load symbolic
   >   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);
   >   fid = fopen("jacobian.tex","w");
   >   fprintf(fid, "%s\n", ltxjac);
   >   fclose(fid);
   >   ltxjac
   > #+end_src

   > \begin{equation}
   > \input{jacobian}
   > \end{equation}

Thanks, that is a solution but  a bit cumbersome because of the
additional latex file. John sent me a hack which seems a bit more
flexible.

Uwe 
   > I don't have MATLAB so have tested with octave instead...

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2016-07-11 15:55     ` John Kitchin
  2016-07-11 16:12       ` Uwe Brauer
@ 2017-03-10 16:08       ` Uwe Brauer
  2017-03-10 17:51         ` Scott Randby
       [not found]       ` <5e1e71e3698e415ca51a0b9e3cab5dac@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
  2 siblings, 1 reply; 27+ messages in thread
From: Uwe Brauer @ 2017-03-10 16:08 UTC (permalink / raw)
  To: John Kitchin; +Cc: Uwe Brauer, emacs-orgmode

>>> "John" == John Kitchin <jkitchin@andrew.cmu.edu> 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 <jkitchin@andrew.cmu.edu> 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
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-10 16:08       ` Uwe Brauer
@ 2017-03-10 17:51         ` Scott Randby
  2017-03-10 21:15           ` Uwe Brauer
  0 siblings, 1 reply; 27+ messages in thread
From: Scott Randby @ 2017-03-10 17:51 UTC (permalink / raw)
  To: Uwe Brauer, emacs-orgmode

On 03/10/2017 11:08 AM, Uwe Brauer wrote:
>>>> "John" == John Kitchin <jkitchin@andrew.cmu.edu> 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 <jkitchin@andrew.cmu.edu> 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
>>
> 
> 

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
       [not found]       ` <5e1e71e3698e415ca51a0b9e3cab5dac@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
@ 2017-03-10 18:03         ` Eric S Fraga
  2017-03-10 21:18           ` Uwe Brauer
                             ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Eric S Fraga @ 2017-03-10 18:03 UTC (permalink / raw)
  To: emacs-orgmode

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

On Friday, 10 Mar 2017 at 16:08, Uwe Brauer wrote:
>>>> "John" == John Kitchin <jkitchin@andrew.cmu.edu> 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

[...]

> 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 may need to add ":exports results" to the src line.

Also, you should also modify the code to wrap the output in an equation
environment:

disp('\begin{equation}')
disp(ltxjac)
disp('\end{equation}')

this works for me then.

-- 
Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-10 17:51         ` Scott Randby
@ 2017-03-10 21:15           ` Uwe Brauer
  2017-03-10 21:56             ` John Kitchin
  2017-03-11 23:50             ` Scott Randby
  0 siblings, 2 replies; 27+ messages in thread
From: Uwe Brauer @ 2017-03-10 21:15 UTC (permalink / raw)
  To: emacs-orgmode


   > On 03/10/2017 11:08 AM, Uwe Brauer wrote:

   > You need to change "#+BEGIN_LaTeX" to "#+begin_export latex" and
   > "#+END_LaTeX" to "#+end_export" for Org 9.0 and above.

Thanks, very much, I never understand what is the benefit of those
changes which break backward compatibility (or forward compatibility)

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-10 18:03         ` Eric S Fraga
@ 2017-03-10 21:18           ` Uwe Brauer
  2017-03-11  8:04           ` Uwe Brauer
       [not found]           ` <cf7ef1dfa1cf455bbaf63ab5fbdf18e5@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
  2 siblings, 0 replies; 27+ messages in thread
From: Uwe Brauer @ 2017-03-10 21:18 UTC (permalink / raw)
  To: emacs-orgmode


   > On Friday, 10 Mar 2017 at 16:08, Uwe Brauer wrote:

   > [...]


   > You may need to add ":exports results" to the src line.

   > Also, you should also modify the code to wrap the output in an equation
   > environment:

   > disp('\begin{equation}')
   > disp(ltxjac)
   > disp('\end{equation}')

   > this works for me then.
Thanks

I want to dig more into that especially when it comes to the output of
non symbolic variables (which is the default) to format those
expressions seems harder to me.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-10 21:15           ` Uwe Brauer
@ 2017-03-10 21:56             ` John Kitchin
  2017-03-10 22:50               ` Uwe Brauer
  2017-03-11 23:50             ` Scott Randby
  1 sibling, 1 reply; 27+ messages in thread
From: John Kitchin @ 2017-03-10 21:56 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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

I get the right wrapper around the results block in the org-file. I did
have to add :exports results
to the header to get it to export though.

John

-----------------------------------
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


On Fri, Mar 10, 2017 at 4:15 PM, Uwe Brauer <oub@mat.ucm.es> wrote:

>
>    > On 03/10/2017 11:08 AM, Uwe Brauer wrote:
>
>    > You need to change "#+BEGIN_LaTeX" to "#+begin_export latex" and
>    > "#+END_LaTeX" to "#+end_export" for Org 9.0 and above.
>
> Thanks, very much, I never understand what is the benefit of those
> changes which break backward compatibility (or forward compatibility)
>
>
>

[-- Attachment #2: Type: text/html, Size: 1477 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-10 21:56             ` John Kitchin
@ 2017-03-10 22:50               ` Uwe Brauer
  0 siblings, 0 replies; 27+ messages in thread
From: Uwe Brauer @ 2017-03-10 22:50 UTC (permalink / raw)
  To: emacs-orgmode

>>> "John" == John Kitchin <jkitchin@andrew.cmu.edu> writes:

   > I get the right wrapper around the results block in the org-file. I did
   > have to add :exports results
   > to the header to get it to export though.

Thanks ok the whole message you sent me I can now copy into a org file
and export it to latex, very nice.

However I just realized that I don't understand the logic of what you
sent to me. So it looks like

#+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

That lisp function uses a m-file, but which one?

When I run the lisp code in my org file (changing the path to my matlab
installations path) I obtain

#+RESULTS:
: org-babel-execute:matlab

But not what you have sent to me and I copied below namely

#+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

which I presume is your 
output of the lisp function?

I am sorry but I am more confused than ever.

I even see that I cannot (after I have executed your lisp function)
execute anymore the following

#+begin_src matlab :results output

t=[-3 -2 1 4 6]
y=[2 0 3 1 4]
cs = spline(t,[0 y 0 ])
[b,c,l,k,d]= unmkpp(cs)
#+end_src

I tested it several times. I restart emacs open an org mode with the
above matlab instructions and I can execute matlab. Then I execute your
lisp code and I cannot run matlab anymore in an org buffer. 
What is wrong here?


Uwe 

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-10 18:03         ` Eric S Fraga
  2017-03-10 21:18           ` Uwe Brauer
@ 2017-03-11  8:04           ` Uwe Brauer
  2017-03-11 13:23             ` John Kitchin
       [not found]           ` <cf7ef1dfa1cf455bbaf63ab5fbdf18e5@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
  2 siblings, 1 reply; 27+ messages in thread
From: Uwe Brauer @ 2017-03-11  8:04 UTC (permalink / raw)
  To: emacs-orgmode


    > On Friday, 10 Mar 2017 at 16:08, Uwe Brauer wrote:

    > [...]


    > You may need to add ":exports results" to the src line.

    > Also, you should also modify the code to wrap the output in an equation
    > environment:

    > disp('\begin{equation}')
    > disp(ltxjac)
    > disp('\end{equation}')


I played a bit more around, and John's code is a great help but the
matlab output for non symbolic variables is just awful

As in
#+begin_src matlab :results output 
clear all;
x=[ 1 2 2 3 4]
#+end_src

#+RESULTS:
: 
: x =
: 
:      1     2     2     3     4
: 

Does anybody know how to get a better formatted output, to get rid of
the empty lines and newline? best would be a org-table?

org-table-convert-region results in 

| :      1     2     2     3     4 |

Uwe Brauer 

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
       [not found]           ` <cf7ef1dfa1cf455bbaf63ab5fbdf18e5@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
@ 2017-03-11 10:37             ` Eric S Fraga
  2017-03-11 14:12               ` Uwe Brauer
  0 siblings, 1 reply; 27+ messages in thread
From: Eric S Fraga @ 2017-03-11 10:37 UTC (permalink / raw)
  To: emacs-orgmode

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

On Saturday, 11 Mar 2017 at 08:04, Uwe Brauer wrote:
> Does anybody know how to get a better formatted output, to get rid of
> the empty lines and newline? best would be a org-table?

Instead of relying on MATLAB's default output, you can generate
formatted output using fprintf [1].


Footnotes: 
[1]  https://uk.mathworks.com/matlabcentral/newsreader/view_thread/44148?requestedDomain=www.mathworks.com

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 26.0.50.1, Org release_9.0.4-242-g2c27b8

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-11  8:04           ` Uwe Brauer
@ 2017-03-11 13:23             ` John Kitchin
  2017-03-11 14:16               ` Uwe Brauer
  2017-10-20 11:03               ` Uwe Brauer
  0 siblings, 2 replies; 27+ messages in thread
From: John Kitchin @ 2017-03-11 13:23 UTC (permalink / raw)
  To: Uwe Brauer; +Cc: emacs-orgmode

You might dig around in ob-octave to see how it works. It should be able
to Matlab (and on Linux/Mac I believe it might). On Windows, it has been
broken for a long time due to the lack of a proper shell (maybe that can
be adapted in win10 though).

I vaguely recall making that matlab function to try it out on Windows
some years ago.

There is a Jupyter Matlab kernel now.
https://github.com/Calysto/matlab_kernel

I was able to use this (and installing the kernel, and making sure a
matlab is on the path):

#+BEGIN_SRC emacs-lisp
(add-to-list 'org-src-lang-modes '("matlab" . matlab))

;; set default headers for convenience
(setq org-babel-default-header-args:matlab
      '((:results . "output replace")
	(:session . "matlab")
	(:kernel . "matlab")
	(:exports . "code")
	(:cache .   "no")
	(:noweb . "no")
	(:hlines . "no")
	(:tangle . "no")))

(defalias 'org-babel-execute:matlab 'org-babel-execute:ipython)
(defalias 'org-babel-prep-session:matlab 'org-babel-prep-session:ipython)
(defalias 'org-babel-matlab-initiate-session 'org-babel-ipython-initiate-session)
#+END_SRC

#+RESULTS:
: org-babel-matlab-initiate-session

To enable this:

#+BEGIN_SRC matlab :results output org drawer
x = [1, 2, 3, 4, 5];
fprintf('|%d', x)
#+END_SRC

#+RESULTS:
:RESULTS:
| 1 | 2 | 3 | 4 | 5 |
:END:

It is not much better output wise without the fprintf, but that seems to
be a feature of Matlab's output. I think Eric is probably right, you
will have use fprintf to get what you want.

I am not a big matlab user these days, so I do not have a sense for how
usable the kernel is. It does run in a session, which is a big
improvement over the other one I wrote.

Uwe Brauer writes:

>     > On Friday, 10 Mar 2017 at 16:08, Uwe Brauer wrote:
>
>     > [...]
>
>
>     > You may need to add ":exports results" to the src line.
>
>     > Also, you should also modify the code to wrap the output in an equation
>     > environment:
>
>     > disp('\begin{equation}')
>     > disp(ltxjac)
>     > disp('\end{equation}')
>
>
> I played a bit more around, and John's code is a great help but the
> matlab output for non symbolic variables is just awful
>
> As in
> #+begin_src matlab :results output
> clear all;
> x=[ 1 2 2 3 4]
> #+end_src
>
> #+RESULTS:
> :
> : x =
> :
> :      1     2     2     3     4
> :
>
> Does anybody know how to get a better formatted output, to get rid of
> the empty lines and newline? best would be a org-table?
>
> org-table-convert-region results in
>
> | :      1     2     2     3     4 |
>
> Uwe Brauer


--
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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-11 10:37             ` Eric S Fraga
@ 2017-03-11 14:12               ` Uwe Brauer
  0 siblings, 0 replies; 27+ messages in thread
From: Uwe Brauer @ 2017-03-11 14:12 UTC (permalink / raw)
  To: emacs-orgmode

>>> "Eric" == Eric S Fraga <e.fraga@ucl.ac.uk> writes:

    > On Saturday, 11 Mar 2017 at 08:04, Uwe Brauer wrote:
    >> Does anybody know how to get a better formatted output, to get rid of
    >> the empty lines and newline? best would be a org-table?

    > Instead of relying on MATLAB's default output, you can generate
    > formatted output using fprintf [1].
Ah, great, but it only works for vectors

x = [1, 2, 3, 4, 5]
fprintf('|%d', x)

For matrices it has to be sprintf

%% 
A=[1 2 3; 4 5 6; 7 8 9]
sprintf('|%d |%d |%d|\n',A')

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-11 13:23             ` John Kitchin
@ 2017-03-11 14:16               ` Uwe Brauer
  2017-03-11 14:22                 ` John Kitchin
  2017-10-20 11:03               ` Uwe Brauer
  1 sibling, 1 reply; 27+ messages in thread
From: Uwe Brauer @ 2017-03-11 14:16 UTC (permalink / raw)
  To: emacs-orgmode


   > You might dig around in ob-octave to see how it works. It should be able
   > to Matlab (and on Linux/Mac I believe it might). On Windows, it has been
   > broken for a long time due to the lack of a proper shell (maybe that can
   > be adapted in win10 though).

   > I vaguely recall making that matlab function to try it out on Windows
   > some years ago.

   > There is a Jupyter Matlab kernel now.
   > https://github.com/Calysto/matlab_kernel


Thanks for pinting it out to me. Couldn't  install it so far
ImportError: No module named pathlib
when trying directly to use >python -m matlab_kernel install

Or ould not find a version that satisfies the requirement backports.tempfile (from matlab-kernel) (from versions: 1.0rc1, 1.0rc1)
Cleaning up...
No distributions matching the version for backports.tempfile (from matlab-kernel)
Storing debug log for failure in /home/oub/.pip/pip.log

Have to write the author.

The output using your code and Eric's suggestion is ok but I am curious
to see what the kernel is supposed to do better.

Uwe 
   > I was able to use this (and installing the kernel, and making sure a
   > matlab is on the path):

   > #+BEGIN_SRC emacs-lisp
   > (add-to-list 'org-src-lang-modes '("matlab" . matlab))

   > ;; set default headers for convenience
   > (setq org-babel-default-header-args:matlab
   >       '((:results . "output replace")
   > 	(:session . "matlab")
   > 	(:kernel . "matlab")
   > 	(:exports . "code")
   > 	(:cache .   "no")
   > 	(:noweb . "no")
   > 	(:hlines . "no")
   > 	(:tangle . "no")))

   > (defalias 'org-babel-execute:matlab 'org-babel-execute:ipython)
   > (defalias 'org-babel-prep-session:matlab 'org-babel-prep-session:ipython)
   > (defalias 'org-babel-matlab-initiate-session 'org-babel-ipython-initiate-session)
   > #+END_SRC


   > #+RESULTS:
   > : org-babel-matlab-initiate-session

   > To enable this:

   > #+BEGIN_SRC matlab :results output org drawer
   > x = [1, 2, 3, 4, 5];
   > fprintf('|%d', x)
   > #+END_SRC

   > #+RESULTS:
   > :RESULTS:
   > | 1 | 2 | 3 | 4 | 5 |
   > :END:

   > It is not much better output wise without the fprintf, but that seems to
   > be a feature of Matlab's output. I think Eric is probably right, you
   > will have use fprintf to get what you want.

   > I am not a big matlab user these days, so I do not have a sense for how
   > usable the kernel is. It does run in a session, which is a big
   > improvement over the other one I wrote.

   > Uwe Brauer writes:

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-11 14:16               ` Uwe Brauer
@ 2017-03-11 14:22                 ` John Kitchin
  2017-03-11 14:54                   ` Uwe Brauer
  2017-03-11 16:50                   ` Uwe Brauer
  0 siblings, 2 replies; 27+ messages in thread
From: John Kitchin @ 2017-03-11 14:22 UTC (permalink / raw)
  To: emacs-orgmode

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

The kernel provides a "session" so matlab stays alive and doesn't have to
restart on every block.

The kernel might require python3.
On Sat, Mar 11, 2017 at 9:20 AM Uwe Brauer <oub@mat.ucm.es> wrote:

>
>    > You might dig around in ob-octave to see how it works. It should be
> able
>    > to Matlab (and on Linux/Mac I believe it might). On Windows, it has
> been
>    > broken for a long time due to the lack of a proper shell (maybe that
> can
>    > be adapted in win10 though).
>
>    > I vaguely recall making that matlab function to try it out on Windows
>    > some years ago.
>
>    > There is a Jupyter Matlab kernel now.
>    > https://github.com/Calysto/matlab_kernel
>
>
> Thanks for pinting it out to me. Couldn't  install it so far
> ImportError: No module named pathlib
> when trying directly to use >python -m matlab_kernel install
>
> Or ould not find a version that satisfies the requirement
> backports.tempfile (from matlab-kernel) (from versions: 1.0rc1, 1.0rc1)
> Cleaning up...
> No distributions matching the version for backports.tempfile (from
> matlab-kernel)
> Storing debug log for failure in /home/oub/.pip/pip.log
>
> Have to write the author.
>
> The output using your code and Eric's suggestion is ok but I am curious
> to see what the kernel is supposed to do better.
>
> Uwe
>    > I was able to use this (and installing the kernel, and making sure a
>    > matlab is on the path):
>
>    > #+BEGIN_SRC emacs-lisp
>    > (add-to-list 'org-src-lang-modes '("matlab" . matlab))
>
>    > ;; set default headers for convenience
>    > (setq org-babel-default-header-args:matlab
>    >       '((:results . "output replace")
>    >    (:session . "matlab")
>    >    (:kernel . "matlab")
>    >    (:exports . "code")
>    >    (:cache .   "no")
>    >    (:noweb . "no")
>    >    (:hlines . "no")
>    >    (:tangle . "no")))
>
>    > (defalias 'org-babel-execute:matlab 'org-babel-execute:ipython)
>    > (defalias 'org-babel-prep-session:matlab
> 'org-babel-prep-session:ipython)
>    > (defalias 'org-babel-matlab-initiate-session
> 'org-babel-ipython-initiate-session)
>    > #+END_SRC
>
>
>    > #+RESULTS:
>    > : org-babel-matlab-initiate-session
>
>    > To enable this:
>
>    > #+BEGIN_SRC matlab :results output org drawer
>    > x = [1, 2, 3, 4, 5];
>    > fprintf('|%d', x)
>    > #+END_SRC
>
>    > #+RESULTS:
>    > :RESULTS:
>    > | 1 | 2 | 3 | 4 | 5 |
>    > :END:
>
>    > It is not much better output wise without the fprintf, but that seems
> to
>    > be a feature of Matlab's output. I think Eric is probably right, you
>    > will have use fprintf to get what you want.
>
>    > I am not a big matlab user these days, so I do not have a sense for
> how
>    > usable the kernel is. It does run in a session, which is a big
>    > improvement over the other one I wrote.
>
>    > Uwe Brauer writes:
>
>
>
> --
John

-----------------------------------
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

[-- Attachment #2: Type: text/html, Size: 5733 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-11 14:22                 ` John Kitchin
@ 2017-03-11 14:54                   ` Uwe Brauer
  2017-03-11 16:50                   ` Uwe Brauer
  1 sibling, 0 replies; 27+ messages in thread
From: Uwe Brauer @ 2017-03-11 14:54 UTC (permalink / raw)
  To: emacs-orgmode


   > The kernel provides a "session" so matlab stays alive and doesn't have to
   > restart on every block.

Ah ok like the matlab shell as in emacs matlab mode.

It seems that I got it to work, there was a python lib conflict but the
author released just a new version solving the problem.
   > The kernel might require python3.

Seems ok in 2.7, but I am not sure that it is running, I just evaluated
the lisp code you sent me, I can't see any difference so maybe something
is not right.

Uwe 

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-11 14:22                 ` John Kitchin
  2017-03-11 14:54                   ` Uwe Brauer
@ 2017-03-11 16:50                   ` Uwe Brauer
  2017-03-11 16:53                     ` John Kitchin
  1 sibling, 1 reply; 27+ messages in thread
From: Uwe Brauer @ 2017-03-11 16:50 UTC (permalink / raw)
  To: emacs-orgmode

>>> "John" == John Kitchin <jkitchin@andrew.cmu.edu> writes:

   > The kernel provides a "session" so matlab stays alive and doesn't have to
   > restart on every block.

   > The kernel might require python3.

Although I think I installed the kernel, I am not sure about the code
you sent me, namely

(defalias 'org-babel-execute:matlab 'org-babel-execute:ipython)
(defalias 'org-babel-prep-session:matlab 'org-babel-prep-session:ipython)
(defalias 'org-babel-matlab-initiate-session 'org-babel-ipython-initiate-session)

These ipython functions where are they supposed to be defined?

BTW where do you  tell the kernel about the matlab executables?

Uwe 

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-11 16:50                   ` Uwe Brauer
@ 2017-03-11 16:53                     ` John Kitchin
  0 siblings, 0 replies; 27+ messages in thread
From: John Kitchin @ 2017-03-11 16:53 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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

You can put them into an elisp src block to try it out. They have to go in
an init file to be permanent. I just made a symlink to the matlab
executable on my path.

The ipython functions are defined in ob-ipython,
https://github.com/gregsexton/ob-ipython I think.

John

-----------------------------------
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


On Sat, Mar 11, 2017 at 11:50 AM, Uwe Brauer <oub@mat.ucm.es> wrote:

> >>> "John" == John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>    > The kernel provides a "session" so matlab stays alive and doesn't
> have to
>    > restart on every block.
>
>    > The kernel might require python3.
>
> Although I think I installed the kernel, I am not sure about the code
> you sent me, namely
>
> (defalias 'org-babel-execute:matlab 'org-babel-execute:ipython)
> (defalias 'org-babel-prep-session:matlab 'org-babel-prep-session:ipython)
> (defalias 'org-babel-matlab-initiate-session 'org-babel-ipython-initiate-
> session)
>
> These ipython functions where are they supposed to be defined?
>
> BTW where do you  tell the kernel about the matlab executables?
>
> Uwe
>
>
>

[-- Attachment #2: Type: text/html, Size: 2226 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-10 21:15           ` Uwe Brauer
  2017-03-10 21:56             ` John Kitchin
@ 2017-03-11 23:50             ` Scott Randby
  1 sibling, 0 replies; 27+ messages in thread
From: Scott Randby @ 2017-03-11 23:50 UTC (permalink / raw)
  To: emacs-orgmode

On 03/10/2017 04:15 PM, Uwe Brauer wrote:
> 
>    > On 03/10/2017 11:08 AM, Uwe Brauer wrote:
> 
>    > You need to change "#+BEGIN_LaTeX" to "#+begin_export latex" and
>    > "#+END_LaTeX" to "#+end_export" for Org 9.0 and above.
> 
> Thanks, very much, I never understand what is the benefit of those
> changes which break backward compatibility (or forward compatibility)

I agree that breaking backward compatibility is a problem, but I support
this change because font locking of LaTeX code (and others) now works
well. There is a function in the CHANGES document
(http://orgmode.org/Changes.html) called org-repair-export-blocks that
works really well. I added the function to my customizations file and
run it whenever I need to modify and export an older file.

Scott

> 
> 
> .
> 

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-03-11 13:23             ` John Kitchin
  2017-03-11 14:16               ` Uwe Brauer
@ 2017-10-20 11:03               ` Uwe Brauer
  2017-10-20 11:54                 ` Uwe Brauer
  1 sibling, 1 reply; 27+ messages in thread
From: Uwe Brauer @ 2017-10-20 11:03 UTC (permalink / raw)
  To: emacs-orgmode

>>> "John" == John Kitchin <jkitchin@andrew.cmu.edu> writes:

This message is from July, but meanwhile I upgraded to Ubuntu 16.04
matlab 2016b which includes the python engine/kernel and finally
I installed the Jupiter matlab kernel via pip, however I tried to follow
your recommendations below:




   > You might dig around in ob-octave to see how it works. It should be able
   > to Matlab (and on Linux/Mac I believe it might). On Windows, it has been
   > broken for a long time due to the lack of a proper shell (maybe that can
   > be adapted in win10 though).

   > I vaguely recall making that matlab function to try it out on Windows
   > some years ago.

   > There is a Jupyter Matlab kernel now.
   > https://github.com/Calyro/matlab_kernel
   > I was able to use this (and installing the kernel, and making sure a
   > matlab is on the path):

   > #+BEGIN_SRC emacs-lisp
   > (add-to-list 'org-src-lang-modes '("matlab" . matlab))

   > ;; set default headers for convenience
   > (setq org-babel-default-header-args:matlab
   >       '((:results . "output replace")
   > 	(:session . "matlab")
   > 	(:kernel . "matlab")
   > 	(:exports . "code")
   > 	(:cache .   "no")
   > 	(:noweb . "no")
   > 	(:hlines . "no")
   > 	(:tangle . "no")))

   > (defalias 'org-babel-execute:matlab 'org-babel-execute:ipython)
   > (defalias 'org-babel-prep-session:matlab 'org-babel-prep-session:ipython)
   > (defalias 'org-babel-matlab-initiate-session 'org-babel-ipython-initiate-session)
   > #+END_SRC


   > #+RESULTS:
   > : org-babel-matlab-initiate-session


That I obtain
   > To enable this:

   > #+BEGIN_SRC matlab :results output org drawer
   > x = [1, 2, 3, 4, 5];
   > fprintf('|%d', x)
   > #+END_SRC


Here I obtain the following error:

Debugger entered--Lisp error: (void-function org-babel-execute:matlab)
  org-babel-execute:matlab("x = [1, 2, 3, 4, 5];\nfprintf('|%d', x)"
  ((:colname-names) (:rowname-names) (:result-params "replace" "output"
  "drawer") (:result-type . output) (:results . "replace output drawer")
  (:exports . "code") (:session . "matlab") (:kernel . "matlab") (:cache
  . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no")))
  org-babel-execute-src-block(nil ("matlab" "x = [1, 2, 3, 4,
  5];\nfprintf('|%d', x)" ((:colname-names) (:rowname-names)
  (:result-params "drawer" "output" "replace") (:result-type . output)
  (:results . "drawer output replace") (:exports . "code") (:tangle .
  "no") (:hlines . "no") (:noweb . "no") (:cache . "no") (:kernel .
  "matlab") (:session . "matlab")) "" nil 671 "(ref:%s)"))
  org-ctrl-c-ctrl-c(nil) funcall-interactively(org-ctrl-c-ctrl-c nil)
  call-interactively(org-ctrl-c-ctrl-c nil nil)
  command-execute(org-ctrl-c-ctrl-c)



What is the problem? Which package do I miss, ipython is installed in /usr/local/bin

Thanks

Uwe Brauer 

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: workflow, matlab+latex in org file
  2017-10-20 11:03               ` Uwe Brauer
@ 2017-10-20 11:54                 ` Uwe Brauer
  0 siblings, 0 replies; 27+ messages in thread
From: Uwe Brauer @ 2017-10-20 11:54 UTC (permalink / raw)
  To: emacs-orgmode




   > Here I obtain the following error:

   > Debugger entered--Lisp error: (void-function org-babel-execute:matlab)
   >   org-babel-execute:matlab("x = [1, 2, 3, 4, 5];\nfprintf('|%d', x)"
   >   ((:colname-names) (:rowname-names) (:result-params "replace" "output"
   >   "drawer") (:result-type . output) (:results . "replace output drawer")
   >   (:exports . "code") (:session . "matlab") (:kernel . "matlab") (:cache
   >   . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no")))
   >   org-babel-execute-src-block(nil ("matlab" "x = [1, 2, 3, 4,
   >   5];\nfprintf('|%d', x)" ((:colname-names) (:rowname-names)
   >   (:result-params "drawer" "output" "replace") (:result-type . output)
   >   (:results . "drawer output replace") (:exports . "code") (:tangle .
   >   "no") (:hlines . "no") (:noweb . "no") (:cache . "no") (:kernel .
   >   "matlab") (:session . "matlab")) "" nil 671 "(ref:%s)"))
   >   org-ctrl-c-ctrl-c(nil) funcall-interactively(org-ctrl-c-ctrl-c nil)
   >   call-interactively(org-ctrl-c-ctrl-c nil nil)
   >   command-execute(org-ctrl-c-ctrl-c)


Ok, I did not had ob-ipython installed. Now I did but obtain a different
error

Debugger entered--Lisp error: (error "There was a fatal error trying to
  process the request. See *ob-ipython-debug*") signal(error ("There was
  a fatal error trying to process the request. See *ob-ipython-debug*"))
  error("There was a fatal error trying to process the request. See
  *ob-ipython-debug*") ob-ipython--dump-error("Traceback (most recent
  call last):\n File
  \"/home/oub/.emacs.d/elpa/ob-ipython-20171008.1733/client.py\", line
  60, in <module>\n c = create_client(args.conn_file)\n File
  \"/home/oub/.emacs.d/elpa/ob-ipython-20171008.1733/client.py\", line
  43, in create_client\n cf = find_connection_file('emacs-' + name)\n
  File
  \"/usr/local/lib/python2.7/dist-packages/jupyter_client/connect.py\",
  line 212, in find_connection_file\n raise IOError(\"Could not find %r
  in %r\" % (filename, path))\nIOError: Could not find 'emacs-matlab' in
  ['.', '/run/user/1000/jupyter']\n") ob-ipython--execute-request("x =
  [1, 2, 3, 4, 5];\nfprintf('|%d', x)" "matlab")
  ob-ipython--execute-sync("x = [1, 2, 3, 4, 5];\nfprintf('|%d', x)"
  ((:colname-names) (:rowname-names) (:result-params "replace" "output"
  "drawer") (:result-type . output) (:results . "replace output drawer")
  (:exports . "code") (:session . "matlab") (:kernel . "matlab") (:cache
  . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no")))
  org-babel-execute:matlab("x = [1, 2, 3, 4, 5];\nfprintf('|%d', x)"
  ((:colname-names) (:rowname-names) (:result-params "replace" "output"
  "drawer") (:result-type . output) (:results . "replace output drawer")
  (:exports . "code") (:session . "matlab") (:kernel . "matlab") (:cache
  . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no")))
  org-babel-execute-src-block(nil ("matlab" "x = [1, 2, 3, 4,
  5];\nfprintf('|%d', x)" ((:colname-names) (:rowname-names)
  (:result-params "drawer" "output" "replace") (:result-type . output)
  (:results . "drawer output replace") (:exports . "code") (:tangle .
  "no") (:hlines . "no") (:noweb . "no") (:cache . "no") (:kernel .
  "matlab") (:session . "matlab")) "" nil 671 "(ref:%s)"))
  org-ctrl-c-ctrl-c(nil) funcall-interactively(org-ctrl-c-ctrl-c nil)
  call-interactively(org-ctrl-c-ctrl-c nil nil)
  command-execute(org-ctrl-c-ctrl-c)

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2017-10-20 11:54 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <m2eg709w4s.fsf@gmail.com>
2016-07-11 13:55 ` workflow, matlab+latex in org file Uwe Brauer
     [not found] <c0b96d809e4b41529f81beaa685a9fd0@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2016-07-11 16:42 ` Eric S Fraga
2016-07-12 12:44   ` Uwe Brauer
2016-07-11 12:32 Uwe Brauer
2016-07-11 14:05 ` John Kitchin
2016-07-11 14:11   ` Uwe Brauer
2016-07-11 15:55     ` John Kitchin
2016-07-11 16:12       ` Uwe Brauer
2017-03-10 16:08       ` Uwe Brauer
2017-03-10 17:51         ` Scott Randby
2017-03-10 21:15           ` Uwe Brauer
2017-03-10 21:56             ` John Kitchin
2017-03-10 22:50               ` Uwe Brauer
2017-03-11 23:50             ` Scott Randby
     [not found]       ` <5e1e71e3698e415ca51a0b9e3cab5dac@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2017-03-10 18:03         ` Eric S Fraga
2017-03-10 21:18           ` Uwe Brauer
2017-03-11  8:04           ` Uwe Brauer
2017-03-11 13:23             ` John Kitchin
2017-03-11 14:16               ` Uwe Brauer
2017-03-11 14:22                 ` John Kitchin
2017-03-11 14:54                   ` Uwe Brauer
2017-03-11 16:50                   ` Uwe Brauer
2017-03-11 16:53                     ` John Kitchin
2017-10-20 11:03               ` Uwe Brauer
2017-10-20 11:54                 ` Uwe Brauer
     [not found]           ` <cf7ef1dfa1cf455bbaf63ab5fbdf18e5@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2017-03-11 10:37             ` Eric S Fraga
2017-03-11 14:12               ` Uwe Brauer

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.