On 21.04.2024 19:40, Uwe Brauer wrote:
Well, I also prefer gitlab, especially after recent controversies with
co-pilot
(https://www.infoworld.com/article/3627319/github-copilot-is-unacceptable-and-unjust-says-free-software-foundation.html),
though I'm not fervent about it...
Yes, I do use org-babel and matlab. Until now, it hasn't been flawless
experience but I manage to get the results back.
But to be honest, I have no idea what mysterious mechanism enables me
that. It's not been long since I've been using emacs, so there's still
many lines in my init.el copied from here and there in a hope they
will do...
According to my notes I followed the instructions from here:
https://gewhere.github.io/blog/2017/12/19/setup-matlab-in-emacs-and-babel-orgmode/
but nowwhen I inspect my init.el I can find only the code from the
last section of above-mentioned page ("Setup MATLAB with babel
orgmode").
Besides installing matlab-mode I have also manually downloaded:
https://github.com/karthink/.emacs.d/blob/master/plugins/ob-octave-fix.el
and included in init.el following the discussion found here:
- https://www.reddit.com/r/emacs/comments/pufgce/matlab_mode/
-
https://www.reddit.com/r/emacs/comments/fy98bs/orgbabels_matlab_session_output_is_malformed/
... and that's all... org-babel and matlab somehow work together and I
try not to complain much... ;)
Thanks I will study this later. What I am most interested is
1. Execute matlab code in a org buffer (with the correct block around the
matlab code.
2. Insert the result directly in the org buffer.
Here in exchange is my method.
1. The python engine shipped by mathworks (warning different matlab
releases require different python versions, that is why I am
stuck at the moment with R2019A, which still support python 3.5.
2. ob-ipython
Actually the following steps
** Python3 and matlab-kernel: HOWTO
sudo apt-get install python3-setuptools
sudo -H python3 -m pip install jupyter
sudo apt-get remove python3-pexpect
sudo -H python3 -m pip install pexpect
sudo -H python3 -m pip install matlab_kernel
** Install the python API for matlab.
MATLABROOT=/usr/local/MATLAB/R2019a
Cd $MATLABROOT/extern/engines/python
sudo -H python3 setup.py install
** Start the engine
Run
/usr/bin/python3
in the python prompt:
import matlab.engine
eng = matlab.engine.start_matlab()
the eng command needs some time to run.
When finished run now
eng.quit()
#+BEGIN_SRC emacs-lisp
(setq org-confirm-babel-evaluate nil) ;don't prompt me to confirm everytime I
want to evaluate a block
;;; display/update images in the buffer after I evaluate
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images 'append)
(add-to-list 'org-src-lang-modes '("matlab" . matlab))
(setq python-shell-interpreter "python3")
;; 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
Then use the following example
#+begin_src matlab :results output latex :exports results :eval never-export
:wrap latex
x = [1, 2, 3, 4, 5];
fprintf('|%d', x)
#+end_src
#+RESULTS:
#+begin_latex
|1|2|3|4|5
#+end_latex
Uwe
Your approach is indeed cumbersome.
In mine we need to:
1. Install `matlab-support` - a debian package that enables matlab
integration within the system:
sudo apt install matlab-support
2. In Emacs: install `matlab-mode` package
3. Download
https://github.com/karthink/.emacs.d/blob/master/plugins/ob-octave-fix.el
and put it somewhere in Emacs search path.
4. My init.el content with matlab/org-babel configurations:
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; enabling org-babel
(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)
))
;; setup matlab in babel
(setq org-babel-default-header-args:matlab
'((:results . "output") (:session . "*MATLAB*")))
;; octave/matlab-fix
;;;; (require 'ob-octave-fix nil t) ; This is for older approach
(require 'ob-octave-fix)
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
I do remember that this 'ob-octave-fix' is very important. Otherwise
there are some problems...
This works with Emacs 29.1 and currently Matlab 2023b.
The code you provided returned nothing in my case and in order to obtain
the same result I needed to tailor it a bit (Should there really be a
call to 'fprintf'?):
#+begin_src matlab :results output latex :exports results :eval
never-export :wrap latex
x = [1, 2, 3, 4, 5] ;
disp(sprintf('|%d', x))
#+end_src
#+RESULTS:
#+begin_latex
|1|2|3|4|5
#+end_latex
_______________________________________________
Matlab-emacs-discuss mailing list
Matlab-emacs-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss