How do I turn off the LaTeX interpreter per line in my title within MATLAB?

20 views (last 30 days)
Hi all,
I'm looking to have, within a title, two lines: the top one a LaTeX formated text (including subscript and a \Delta symbol), and the lower line with some text that I want to disable the formatting as it would look messy - e.g. my sample name is '14_6_520', but at the moment this would subscript the 6 and 5, as shown in the image below:
I understand that to put two lines in a plot title, it requires the following code after plot:
title({'First line';'Second line'})
The top title (this is the one I want with the formatting)
Plotting = '\Delta{H_{Irr-Uir}} vs Disp'
The lower title (this is the one I don't want to have formatted - here I would enter 14_6_520):
ID = string(inputdlg('Enter the name to ID this data with:')); %this is where, in the GUI, I'd enter the text 14_6_520
Putting these together in to a plot title with two lines would look like this:
title({(Plotting);(ID)});
but I'd like 'ID' with 'interpreter' set to 'none' to tell it I don't want the lower line to be formatted, which I thought would be achieved with this code:
title({(Plotting);(ID,'Interpreter','none')});
However this does not work. Is there a way to choose interpreter on/off (by line) within the title? Many thanks!

Answers (1)

Star Strider
Star Strider on 17 Jul 2025
Edited: Star Strider on 17 Jul 2025
Probably the easiest way to do what you want would be to 'escape' the underscore lines using backslashes (\) --
figure
title(["$\Delta{H_{Irr-Uir}} vs Disp$" "$14_66_20$"], Interpreter='LaTeX') % Original
figure
title(["$\Delta{H_{Irr-Uir}} vs Disp$" "$14\_66\_20$"], Interpreter='LaTeX') % Underscores 'Escaped'
EDIT --
If the lines are entered with the underscores, use the strrep function to add the backslashes automatically --
numstr = '14_66_20'
numstr = '14_66_20'
numstresc = strrep(numstr, '_','\_')
numstresc = '14\_66\_20'
.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2025a

Community Treasure Hunt

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

Start Hunting!