TeX (LaTeX math mode) symbols in legends and labels in MATLAB figures

Shah (view profile)

on 22 Nov 2011
Latest activity Edited by Matthew Simoneau

Matthew Simoneau (view profile)

on 30 May 2014

I am plotting some data which includes estimates of some parameters. I want to describe the estimates by using \hat on the parameter symbols. This I have o do in legends and axis labels fields. I could not fix this matter despite some experiments using information from MATLAB help. Any idea, please to fix this problem.

I really appreciate help on this matter which will improve the look of my presentation.

Shah

Products

No products are associated with this question.

Frederik van der Walt (view profile)

Answer by Frederik van der Walt

Frederik van der Walt (view profile)

on 4 Apr 2012

l= legend(['$\hat{\psi}$']);

set(l,'Interpreter','Latex');

Steven (view profile)

on 22 Nov 2011

Try with Latex interpreter, something like

    title(['$latex$'],'interpreter','latex')

Shah

Shah (view profile)

on 22 Nov 2011

Thanks Steven but its not working here. I am using MATLAB 7.9.0.

I wrote legend(['$\hat{\psi}$'],'interpreter','latex') but got a warning: Unable to interpret TeX string '$\hat{\psi}$'interpreterlatex'. Same appear in the legend field.

Shah (view profile)

on 23 Nov 2011

......... Its done! Actually, the default interpreter in MATLAB for legend is 'tex', I guess. It is not changed from the code line. What I had to do was to right click on the legend in the figure window and then changed the 'interpreter' from 'tex' to 'latex'. This action changed the latex statement in the legend field to Math mode.

Cheers Shah

Matthew Simoneau (view profile)

on 30 May 2014

To use the full LaTeX interpreter, you can specify it as a parameter:

title('$\hat{\psi}$','Interpreter','latex')


Note that for legend, you need to use pass in you labels as a cell array to distinguish them from the parameters:

plot(1:10)
legend({'$\hat{\psi}$'},'Interpreter','latex')