Are there Any Restrictions on Latex Markup in Figure Titles?

4 views (last 30 days)
This works fine:
syms t
s1(t) = exp(-abs(t));
figure;
title("$"+latex(s1(t))+"$",'Interpreter','latex')
But this does not
s2(t) = piecewise(t<-1,0, t>2,0, exp(-abs(t)));
figure;
title("$"+latex(s2(t))+"$",'Interpreter','latex')
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
$\left\{\begin{array}{cl} 0 & \text{\ if\ \ }t<-1\vee 2<t\\ {\mathrm{e}}^{-\left|t\right|} & \mathrm{ otherwise} \end{array}\right.$
Is there any way to get s2(t) on the figure in any way at all (title, text, anything)?
  1 Comment
Star Strider
Star Strider on 8 Dec 2021
The Symbolic Math Toolbox has its own way of depicting piecewise functions:
syms t
s2(t) = piecewise(t<-1,0, t>2,0, exp(-abs(t)))
s2(t) = 
I doubt that could be incorporated into a text object of any sort.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 8 Dec 2021
The \text is the immediate problem. If you use \textrm instead then you get something
  4 Comments
Paul
Paul on 8 Dec 2021
Well ... so much for my mental model.
Strictly speaking, is the \text markup produced by the latex() command fundamentally incorrect? Or is it correct per the latex "standard" (whatever that may be) but for whatever reason just not supported in rendering equations in graphics objects?
IOTW, is there a bug in the latex() command?
Walter Roberson
Walter Roberson on 8 Dec 2021
\text is part of the amsmath package. There is no documentation as to which packages the various components support, but amsmath is decidedly not supported for graphics objects.

Sign in to comment.

More Answers (0)

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!