Is it possible to generate dynamic text in Matlab Live Script notebooks?

25 views (last 30 days)
Is there a way to generate Text that includes dynamic variables?
I would like to use this to customize teaching assignments to individual students given in form of Live Script notebooks.
For example, assigning initially a variable to x=5;
I like to write a text like:
Assignment 1:
Calculate the product of 2 * {x} in the code section below.
So that it appears on the reader with the variable automatically substituted:
Assignment 1:
Calculate the product of 2 * 5 in the code section below.
  1 Comment
Oliver Kluge
Oliver Kluge on 20 Mar 2023
Edited: Walter Roberson on 30 Mar 2023
A beta version for
1) creating handouts in the form of interactive live scripts,
2) creating handouts in the form of non-interactive documents,
e.g., as PDF, LaTeX, HTML, or Microsoft Word handouts,
is available for MATLAB's Live Editor.
Referencing MATLAB variables is possible with interactive live scripts and non-interactive documents.
If you are interested, please visit
Thank you.

Sign in to comment.

Answers (2)

Cris LaPierre
Cris LaPierre on 18 Oct 2022
This is not currently possible. If you'd like, you can submit this to MathWorks as a suggestion
Create Service Request > Technical Support

Walter Roberson
Walter Roberson on 22 Oct 2022
It is possible, but it is messy and not supported at all. I would not recommend it.
First create your mlx file.
Now, unzip() the mlx file. One file and three sub-directories will be created.
The matlab/document.xml file will contain an xml encoded version of the Live Script. For example (wrapped even though the original is all one line)
<?xml version="1.0" encoding="UTF-8"?><w:document
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p><w:pPr><w:pStyle w:val="text"/><w:jc w:val="left"/></w:pPr><w:r>
<w:t> Assignment 1:</w:t></w:r></w:p>
<w:p><w:pPr><w:pStyle w:val="text"/><w:jc w:val="left"/></w:pPr><w:r>
<w:t> Calculate the product of 2 * </w:t></w:r><w:r>
<w:t>{x}</w:t></w:r><w:r>
<w:t> in the code section below.</w:t></w:r></w:p>
<w:p><w:pPr><w:pStyle w:val="code"/></w:pPr><w:r>
<w:t><![CDATA[result = ]]></w:t></w:r></w:p>
</w:body></w:document>
You can use code to edit that text, and then you can zip() the directory back up and rename the .zip to .mlx.
Not. Recommended.
Especially as you would have to create a different mlx file for each different value of x.... unless you wanted the user to run a mlx that generated the adjusted mlx !
  2 Comments
Martin Rhode
Martin Rhode on 22 Oct 2022
Amazing. Practially, its not really going to help, but still interesting. Thanks
Walter Roberson
Walter Roberson on 22 Oct 2022
A couple of months ago I tried to figure out how the symbolic toolbox manages to put up formatted equations dynamically. I was able to track down the calls used, but I was not able to track down the preconditions. If I put the breakpoint in at the right place in the code I could modify the data structure to cause some alternate equation to be displayed, but if I took those calls and made the same call outside of the function, it did not work for me.
The internal data structure that was used contains MathML, which is one of the standards for generating markup of equations in an HTML type of language. If I had been able to figure out what was needed to inject my own MathML then it would have been usable for what you want. Unfortunately I didn't manage to get the context right.

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!