2

I would like to have the expression $$\rho\!\begin{pmatrix}a&b\\ c & d\end{pmatrix}=1$$ as a legend of a plot. When I try (code is adapted from this answer)
Plot[x^2, {x, 0, 1}, PlotLegends -> Placed[{Text[Style[ToExpression["\\rho\\left({{1/(p-1),1/(p-1)},{2/(q-1),0}}\\right)=1",TeXForm, HoldForm], Bold]]}, {.4, .8}]]

I obtain the following:
enter image description here
which is not what I want...

I tried using MaTex but had trouble installing it (in the configuration step)...

Is there a simple way to fix my issue?

Surb
  • 125
  • 5

3 Answers3

4

Using MaTeX

Needs["MaTeX`"]
pl=HoldForm[p {{a,b},{c,d}}==1];
plt=MaTeX[TeXForm@pl,Magnification->1.5];
Plot[x^2,{x,0,1},PlotLegends->Placed[plt,{.4,.8}]]

Mathematica graphics

To use rho in place of p, you can try replacing the p (since only one of them happen to be there in this example)

pl=HoldForm[p {{a,b},{c,d}}==1];
plt=ToString@TeXForm@pl;
plt=MaTeX[StringReplace[plt,"p"->"\\rho"],Magnification->1.7];
Plot[x^2,{x,0,1},PlotLegends->Placed[plt,{.4,.8}]]

Mathematica graphics

Nasser
  • 143,286
  • 11
  • 154
  • 359
  • 1
    Actually the ToString@TeXForm[...] is not necessary. This is done automatically by MaTeX. Just writing pl instead is sufficient. – Szabolcs Jul 06 '17 at 04:12
  • 1
    @Szabolcs thanks. I did not know this. Changed the first example. But for the second example, I still need ToString I think, since I needed to do StringReplace later on. – Nasser Jul 06 '17 at 04:17
4
eqn = HoldForm[ ρ MatrixForm[{{a, b}, {c, d}}] == 1];

Plot[x^2, {x, 0, 1},
 PlotLegends -> Placed[{Style[eqn, Bold]}, {.4, .8}]]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
2

Maybe

pl = p {{a, b}, {c, d}} == 1 // HoldForm // TraditionalForm // 
   Rasterize[#, RasterSize -> 500] & // Magnify[#, 1] &;

Plot[x^2, {x, 0, 1}, PlotLegends -> Placed[pl, {.4, .8}]]

enter image description here

eldo
  • 67,911
  • 5
  • 60
  • 168
  • Looks good :), thank you very much. The only little details is that the "p" is not a $p$ but a rho $\rho$. Is it possible to also include that or it would make the solution much more complicated? – Surb Jul 05 '17 at 22:02
  • Instead of the "normal" p just input esc rho esc – eldo Jul 05 '17 at 23:02