Writing a .m (Live) that can be opened as a Live Script
I've been confused trying to write (or have an AI write) the .m (Live) text format from scratch for various reasons using .mlx format exported with the IDE as .m (old) and .m (LIve). Of course, one problem is the .m and .m (Live) files have the same name,causing confusion and requiring renaming, but repeatedly, after sussing out and following all conventions for headings and latex etc in .m (LIve), my .m (Live) files would not open as .mlx in the IDE. I think I've found the answer by trial and error and comparison and don't know it is documented. Add at the end
%[appendix]{"version":"1.0"} %--- %[metadata:view] % data: {"layout":"inline"} %---
This seems to trigger the IDE to recognize this is a .m (Live). Woohoo! This is a LOT easier than writing .mlx zip packages from scratch.
5 Comments
Time DescendingMichelle's suggestion is great if you are using a coding agent. If you are working by hand, the minimal script that I have written that will be recognized as a live script .m file is two blank lines, then the appendix declaration, then a single blank line:
%[appendix]{"version":"1.0"}
%%---
Part of the issue is that MathWorks, unfortunately, did not completely document the plain-text Live Script format. See "Live Code File Format (.m)." There is enough information there to help someone understand roughly what is going on when reading such a file, but there is not enough information to help someone who wants to automate the creation or processing of such a file.
The fact that MathWorks included the matlab-create-live-script skill in the MATLAB Agentic Toolkit suggests to me that someone there understood the programmatic use cases and that the documentation was insufficient to support them. I think there is information in the skill that should have been included in the doc.
What I noticed earlier, when the plain-text Live Script format was released, is that the documentation does not explain the data encoding for various items that appear in the appendix. The agentic toolbox skill does not have this information either.
My use case, generally speaking, is to analyze and then convert an existing Live Script into some other form that would be suitable for inclusion in a different kind of published document, such as a blog post on a particular blogging platform, or a book created using LaTeX.
@Duncan Carlsmith, I'd be interested to know more about your use cases for creating Live Scripts from scratch and independently from the MATLAB Editor, if you are able to share them.
There's a resource in the MATLAB MCP Core Server for writing Live Scripts, and a skill in the MATLAB Agentic Toolkit that adds a bit of style on top of it. Have you tried using these?
Sign in to participate