Insert a MATLAB script on TexMacs

Hello everyone,

I know that this question has already been answered in a similar post but please consider that I have not fully understood the explanation given.

What I am trying to do is to simply insert a MATLAB script in a TexMacs document (like the mcode package for other LaTex distributions) : I am using a Mac running on macOs Monterrey (12.2.1) and I have installed the latest distribution of TexMacs.

I am not very familiar with the shell command (student level) and the explanations given on the Github provided in the associated post of the MATLAB plugin are unclear for me.

Could someone help me to do these manipulations carefully since I don’t want to miss something that would affect the TexMacs editor on my laptop.

Thank you in advance for your help and comprehension.

Wellcome to the forum, Wiss.

If you just want to insert programming code in your *.tm-file – code editing can be enabled by Insert→Program→Block of Code. There are more highlighters than listed in the Block of Code-menu. They just don’t seem to be very well accessible from the menus. You can insert \octave-code followed by the Enter key. There are some suggestions by @jeroen and @pireddag given here JavaScript and TypeScript syntax highlighting

If you want to execute Matlab code from within TeXmacs you need to launch the plugin (Insert–>Session–>Matlab). You can type in Matlab code from the keyboard and also read in entire *.m-files.
Maybe you want to consult the plug-in manual (Help–>Plug-ins–>Matlab). Feel free to ask any question if the explanations therein are not entirely clear to you.

Cheers
Tilda

3 Likes

Here I had said I would extend the plugin (written by @Tilda) to make it work under Windows as well, but I never did it. Let me update everyone when I have done it :slight_smile:

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.