0

I am using Latex formatting in the legend of a Matlab plot. For some reason the Latex command '\text{some word}' doesn't work. Matlab prints it as $\text{abc}$. For example, in the following legend statement, the first items gets formatted properly but the second item doesn't:

legend({'$||u_{N}-u||_{L^2}$', '$\text{abc}$'},'Interpreter','latex')

Matlab gives the error:

String scalar or character vector must have valid interpreter syntax: $\text{abc}$

So what is the problem, $\text{abc}$ is a valid Latex command. If I don't use the \text command just write it as plain text, it italicizes the text. Does anyone know if there is any way to use the \text command in a Matlab legend?

sonicboom
  • 9,921
  • 13
  • 50
  • 84
  • Try \textrm. (I think \text needs an ams package.) – David Mitra Oct 23 '19 at 09:31
  • 2
    This is not a matlab support forum. While we permit questions about matlab here, these should be mathematical in nature. And regardless to where you draw the line to what is mathematical in nature, questions like this are definitely off topic. – Asaf Karagila Oct 23 '19 at 09:36
  • Oops, I meant to post this to the Tex stackexhange not m.se. – sonicboom Oct 25 '19 at 08:56

1 Answers1

3

To answer your question, just use:

legend({'$||u_{N}-u||_{L^2}$', 'abc'},'Interpreter','latex')

for basic text, you can also use

legend({'$||u_{N}-u||_{L^2}$', '$\mathrm{abc}$'},'Interpreter','latex')

in case you want to use text in an equation.

This question is however better suited in either tex.stackexchange.com or stackoverflow.com

seaver
  • 488
  • 1
  • 3
  • 15