0

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.

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
StarBucK
  • 2,164
  • 1
  • 10
  • 33

2 Answers2

3

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.)

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
  • 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. – StarBucK Aug 06 '18 at 02:01
0
Text["\!\(\*SubscriptBox[\(\[Theta]\), \(n\)]\)= \!\(\*FractionBox[\(\
\[Pi]\), \(2\)]\)"]

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

enter image description here

David G. Stork
  • 41,180
  • 3
  • 34
  • 96
  • 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. – StarBucK Aug 06 '18 at 02:01