mwouts / jupytext

Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
https://jupytext.readthedocs.io
MIT License
6.59k stars 386 forks source link

Incorrect m:percent formatting (MATLAB) #1113

Open Lolcroc opened 1 year ago

Lolcroc commented 1 year ago

Code and markdown cells in .m (MATLAB) scripts are delimited with % %%, rather than giving the expected result %%.

mwouts commented 1 year ago

Hi @Lolcroc , yes indeed, in the m:percent format cells are delimited by % %%, cf. this example: https://github.com/mwouts/jupytext/blob/main/tests/notebooks/mirror/ipynb_to_percent/octave_notebook.m

This is consistent with the other percent formats (comment character + %%). Can you tell us what made you expect just %% for the cell delimiter ?

Lolcroc commented 1 year ago

Hi @mwouts. This might be a point of discussion. MATLAB typically delimits code sections with double percent (%%) formatting. This is not just purely aesthetic; a MATLAB script opened in the MATLAB editor with %%-formatted sections can be executed in sections, whereas % %%-formatted lines are simply parsed as comments. Compare this to the typical behavior for # %%-formatted sections in Python, which may be executed individually in popular editors like Spyder or VS Code.

The request is therefore to create commonality between jupytext section formatting, and built-in MATLAB code sections. Hopefully that makes the story a bit more clear.

mwouts commented 1 year ago

I see! Thank you for the explanation. Do you usually have comments (e.g. section titles) after the %% section prefix in MATLAB?

Lolcroc commented 1 year ago

Hi @mwouts. Yes! The syntax is simply %% Section title. Often times, subtitles or descriptions are added by appending comments on new lines, as in

%% This is a section
% This is how it works.
% You can use it for this.

The official documentation on this format can be found here.