From: Uwe B. <ou...@ma...> - 2024-04-23 13:34:09
Attachments:
smime.p7s
|
>>> "m" == martinoidar <mar...@gm...> writes: Hi I decided to start a new thread, since I made some progress and it seems there are at least two ways to execute matlab from an org buffer and insert the result back into that buffer. 1. Using the python engine matlab ships (I am not describing the setup now) Disadvantage a. Not all matlab releases support all ptyhon versions. For example ptyhon 3.5 is only supported till 2019a b. It takes some time for the python engine to start Advantage a. The format of the result is very nice. 2. Using the matlab-shell itself (thanks @Martin for pointing this out) Test Configuration: a. Start emacs -Q b. Load the following file --8<---------------cut here---------------start------------->8--- (setq load-path (cons (expand-file-name "~/emacs/site-lisp/packages/src/Matlab/HG-Git/matlab-sf-hg") load-path)) (load-file "/home/oub/emacs/init/custom-init-faces.el") (require 'company-matlab-shell) (require 'org) (require 'gdb-mi) (autoload 'matlab-mode "matlab" "Enter Matlab mode." t) (setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist)) (autoload 'matlab-shell "matlab" "Interactive Matlab mode." t) (org-babel-do-load-languages 'org-babel-load-languages '( (C . t) ; enable processing C, C++, and D source blocks (matlab . t) ;;(perl . t) (octave . t) (org . t) (python . t) (plantuml . t) (shell . t) )) (setq org-babel-default-header-args:matlab '((:results . "output") (:session . "*MATLAB*"))) --8<---------------cut here---------------end--------------->8--- And load ob-octave-fix.el https://github.com/karthink/.emacs.d/blob/master/plugins/ob-octave-fix.el Then the following code can be executed in a org buffer #+begin_src matlab :results output latex :exports results :eval never-export :wrap latex clear all x = [1, 2, 3, 4, 5]; disp(sprintf('|%d', x)) #+end_src #+RESULTS: #+begin_latex x = [1, 2, 3, 4, 5]; disp(sprintf('|%d', x)) |1|2|3|4|5 #+end_latex #+begin_src matlab :results output latex :exports results :eval never-export :wrap latex clear all x = [1, 2, 3, 4, 5]; disp(sprintf('|%d', x)) #+end_src #+RESULTS: #+begin_latex |1|2|3|4|5 #+end_latex That already indicates that the formatting needs care, moreover =fprintf= is not supported #+begin_src matlab :results output latex :exports results :eval never-export :wrap latex clear all x = [1, 2, 3, 4, 5] ; fprintf('|%d', x) #+end_src #+RESULTS: #+begin_latex #+end_latex So I need to investigate this a bit more. In summary: the second solution works surprisingly well and is faster than the python solution, but the formatting seems to me more restricted as in the python case. Any comments? Has anybody tried this out? @John you talked about such feature in the past. Can you confirm this behavior? Regards Uwe |
From: martinoidar <mar...@gm...> - 2024-04-25 19:56:05
|
On 23.04.2024 15:33, Uwe Brauer wrote: >>>> "m" == martinoidar <mar...@gm...> writes: > Hi > > I decided to start a new thread, since I made some progress and it seems > there are at least two ways to execute matlab from an org buffer and > insert the result back into that buffer. > > 1. Using the python engine matlab ships (I am not describing the > setup now) > Disadvantage > a. Not all matlab releases support all ptyhon versions. For > example ptyhon 3.5 is only supported till 2019a > > b. It takes some time for the python engine to start > > Advantage > > a. The format of the result is very nice. > > 2. Using the matlab-shell itself (thanks @Martin for pointing this > out) > Test Configuration: > > a. Start emacs -Q > > b. Load the following file > > --8<---------------cut here---------------start------------->8--- > (setq load-path (cons (expand-file-name "~/emacs/site-lisp/packages/src/Matlab/HG-Git/matlab-sf-hg") load-path)) > (load-file "/home/oub/emacs/init/custom-init-faces.el") > (require 'company-matlab-shell) > (require 'org) > (require 'gdb-mi) > (autoload 'matlab-mode "matlab" "Enter Matlab mode." t) > (setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist)) > (autoload 'matlab-shell "matlab" "Interactive Matlab mode." t) > (org-babel-do-load-languages > 'org-babel-load-languages '( > (C . t) ; enable processing C, C++, and D source blocks > (matlab . t) > ;;(perl . t) > (octave . t) > (org . t) > (python . t) > (plantuml . t) > (shell . t) > )) > > (setq org-babel-default-header-args:matlab > '((:results . "output") (:session . "*MATLAB*"))) > > --8<---------------cut here---------------end--------------->8--- > > And load ob-octave-fix.el > https://github.com/karthink/.emacs.d/blob/master/plugins/ob-octave-fix.el > > Then the following code can be executed in a org buffer > > #+begin_src matlab :results output latex :exports results :eval never-export :wrap latex > clear all > x = [1, 2, 3, 4, 5]; > disp(sprintf('|%d', x)) > #+end_src > > #+RESULTS: > #+begin_latex > x = [1, 2, 3, 4, 5]; > disp(sprintf('|%d', x)) > |1|2|3|4|5 > #+end_latex > > > #+begin_src matlab :results output latex :exports results :eval never-export :wrap latex > clear all > x = [1, 2, 3, 4, 5]; > disp(sprintf('|%d', x)) > #+end_src > > #+RESULTS: > #+begin_latex > |1|2|3|4|5 > #+end_latex > > That already indicates that the formatting needs care, moreover > =fprintf= is not supported > #+begin_src matlab :results output latex :exports results :eval never-export :wrap latex > clear all > x = [1, 2, 3, 4, 5] ; > fprintf('|%d', x) > #+end_src > > #+RESULTS: > #+begin_latex > #+end_latex > > So I need to investigate this a bit more. > > In summary: the second solution works surprisingly well and is faster > than the python solution, but the formatting seems to me more restricted > as in the python case. > > Any comments? > > Has anybody tried this out? > > @John you talked about such feature in the past. > > Can you confirm this behavior? > > Regards > > Uwe Hi Uwe, My comments on the topic have grown to such a size that I decided it's better to make a post from them. Please have a look here: https://cissic.github.io/posts/latex-output-from-matlab-octave-source-blocks/ Regards, M |
From: martinoidar <mar...@gm...> - 2024-04-25 20:07:35
|
On 25.04.2024 21:55, martinoidar wrote: > > On 23.04.2024 15:33, Uwe Brauer wrote: >>>>> "m" == martinoidar <mar...@gm...> writes: >> Hi >> >> I decided to start a new thread, since I made some progress and it seems >> there are at least two ways to execute matlab from an org buffer and >> insert the result back into that buffer. >> >> 1. Using the python engine matlab ships (I am not describing the >> setup now) >> Disadvantage >> a. Not all matlab releases support all ptyhon versions. For >> example ptyhon 3.5 is only supported till 2019a >> >> b. It takes some time for the python engine to start >> >> Advantage >> >> a. The format of the result is very nice. >> >> 2. Using the matlab-shell itself (thanks @Martin for pointing this >> out) >> Test Configuration: >> >> a. Start emacs -Q >> >> b. Load the following file >> >> --8<---------------cut here---------------start------------->8--- >> (setq load-path (cons (expand-file-name >> "~/emacs/site-lisp/packages/src/Matlab/HG-Git/matlab-sf-hg") load-path)) >> (load-file "/home/oub/emacs/init/custom-init-faces.el") >> (require 'company-matlab-shell) >> (require 'org) >> (require 'gdb-mi) >> (autoload 'matlab-mode "matlab" "Enter Matlab mode." t) >> (setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist)) >> (autoload 'matlab-shell "matlab" "Interactive Matlab mode." t) >> (org-babel-do-load-languages >> 'org-babel-load-languages '( >> (C . t) ; enable processing C, C++, and >> D source blocks >> (matlab . t) >> ;;(perl . t) >> (octave . t) >> (org . t) >> (python . t) >> (plantuml . t) >> (shell . t) >> )) >> >> (setq org-babel-default-header-args:matlab >> '((:results . "output") (:session . "*MATLAB*"))) >> >> --8<---------------cut here---------------end--------------->8--- >> >> And load ob-octave-fix.el >> https://github.com/karthink/.emacs.d/blob/master/plugins/ob-octave-fix.el >> >> Then the following code can be executed in a org buffer >> >> #+begin_src matlab :results output latex :exports results :eval >> never-export :wrap latex >> clear all >> x = [1, 2, 3, 4, 5]; >> disp(sprintf('|%d', x)) >> #+end_src >> >> #+RESULTS: >> #+begin_latex >> x = [1, 2, 3, 4, 5]; >> disp(sprintf('|%d', x)) >> |1|2|3|4|5 >> #+end_latex >> >> >> #+begin_src matlab :results output latex :exports results :eval >> never-export :wrap latex >> clear all >> x = [1, 2, 3, 4, 5]; >> disp(sprintf('|%d', x)) >> #+end_src >> >> #+RESULTS: >> #+begin_latex >> |1|2|3|4|5 >> #+end_latex >> >> That already indicates that the formatting needs care, moreover >> =fprintf= is not supported >> #+begin_src matlab :results output latex :exports results :eval >> never-export :wrap latex >> clear all >> x = [1, 2, 3, 4, 5] ; >> fprintf('|%d', x) >> #+end_src >> >> #+RESULTS: >> #+begin_latex >> #+end_latex >> >> So I need to investigate this a bit more. >> >> In summary: the second solution works surprisingly well and is faster >> than the python solution, but the formatting seems to me more restricted >> as in the python case. >> >> Any comments? >> >> Has anybody tried this out? >> >> @John you talked about such feature in the past. >> >> Can you confirm this behavior? >> >> Regards >> >> Uwe > > > Hi Uwe, > > My comments on the topic have grown to such a size that I decided it's > better to make a post from them. > > Please have a look here: > > https://cissic.github.io/posts/latex-output-from-matlab-octave-source-blocks/ > > > Regards, > > M > Update: I've just noticed that not everything is properly rendered in markdown form. Here's a pdf version of the document: https://github.com/cissic/temp-aux-repo/blob/main/2024-04-25-latex-output-from-matlab-octave-source-blocks.pdf |
From: Uwe B. <ou...@ma...> - 2024-04-27 07:16:22
Attachments:
smime.p7s
|
> On 25.04.2024 21:55, martinoidar wrote: > Update: > I've just noticed that not everything is properly rendered in markdown > form. Thanks, but I still do not understand why *fprintf* is not supported and why the indenting should be important. When I have a bit more time, I will ask John explicitly 😇 since he seems to know quite a bit about that issue but who is also very occupied. Uwe > Here's a pdf version of the document: > https://github.com/cissic/temp-aux-repo/blob/main/2024-04-25-latex-output-from-matlab-octave-source-blocks.pdf -- I strongly condemn Hamas heinous despicable pogroms/atrocities on Israel I strongly condemn Putin's war of aggression against Ukraine. I support to deliver weapons to Ukraine's military. I support the EU and NATO membership of Ukraine. |
From: Uwe B. <ou...@ma...> - 2024-11-22 15:59:52
Attachments:
smime.p7s
|
> On 25.04.2024 21:55, martinoidar wrote: Hi > Update: > I've just noticed that not everything is properly rendered in markdown > form. I just want to point out that we merged successfully our org-mode branch into the main, the default branch, and now the native org supports works flawlessly and does not require the python engine anymore. You can access the newest version either via MELPA or directly from https://github.com/mathworks/Emacs-MATLAB-Mode.git Uwe Brauer -- I strongly condemn Hamas heinous despicable pogroms/atrocities on Israel I strongly condemn Putin's war of aggression against Ukraine. I support to deliver weapons to Ukraine's military. I support the EU and NATO membership of Ukraine. |