0
$\begingroup$

I would like to write the following for the legend of a curve :

$$ Theta = \frac{\pi}{2}$$

Where the value $\frac{\pi}{2}$ is actually in a variable named $Theta$ (same name as the text on the lhs of the equality). Of course, I don't know in advance that $Theta=\frac{\pi}{2}$). Also, I need to add some style to my text (like making it bold, increasing its size etc), this is why I am using the function Style as below.

However, when I write this in Mathematica :

Style["Theta=" <> ToString[Theta]]

The fraction goes under the $Theta$ like in this picture :

enter image description here

What can I do to make Mathematica write properly what I want? I am looking for a very simple solution.

$\endgroup$
1
  • $\begingroup$ Have you seen MaTeX? $\endgroup$
    – Michael E2
    Commented Aug 6, 2018 at 2:03

2 Answers 2

3
$\begingroup$

Don't use ToString (and especially, don't use a single argument ToString). Instead, just use expressions instead of strings:

Subscript[θ,n]==π/2

enter image description here

Addendum to address updated question

Again, don't use ToString. Here is how I would create your legend:

θ = Pi/2;
Style[HoldForm[θ] == θ, 20]

enter image description here

(Note that legends in plots are by default displayed in TraditionalForm, so that the double equal symbol gets rendered as a (long) single equal.)

$\endgroup$
1
  • $\begingroup$ Ok, I edited with further details. Actually the value $\pi/2$ is in a variable name that is the same of the text I want to write on the lhs. And I also want to add some style on my text (making it bold, bigger), so I think I can't really use a mathematical expression. The purpose is the legend of a graph. $\endgroup$
    – StarBucK
    Commented Aug 6, 2018 at 2:01
0
$\begingroup$
Text["\!\(\*SubscriptBox[\(\[Theta]\), \(n\)]\)= \!\(\*FractionBox[\(\
\[Pi]\), \(2\)]\)"]

It is simplest to compose your text using the Basic Math Assistant palette.

enter image description here

$\endgroup$
1
  • $\begingroup$ Ok, I edited with further details. Actually the value π/2 is in a variable name that is the same of the text I want to write on the lhs. And I also want to add some style on my text (making it bold, bigger), so I think I can't really use a mathematical expression. The purpose is the legend of a graph. $\endgroup$
    – StarBucK
    Commented Aug 6, 2018 at 2:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.