Insert a MATLAB script on TexMacs

Well, dear @pireddag, I didn’t write the Matlab plug-in. I just wrote its user-manual profiting greatly from your technical expertise. I may have initiated a rewrite of the start-up script, which in the end however, was a collaborative effort of you, @jeroen, and me.

I guess getting the script working under Windows may well make some people happy.:wink:

Cheers
Tilda

I had forgotten all of the details :slight_smile:

Thank you for your kind answer @Tilda,

I have tried your suggestions but it seems like there is no MATLAB attribution or OCTAVE in the path :

Program -> Block of Code

You are surely aware that there is a LaTex package for MATLAB nammed “mcode” that allows to print scripts in a very similar way to MATLAB native editor.

I don’t know if it’s still possible on TexMacs ?

I hope that my question is not confusing,

Thanks a lot for your advices,

Best regards.

I believe @Tilda’s suggestion is to try \octave-code. Did you try this?

My bad ! Thank you for the remark @jeroen : now it somehow works as I want it to do.
I will read the help section in order to lauch a MATLAB session on my file. I would probably come back to this conversation if I encounter any potential problem !

Thank you again for your help :slight_smile:

No problem! It is confusing that not all supported languages are in the menu. I’ll have a look and see if I can find a fix.

@jeroen , I may have another question :
In order to launch the MATLAB session on TexMacs, I am following the steps documented in the help section.
I have created a softlink. Now, I have to install the Github zip document in the TeXmacs path. However, I don’t find any directory nammed “plugins” in this path. For instance, I have to install the folder in the path : $HOME/.TeXmacs/plugins/matlab
However : this directory doesn’t exist on my computer…

How is it possible ?

Thank you again for your help,

Best regards.

I don’t think this is necessary. The MATLAB plugin should be installed by default. Why do you want to install a version from git?

@jeroen Because, if I try to plot a simple function (for example : sin(x)) : I keep having this error message :

2022-04-25 14:47:40.572 MATLAB_maci64[24487:8874809] CoreText note: Client requested name “.SFNS-Regular”, it will get Times-Roman rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].
2022-04-25 14:47:40.572 MATLAB_maci64[24487:8874809] CoreText note: Set a breakpoint on CTFontLogSystemFontNameRequest to debug.
2022-04-25 14:47:40.581 MATLAB_maci64[24487:8874809] CoreText note: Client requested name “.SFNS-Bold”, it will get Times-Roman rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].
2022-04-25 14:47:40.588 MATLAB_maci64[24487:8874809] CoreText note: Client requested name “.SFNS-Regular”, it will get Times-Roman rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].
2022-04-25 14:47:40.589 MATLAB_maci64[24487:8874809] CoreText note: Client requested name “.SFNS-Bold”, it will get Times-Roman rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].

I don’t know why ?

By the way the color scheme of the octave code block is quite different from the default color scheme of the Matlab editor. Does anyone know how to change the colors?

@pireddag Yes, you are right but I don’t know if it’s possible since it’s still a block of OCTAVE code and not really a MATLAB one… I would be interested to know if it’s possible to match the native colors.

You can put something like the below in my-init-texmacs.scm to change the colours.

(define (notify-octave-syntax var val)
  (syntax-read-preferences "octave"))

(define-preferences
  ("syntax:octave:none" "red" notify-octave-syntax)
  ("syntax:octave:comment" "brown" notify-octave-syntax)
  ("syntax:octave:error" "dark red" notify-octave-syntax)
  ("syntax:octave:constant" "#4040c0" notify-octave-syntax)
  ("syntax:octave:constant_number" "#4040c0" notify-octave-syntax)
  ("syntax:octave:constant_string" "dark grey" notify-octave-syntax)
  ("syntax:octave:constant_char" "#333333" notify-octave-syntax)
  ("syntax:octave:declare_function" "#0000c0" notify-octave-syntax)
  ("syntax:octave:declare_module" "0000c0" notify-octave-syntax)
  ("syntax:octave:declare_type" "000000" notify-octave-syntax)
  ("syntax:octave:operator" "#8b008b" notify-octave-syntax)
  ("syntax:octave:operator_openclose" "#B02020" notify-octave-syntax)
  ("syntax:octave:operator_field" "#88888" notify-octave-syntax)
  ("syntax:octave:operator_special" "orange" notify-octave-syntax)
  ("syntax:octave:keyword" "#309090" notify-octave-syntax)
  ("syntax:octave:keyword_conditional" "#309090" notify-octave-syntax)
  ("syntax:octave:keyword_control" "#309090" notify-octave-syntax))
4 Likes

@jeroen : I have an issue with the localisation of these files. For instance, the directory

$TEXMACS_PATH/progs

is not found on my computer and I don’t know why. Is it related to the fact that I am running a M1 Mac so I have installed the .dmg related to the arm distribution provided on the website ? I don’t know because it’s strange : I am able to run TexMacs as an application but not finding the directory needed to write your suggestions…

Thank you in advance for your help and sorry for disturbing you,

Best regards,

I think I can help with that: please see the section How to edit the TeXmacs user initialization files in [wiki] Assorted code snippets to customize TeXmacs' behaviour

If you also want to know where the file is, please try “Save as” once you have opened the file, and the file selection dialog should open in the directory where the file is located. Then, once that you have seen which directory the file is contained in, you can close the dialog without saving.

1 Like

Customization should go in $TEXMACS_HOME_PATH and not $TEXMACS_PATH. The first usually resolves to ~/.TeXmacs while the second, on Mac, is equivalent usually to /Applications/TeXmacs.app/Contents/Resources/share/TeXmacs. Maybe your .app package is however elsewhere.

1 Like

@pireddag Appreciated ! It worked for me : I have localised the position of the required file. Thank you.

@jeroen @Tilda Please, have you ever experienced this issue while trying to plot something using the MATLAB session ? I am currently trying to launch a proper session but I keep having this issue :

Also, if I close the associated session then the figure pop in and then is closed immediately… So, I am unable to have access to this plot.

Thank you in advance for your help.

It seems that Matlab, for some reason try to open a window to do the plot instead of sending it (in some form) to TeXmacs. I do not know about this plugin, but looking at it you should be able to understand why it is so. Usually the plugin is written in matlab itself.

You can try to run from a shell:

matlab -nodesktop -nosplash

and then check what happens if you run your code there. -nodesktop should prevent matlab to open the GUI, but I’m not sure what is supposed to do when you try to make a plot.

No, dear @Wiss, I don’t experience these error messages, when running a Matlab session from with in TeXmacs. I have Matlab R2020a Update 6 and the start-up script tm_matlab that ships with TeXmacs 2.1.1 works fine.

Maybe you want to make sure that no previous instance of the Matlab.app is running, i.e. close the GUI app before you launch a Matlab session from within TeXmacs. Give this a try.

Your problem could also be a font issue. If you have TeX installed on your system, you might try to configure Matlab to use TeX fonts. This can be done in startup.m. (Matlab specific)

Cheers
Tilda