Matlab Create Live Script
MathWorksOfficialCreated by MathWorks
- Skill
- Content generator
- Science and research
- BSD-2-Clause
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides the syntax and guidelines for authoring MATLAB live scripts using plain-text .m files. By using specific formatting directives, users can create documents that include rich text, LaTeX equations, and inline figures while maintaining compatibility with version control systems. It includes instructions for converting binary .mlx files to plain-text format and provides a structured approach for embedding outputs and validating scripts within a MATLAB environment.
What it does
- Defines syntax for rich text, section headers, and LaTeX equations in .m files
- Provides a method to convert binary .mlx files into version-control-friendly .m files
- Includes a required appendix structure for metadata and embedded outputs
- Offers guidelines for layout, including tiled plots and list formatting
- Provides a utility to execute scripts and embed outputs directly into the file
- Outlines a workflow for planning, writing, validating, and rendering live scripts
When to use it
- When creating tutorials, analysis notebooks, or technical reports in MATLAB
- When you need to maintain MATLAB documentation under version control
- When converting existing binary .mlx files to a text-based format
- When you require inline figures and LaTeX equations within your code documentation
Advantages
- Enables version control for MATLAB live scripts by using plain-text files
- Supports rich formatting and mathematical notation within code files
- Provides a clear, structured syntax for consistent document rendering
- Allows for the embedding of execution outputs directly into the script
Usage examples
- “Create a MATLAB live script that explains the Pythagorean theorem with a centered equation.”
- Generates a .m file using the %[text] directive and the required centered equation syntax, ending with the mandatory appendix.
- “Convert my existing binary analysis.mlx file to a plain-text format.”
- Provides the MATLAB command sequence to open the file and save it as a .m file, ensuring it follows the required plain-text structure.
Install
1 of its files are not mirrored here, so install it from its source:
https://github.com/matlab/matlab-agentic-toolkit/tree/2a7f215e965597acf6ed495beb9e7b8aff45a3be/skills-catalog/matlab-core/matlab-create-live-script
Documentation by MathWorks
Live Scripts
Plain-text .m files that render as rich documents in the MATLAB Live Editor. Version-control friendly — never use binary .mlx.
When to Use
Tutorials, reports, analysis notebooks, or documentation
Interactive exploration with inline figures and equations
Version-controlled content (plain-text
.m, not binary.mlx)Converting an existing binary
.mlxfile to plain-text.m
When NOT to Use
Regular scripts without rich formatting
Function files
MATLAB older than R2025a
Converting from .mlx
To convert a binary .mlx file to a plain-text .m live script, run the following at the MATLAB Command Window. The recipe is not part of the resulting .m file:
editor = matlab.desktop.editor.openDocument(mlxPath, Visible=0);
editor.saveAs(newMPath); % use .m extension
editor.closeNoPrompt;Rules
Text lines use
%[text]— NOT bare%One paragraph = one
%[text]line — do not hard-wrap; let the Live Editor handle line widthNo empty
%[text]lines — they render as unwanted blank spaceSection headers:
%%on its own line, then%[text] ## Titleon next lineNo blank lines in the file, except a single blank line directly before
%[appendix]No
figurecommand — implicit figure creation onlyNo more than one plot per section (unless using tiled layouts)
No
close allorclearNo
mfilename— does not work as intended in live scripts. Hardcode filenames or usepwd.Escape these characters when used as literal text (not as markdown syntax):
*,_,[,],`,\. Also escape.after a digit and#at line start.Equations use single-
$inline form only:$ a = \\pi r^2 $(no$$ ... $$). For a centered/display equation, wrap the line:%[text]{"align":"center"} $ X(k) = \\sum\_{n=0}^{N-1} x(n) e^{-j2\\pi kn/N} $Inside an equation, LaTeX commands take double backslashes (
\\sin,\\frac,\\pi) and markdown characters take single (\_,\*). Use a tool that takes literal text (Edit, Write, fwrite) — don't use Bash heredocs; they collapse\\to\even when quoted, which corrupts LaTeX equations.Last list item (bulleted or numbered) ends with
\Every file ends with the required appendix
Avoid
fprintf— drop the semicolon or usedisp(). Output appears inline below the code that produced it, not in the Command Window.Outputs should serve the reader's understanding, not verify execution
Required Appendix
Every live script must end with:
%[appendix]{"version":"1.0"}
%---
%[metadata:view]
% data: {"layout":"inline"}
%---Reading live scripts (Token Optimization)
When reading a live script file, ignore everything below the %[appendix] marker. The appendix contains embedded images and metadata that consume tokens without adding useful information. All code and text content appears before it.
Format Reference
| Syntax | Renders as |
|---|---|
%% | Section break |
%[text] # Title | H1 heading |
%[text] ## Section | H2 heading |
%[text] **bold** | Bold |
%[text] *italic* | Italic |
%[text] `code` | Monospace |
%[text] <u>text</u> | Underlined text |
%[text] $ a = \\pi r^2 $ | Inline equation |
%[text]{"align":"center"} $ ... $ | Centered/display equation |
%[text] - item | Bullet |
%[text] - last \ | Last bullet |
%[text] 1. item | Numbered list |
%[text] 2. last \ | Last numbered item |
%[text] [text](url) | External hyperlink |
%[text] [text](internal:id) | Internal link to an anchor |
%[text] %[text:anchor:id] ... | Anchor (link target) |
%[text:tableOfContents]{"heading":"..."} | Table of Contents |
IDs (anchors, and any other id-bearing element): letters, digits, and underscores only. No hyphens — my-section won't bind; use my_section. For anchors, place the marker immediately after %[text] at the start of the line.
Tables
%[text:table]
%[text] | Method | Result |
%[text] | --- | --- |
%[text] | Trapezoidal | 1.9998 |
%[text:table]Example
%[text] # Sinusoidal Signals
%[text] Examples of sinusoidal signals in MATLAB.
%[text:tableOfContents]{"heading":"Contents"}
%[text] - sine waves
%[text] - cosine waves \
x = linspace(0,8*pi);
%%
%[text] ## Sine Wave
plot(x,sin(x))
title('Sine Wave')
xlabel('x (radians)')
ylabel('sin(x)')
grid on
%%
%[text] ## Cosine Wave
plot(x,cos(x))
title('Cosine Wave')
xlabel('x (radians)')
ylabel('cos(x)')
grid on
%%
%[text] ## Summary
%[text] The sine and cosine functions are $ \\pi/2 $ radians out of phase.
%[appendix]{"version":"1.0"}
%---
%[metadata:view]
% data: {"layout":"inline"}
%---Common Patterns
Mathematical Explanations with Equations
%[text] ## Theory
%[text] The discrete Fourier transform is defined as:
%[text]{"align":"center"} $ X(k) = \\sum\_{n=0}^{N-1} x(n) e^{-j2\\pi kn/N} $
%[text] where $ x(n) $ are the time-domain samples and $ k $ indexes the frequency bins.Code with Inline Comments
%%
%[text] ## Data Processing
%[text] Load and filter the data, then visualize the results.
data = load('measurements.mat');
filtered = lowpass(data, 0.5); % Apply lowpass filter
plot(filtered)
title('Filtered Data')Tiled Layouts for Comparison
Use only when side-by-side comparison is important to the illustration:
%%
%[text] ## Comparison of Methods
tiledlayout(1,2)
nexttile
plot(method1)
title('Method 1')
nexttile
plot(method2)
title('Method 2')Workflow
Plan — Title, setup, analysis sections, summary
Write —
%[text]for text,%%for sections, appendix at end. Use a tool that takes literal text (Edit, Write, fwrite). Don't use Bash heredocs (cat > file <<EOF); they collapse\\to\even when quoted, which corrupts LaTeX equations.Validate (if MATLAB attached) — Run the code through
evaluate_matlab_codeto confirm it executes cleanly. Note the wall-clock time — Embed Outputs takes about the same.Embed Outputs (optional, if MATLAB attached) — Run
executeLiveScript("<absolute-path>.m")to save each section's outputs (plots, displayed values) inline next to the code that produced them.Verify Rendering (optional, if MATLAB attached) — Run
export("<absolute-path>.m", "<absolute-path>.html")to produce an HTML approximation of the rendered document. Read it back to confirm equations are typeset, figures appear inline,%[text]directives don't leak as literal text, etc. Delete the.htmlwhen done — it's a verification artifact, not a deliverable.
The Write step is the load-bearing one — Write alone produces a valid live script the user can open and run. Validate, Embed Outputs, and Verify Rendering are progressive enhancements that require an attached MATLAB session. Without one, stop after Write. After Embed Outputs, the file is rewritten to disk by MATLAB — re-read before any further edits.
executeLiveScript
Bundled in the scripts/ folder of this skill. Add to path before first use:
addpath(fullfile(skillRoot, "scripts")); % skillRoot = directory containing this SKILL.mdCalling executeLiveScript(filePath) returns nothing on success. Runtime errors inside the script do not raise exceptions — the script writes them into the appendix as "dataType":"error" blocks; grep the saved .m to find them.
Run Validate before Embed Outputs. If a cell errors during Embed Outputs, that cell becomes an error block and outputs in cells after it are stripped from the file. Run through evaluate_matlab_code first.
If Embed Outputs errors with "Nested Live Editor execution" or hangs past the Validate time: retry once with the MATLAB desktop visible. If that also fails, the on-disk file from Write is still valid — skip Embed Outputs and let the user run the script themselves.
Checklist
Before finishing a live script, verify:
[ ] File has .m extension
[ ] Sections use
%%alone on its own line, followed by%[text] ##[ ] No blank lines or empty
%[text]lines (except one blank line directly before%[appendix])[ ] Each paragraph is a single
%[text]line (no hard-wrapping)[ ] One plot per section (unless tiled layout)
[ ] Bulleted and numbered lists end with backslash on last item
[ ] LaTeX command backslashes are doubled in the saved file:
\\sin,\\frac,\\pi[ ] No
figurecommands[ ] No
close allorclearat start[ ] No
mfilename[ ] Appendix is present and correctly formatted
[ ] Outputs serve the reader, not the developer
Not Yet Supported
Minor features planned for a future revision:
Interactive controls (sliders, dropdowns, numeric inputs)
Hide Code View (output view that hides the source code)
Copyright 2026 The MathWorks, Inc.
Files
- ATTRIBUTION.mdAdded by AutoGineer1.0 KiB
- LICENSELicence file added by AutoGineer1.4 KiB
- SKILL.md9.3 KiB
- manifest.yaml509 B
- scripts/executeLiveScript.p(opens on GitHub)Not mirrored: opens on GitHub155 B
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- MathWorks
- Publisher
- MathWorks (Official)
- Source
- matlab/matlab-agentic-toolkit · skills-catalog/matlab-core/matlab-create-live-script · commit 2a7f215
- Licence
- BSD 2-Clause License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE.md)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by MathWorks or MathWorks.
Get it from the source
1 of this skill’s files are not mirrored here, so there is no ZIP. Get the complete skill from its source: matlab/matlab-agentic-toolkit