Using LaTeX in legends and labels of plots?

Viewed 8034

I'm trying to add a legend with the function being drawn on the plot, e.g.:

description = legend({"y(x) = \sqrt{\frac{100(1-0.10x^2)^2+0.02x^2}{(1-x^2)^2+0.1x^2}}"});

legend(description ,"location", "northoutside");

however, the result I get is:

enter image description here

What is the correct syntax to include LaTeX math mode symbols?


Octave-4.2.1 on Windows 10

2 Answers

Depending on the variety of TeX math symbols you use, it may suffice using quoting with '' instead of "".

For instance,

  1. Powers work well with any of the two.
  2. '\rho' gets the correct legend, while "\rho" does not. Likewise for other greek symbols I tested.
  3. \frac and \sqrt work with none of the two.

I did not look for authoritative information with more details, and you are in case 3, so using single quotes is not enough. But it may be enough for others (as it was for me).

Related