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 |