How do I change the text output in Live Scripts?
40 views (last 30 days)
Show older comments
In a Live Script, I make some calculations and want to print out the result. I am using fprintf to do this. For example:
s='text output';
fprintf('Text value is %s',s);
The live script then prints out:
Text value is text output
How do I change the font, the font size, or the font style of the output?
I have tried to change font size in preferences, but none of the options change the font size of the live script output. If I zoom, it zooms everything (live script text as well as the output).
Thanks for any help you can offer
Rodney
0 Comments
Answers (2)
Ankit
on 24 Jan 2022
@Rodney Smith Please try following links to change the font, font size and font style.
for bold:
fprintf('Hello <strong> bold </strong> world.\n')
I use cprintf - display formatted colored text in Command Window - File Exchange - MATLAB Central (mathworks.com) for changing the font, style etc in MATLAB window. But I didn't tested this on Live Script.
7 Comments
Lorenzo Marchionne
on 6 Jul 2022
Hi @Rodney Smith, I've tried to use cprintf in Live Script but unfortunately it doesn't work to me (the printed text is always in black). However it does work properly if I use it in a standard script or directly in the command window.
I see you found the way to make it work in Live Script too. Would you be so kind to give me some extra info on how you managed to make it work in live scripts? It would be very appreciated. Thanks :)
Walter Roberson
on 8 Jul 2022
The internal mechanism of getting LiveScript to display graphical representation, is to call
matlab.internal.language.signalVariableDisplay(VALUE, NAME)
where NAME is either '' or a character vector giving a displayable variable name (to display on the left hand side of '=' in the display)
VALUE is expected to be either a symbolic object or else a table object (if anything else is accepted, I have not seen evidence of that.)
I do not know how tables are formatted for this purpose.
For symbolic objects, the symbolic object has a property mathmlOutput which is normally created by createMathML(X,symSuggestions) where symSuggestions is the descriptor for the "Other actions" contextual menu (like "Copy output", "evaluate with vpa" and so on.) The createMathML call creates the basic MathML for the object by calling mathml() on the object.
If you put a breakpoint in at the right place in @sym/disp.m and you replace X.mathmlOutput with a different character vector of MathML, then you can get LiveScript to display the altered information. For example I was able to bold a term in a symbolic expression.
Unfortunately...
- repeated calls to matlab.internal.language.signalVariableDisplay() with altered mathmlOutput properties do not seem to have any effect
- calling matlab.internal.language.signalVariableDisplay() outside of @sym/disp.m does not seem to have any effect
So, there might be a way to get arbitrary mathML output... but it is not obvious to program that.
I seem to recall from previous investigation that .mlx is zip'd XML and that for text headers and GIF images that it is encoded in mathML inside the XML. If that memory is correct then if, hypothetically, you could reliably trigger outputing arbitrary mathML then interesting outputs would become possible. Unfortunate that there is no clear way to do this.
0 Comments
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!