Skip to content

matlab-live-script: Document backslash escaping behavior after executeAndSave #11

@yanndebray

Description

@yanndebray

Summary

The matlab-live-script skill documentation should clarify that matlab.internal.liveeditor.executeAndSave() escapes backslashes in LaTeX equations, which can cause confusion when debugging or inspecting the plain text file.

Problem Description

When creating a Live Script with LaTeX equations following the skill's guidance to use single backslashes:

%[text] $$e^{at} \longrightarrow \frac{1}{s-a}$${"altText":"Laplace transform"}

After running matlab.internal.liveeditor.executeAndSave('myScript.m'), the file contains:

%[text] $$e^{at} \\longrightarrow \\frac{1}{s-a}$${"altText":"Laplace transform"}

This doubled backslash behavior is expected (MATLAB escapes backslashes for internal storage), but it's not documented in the skill. This leads to:

  1. Confusion when inspecting the plain text file after execution
  2. Attempted "fixes" that break the equations
  3. Uncertainty about whether equations will render correctly

Observed Side Effects

In some cases, executeAndSave also escapes brackets in %[text] markup:

%\[text] ---    % Should be %[text] ---

This appears to be a MATLAB bug but should be noted as a known issue.

Suggested Documentation Updates

1. Add note to Step 6 (Execute and Save)

**Important Note on Backslash Escaping:**
After `executeAndSave` runs, backslashes in LaTeX equations will appear 
doubled in the plain text file (e.g., `\frac` becomes `\\frac`). This is 
**expected behavior** - MATLAB escapes backslashes for internal storage. 
The Live Editor will correctly un-escape and render them. Do NOT manually 
"fix" the doubled backslashes if editing the file as plain text after execution.

2. Add to DON'T section

- Don't use unsupported LaTeX commands like `\xrightarrow` - use simpler 
  alternatives like `\longrightarrow`

3. Consider adding a "Known Issues" section

Document the bracket escaping bug and any other quirks discovered.

Environment

  • MATLAB R2025b
  • Plain text Live Script format (.m)

Related

This was discovered while creating a 3Blue1Brown-style Laplace transform visualization tutorial as a Live Script.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions