$npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-create-live-scriptCreate, edit, and run plain-text MATLAB live scripts (.m files) with rich text formatting, LaTeX equations, section breaks, and inline figures. Use when generating tutorials, analysis notebooks, reports, documentation, or educational content, when modifying existing live scripts,
| 1 | # Live Scripts |
| 2 | |
| 3 | Plain-text `.m` files that render as rich documents in the MATLAB Live Editor. Version-control friendly — never use binary `.mlx`. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | - Tutorials, reports, analysis notebooks, or documentation |
| 8 | - Interactive exploration with inline figures and equations |
| 9 | - Version-controlled content (plain-text `.m`, not binary `.mlx`) |
| 10 | - Converting an existing binary `.mlx` file to plain-text `.m` |
| 11 | |
| 12 | ## When NOT to Use |
| 13 | |
| 14 | - Regular scripts without rich formatting |
| 15 | - Function files |
| 16 | - MATLAB older than R2025a |
| 17 | |
| 18 | ## Converting from `.mlx` |
| 19 | |
| 20 | 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: |
| 21 | |
| 22 | ```matlab |
| 23 | editor = matlab.desktop.editor.openDocument(mlxPath, Visible=0); |
| 24 | editor.saveAs(newMPath); % use .m extension |
| 25 | editor.closeNoPrompt; |
| 26 | ``` |
| 27 | |
| 28 | ## Rules |
| 29 | |
| 30 | - Text lines use `%[text]` — NOT bare `%` |
| 31 | - One paragraph = one `%[text]` line — do not hard-wrap; let the Live Editor handle line width |
| 32 | - No empty `%[text]` lines — they render as unwanted blank space |
| 33 | - Section headers: `%%` on its own line, then `%[text] ## Title` on next line |
| 34 | - No blank lines in the file, except a single blank line directly before `%[appendix]` |
| 35 | - No `figure` command — implicit figure creation only |
| 36 | - No more than one plot per section (unless using tiled layouts) |
| 37 | - No `close all` or `clear` |
| 38 | - No `mfilename` — does not work as intended in live scripts. Hardcode filenames or use `pwd`. |
| 39 | - Escape these characters when used as **literal text** (not as markdown syntax): `*`, `_`, `[`, `]`, `` ` ``, `\`. Also escape `.` after a digit and `#` at line start. |
| 40 | - 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} $` |
| 41 | - 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. |
| 42 | - Last list item (bulleted or numbered) ends with `\` |
| 43 | - Every file ends with the required appendix |
| 44 | - Avoid `fprintf` — drop the semicolon or use `disp()`. Output appears inline below the code that produced it, not in the Command Window. |
| 45 | - Outputs should serve the reader's understanding, not verify execution |
| 46 | |
| 47 | ## Required Appendix |
| 48 | |
| 49 | Every live script must end with: |
| 50 | |
| 51 | ```matlab |
| 52 | %[appendix]{"version":"1.0"} |
| 53 | %--- |
| 54 | %[metadata:view] |
| 55 | % data: {"layout":"inline"} |
| 56 | %--- |
| 57 | ``` |
| 58 | |
| 59 | ## Reading live scripts (Token Optimization) |
| 60 | |
| 61 | 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. |
| 62 | |
| 63 | ## Format Reference |
| 64 | |
| 65 | | Syntax | Renders as | |
| 66 | |--------|-----------| |
| 67 | | `%%` | Section break | |
| 68 | | `%[text] # Title` | H1 heading | |
| 69 | | `%[text] ## Section` | H2 heading | |
| 70 | | `%[text] **bold**` | **Bold** | |
| 71 | | `%[text] *italic*` | *Italic* | |
| 72 | | `` %[text] `code` `` | `Monospace` | |
| 73 | | `%[text] <u>text</u>` | Underlined text | |
| 74 | | `%[text] $ a = \\pi r^2 $` | Inline equation | |
| 75 | | `%[text]{"align":"center"} $ ... $` | Centered/display equation | |
| 76 | | `%[text] - item` | Bullet | |
| 77 | | `%[text] - last \` | Last bullet | |
| 78 | | `%[text] 1. item` | Numbered list | |
| 79 | | `%[text] 2. last \` | Last numbered item | |
| 80 | | `%[text] [text](url)` | External hyperlink | |
| 81 | | `%[text] [text](internal:id)` | Internal link to an anchor | |
| 82 | | `%[text] %[text:anchor:id] ...` | Anchor (link target) | |
| 83 | | `%[text:tableOfContents]{"heading":"..."}` | Table of Contents | |
| 84 | |
| 85 | **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. |
| 86 | |
| 87 | ### Tables |
| 88 | |
| 89 | ```matlab |
| 90 | %[text:table] |
| 91 | %[text] | Method | Result | |
| 92 | %[text] | --- | --- | |
| 93 | %[text] | Trapezoidal | 1.9998 | |
| 94 | %[text:table] |
| 95 | ``` |
| 96 | |
| 97 | ## Example |
| 98 | |
| 99 | ```matlab |
| 100 | %[text] # Sinusoidal Signals |
| 101 | %[text] Examples of sinusoidal signals in MATLAB. |
| 102 | %[text:tableOfContents]{"heading":"Contents"} |
| 103 | %[text] - sine waves |
| 104 | %[text] - cosine waves \ |
| 105 | x = linspace(0,8*pi); |
| 106 | %% |
| 107 | %[text] ## Sine Wave |
| 108 | plot(x,sin(x)) |
| 109 | title('Sine Wave') |
| 110 | xlabel('x (radians)') |
| 111 | ylabel('sin(x)') |
| 112 | grid on |
| 113 | %% |
| 114 | %[text] ## Cosine Wave |
| 115 | plot(x,cos(x)) |
| 116 | title('Cosine Wave') |
| 117 | xlabel(' |