Is it possible to display text in the console using latex expressions ?

Hello,
I would like to display in the console grec letters using the latex syntaxe. Is there a way do this ?
For exemple I can do this with the title() function :
title('\theta_{\lambda/4}=20°')
But
disp('\theta_{\lambda/4}=20°')
displays literally \theta_{\lambda/4}.
I saw that disp('λ') works but you need to ctrl c - ctrl v the λ from somewhere to do so. Since latex interpretation works in title() I guess there must be a way to write latex in a prompt.
Thank you

6 Comments

Hello Matt,
You could check this answer.
The reason why this work with functions such as "title", is that title has the property "interpreter" where you can select latex as an option (I think in your case it is selected by default).
I am not sure that it is possible to do the same on the command window. May I know why you want to output the promt in the command window? Maybe we can find another workaround that is still useful for you.
Best,
Lorenzo
Hello,
I am doing some debuging of a code and would like to monitor a couple of variables that represent angles and wavelength.
My typical use case is
disp('theta = ' num2str(theta))
Some of those angles are function of wavelenghts and so I end up with a couple of variables that are naturally named \theta_{\lambda1} on paper, theta_lambda_1 in matlab. It's just nicer for the eye to read \theta_{\lambda1}.
So latex is not supported in the prompt and the char function and a list of html entries like here (https://www.science.co.il/internet/html/Greek-characters.php) is the way to go ?
disp([char(952) '_' char(955)])
The command window supports some sort of HTML, maybe it's possible to do so, however, the effort might not be worth it.
The output of head function is an example.
Hello Matt,
Is there a reason why you want to debug with text promt and not with the standard debug functionalities?
Best,
Lorenzo
Hello,
Yes : in this case the debugging is about checking if formulas have been correclty implemented in the code and not finding mistakes that generates matlab errors. To do so I manually run the program with different options and check if the resultats are realistic.
For this using disp (as well as plots/imagesc etc) to monitor if variables that have a physical meaning behave as they should well is convenient.
I accepted Jan answer on why it not possible/good practice and did a small function that transforms a '\{greek letter}' is the corresponding letter using the answer you pointed.
Thanks Lorenzo.
Hello,
Yes : in this case the debugging is about checking if formulas have been correclty implemented in the code and not finding mistakes that generates matlab errors. To do so I manually run the program with different options and check if the resultats are realistic.
For this using disp (as well as plots/imagesc etc) to monitor if variables that have a physical meaning behave as they should well is convenient.
I accepted Jan answer on why it not possible/good practice and did a small function that transforms a '\{greek letter}' is the corresponding letter using the answer you pointed.
Thanks Lorenzo.

Sign in to comment.

 Accepted Answer

Jan
Jan on 1 Feb 2023
Edited: Jan on 1 Feb 2023
LaTeX is not an option in the command window.
Using Unicode characters works for some fonts, but fails with other font. The result of a debugging should not depend on the font used in the command window, so I would avoid such fancy tricks.

1 Comment

Indeed I tried this and exotic fonts transforms greek letters in weird shapes. But the usual ones ( liberation XX, Times new roman etc) are fine.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2022a

Asked:

on 1 Feb 2023

Commented:

on 6 Feb 2023

Community Treasure Hunt

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

Start Hunting!