The Latex command $\text{abc}$ does not work in a Matlab legend?

1.6k Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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